1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > nginx+uwsgi+django环境部署部署

nginx+uwsgi+django环境部署部署

时间:2020-09-16 23:30:56

相关推荐

nginx+uwsgi+django环境部署部署

首科常昊技术部

Django框架部署文档:

硬件环境:阿里云ecs服务器8核心、16GB、10Mbps

环境结构:nginx+uwsgi+django

所需软件:python-3.6.1、pip3.6、mysql-5.1.73 nginx-1.6.3、

[root@shoukesrc]#yuminstallzlib-develbzip2-develpcre-developenssl-develncurses-develsqlite-develreadline-develtk-devel[root@shouke~]#yum-yinstallopensslopenssl-devel

编译安装python3.6.1[root@shoukeleslie]#tarzxvfPython-3.6.1.tgz-C/usr/src/[root@shoukeleslie]#cd/usr/src/Python-3.6.1/[root@shoukePython-3.6.1]#./configure--prefix=/usr/local/python--enable-sharedCFLAGS=-fPIC[root@shoukePython-3.6.1]#make&&makeinstall

##安装完python3.6过程中自动安装了pip工具

'''

#Collecting setuptools

#Collecting pip

#Installing collected packages: setuptools,pip

#Successfully installed pip-9.0.1setuptools-28.8.0

'''

现在输入python还是python2.6

[root@shouke~]#pythonPython2.6.6(r266:84292,Jul23,15:22:56)[GCC4.4.70313(RedHat4.4.7-11)]onlinux2Type"help","copyright","credits"or"license"formoreinformation.>>>

将2.6python的程序备份

[root@shouke~]#whichpython/usr/bin/python[root@shouke~]#cd/usr/bin/[root@shoukebin]#mvpythonpython.bak

将3.6的python软链接到/usr/bin/python

[root@shoukebin]#ln-s/usr/local/python/bin/python3/usr/bin/python[root@shoukebin]#pythonpython:errorwhileloadingsharedlibraries:libpython3.6m.so.1.0:cannotopensharedobjectfile:Nosuchfileordirectory

缺少libpython3.6m.so.1.0 将python安装目录下的libpython3.6m.so.1.0链接到/usr/lib64库下

[

root@shoukebin]#ln-s/usr/local/python/lib/libpython3.6m.so.1.0/usr/lib64/

可以使用了

[root@shoukebin]#pythonPython3.6.1(default,Oct26,11:49:35)[GCC4.4.70313(RedHat4.4.7-17)]onlinuxType"help","copyright","credits"or"license"formoreinformation.>>>print("helloworld")helloworld>>>

现在yum无法使用了,因为yum是使用python解释器运行的,现在找不到原来版本的python了,所以无法运行了,

[root@shoukebin]#yumFile"/usr/bin/yum",line30exceptKeyboardInterrupt,e:^SyntaxError:invalidsyntax[root@shoukebin]#whichyum/usr/bin/yum

[root@shouke bin]# cat /usr/bin/yum

#!/usr/bin/python2.6##修改第一行为这样importsystry:importyumexceptImportError:print>>sys.stderr,"""\TherewasaproblemimportingoneofthePythonmod。。。

yum可以使用了:

[root@shoukebin]#yummakecacheLoadedplugins:fastestmirrorLoadingmirrorspeedsfromcachedhostfile*base:*epel:*extras:

安装 uwsgi

[root@shoukebin]#/usr/local/python/bin/pip3installuwsgiCollectinguwsgiDownloading/pypi/packages/bb/0a/45e5aa80dc135889594bb371c082d20fb7ee7303b174874c996888cc8511/uwsgi-2.0.15.tar.gz(795kB)100%|████████████████████████████████|798kB58.5MB/sInstallingcollectedpackages:uwsgiRunningsetup.pyinstallforuwsgi...doneSuccessfullyinstalleduwsgi-2.0.15

验证安装:

[root@shoukebin]#/usr/local/python/bin/uwsgi--version2.0.15

安装django

[root@shouke~]#/usr/local/python/bin/pip3installdjangoCollectingdjangoDownloading/pypi/packages/82/33/f9d2871f3aed5062661711bf91b3ebb03daa52cc0e1c37925f3e0c4508c5/Django-1.11.6-py2.py3-none-any.whl(6.9MB)100%|████████████████████████████████|7.0MB68.8MB/sCollectingpytz(fromdjango)Downloading/pypi/packages/55/62/e7cd0e15b76062d298413f14bb4ec3cd8568a22d274427f9c3c7286969f4/pytz-.2-py2.py3-none-any.whl(484kB)100%|████████████████████████████████|491kB67.8MB/sInstallingcollectedpackages:pytz,djangoSuccessfullyinstalleddjango-1.11.6pytz-.2

验证安装:

[

root@shouke~]#pythonPython3.6.1(default,Oct26,11:49:35)[GCC4.4.70313(RedHat4.4.7-17)]onlinuxType"help","copyright","credits"or"license"formoreinformation.>>>importdjango

>>>django.VERSION(1,11,6,'final',0)

输入url:8002验证。(提示服务器ip地址加入到允许访问的列表内)

[root@shoukedemosite]#vimdemosite/settings.py#修改此文件

[root@shoukedemosite]#pythonmanage.pyrunserver0.0.0.0:8002

再次运行,访问成功:

部署项目:

将项目上传到服务器:

移动到项目/opt下面,并在/opt下面新建文件夹script

[root@shoukeopt]#lsgitlabonline_edit_scriptscript

在script目录里新建uwsgi.ini配置文件

[root@shoukeopt]#cdscript/[root@shoukescript]#lsuwsgi.ini[root@shoukescript]#vimuwsgi.ini

#uwsig使用配置文件启动

[uwsgi]

#项目目录

chdir=/opt/online_edit_script/

#指定项目的application

module=online_edit_script.wsgi:application

#指定sock的文件路径

socket=/opt/script/uwsgi.sock

#进程个数

workers=5

pidfile=/opt//script/uwsgi.pid

#指定IP端口

http=127.0.0.1:9001

#指定静态文件

static-map=/static=/opt/online_edit_script/static

#启动uwsgi的用户名和用户组

uid=root

gid=root

#启用主进程

master=true

#自动移除unix Socket和pid文件当服务停止的时候

vacuum=true

#序列化接受的内容,如果可能的话

thunder-lock=true

#启用线程

enable-threads=true

#设置自中断时间

harakiri=30

#设置缓冲

post-buffering=4096

#设置日志目录

daemonize=/opt/script/uwsgi.log

配置nginx:

服务器上nginx已经部署了,直接修改配置文件

server{;location/{includeuwsgi_params;##加载uwsgi支持模块uwsgi_connect_timeout30;##超时时间uwsgi_passunix:/opt/script/uwsgi.sock;#转到uwsgi这个进程}location/static/{##静态文件nginx自己处理alias/opt/online_edit_script/static/;indexindex.htmlindex.htm;}}

检测语法:

[root@shoukescript]#/application/nginx/sbin/nginx-tnginx:theconfigurationfile/application/nginx-1.6.3//conf/nginx.confsyntaxisoknginx:configurationfile/application/nginx-1.6.3//conf/nginx.conftestissuccessful

安装mysql:

yum-yinstallmysqlmysql-develmysql-servermysql-client

pip3installmysqlclient

修改配置文件将域名加入到允许访问的列表里面。

[root@shouke~]#vim/opt/online_edit_script/online_edit_script/settings.py

初始化uwsgi

Uwsgi–ini/opt/script/uwsgi.ini

会生成一个进程监听本地的9001端口

tcp00127.0.0.1:90010.0.0.0:*LISTEN19214/uwsgi

重启nginx:

killallnginx/usr/local/nginx/sbin/nginx

访问测试:

OK!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。