Django框架部署文档:
硬件环境:阿里云ecs服务器8核心、16GB、10Mbps
环境结构:nginx+uwsgi+django
所需软件:python-3.6.1、pip3.6、mysql-5.1.73 nginx-1.6.3、
1
2
[iyunv@shouke src]# yum install zlib-develbzip2-devel pcre-devel openssl-devel ncurses-devel sqlite-devel readline-develtk-devel
[iyunv@shouke ~]# yum -y install opensslopenssl-devel
1
2
3
4
5
编译安装python3.6.1
[iyunv@shouke leslie]# tar zxvf Python-3.6.1.tgz -C /usr/src/
[iyunv@shouke leslie]# cd /usr/src/Python-3.6.1/
[iyunv@shouke Python-3.6.1]# ./configure--prefix=/usr/local/python --enable-shared CFLAGS=-fPIC
[iyunv@shouke Python-3.6.1]#make&&make install
##安装完python3.6过程中自动安装了pip工具
'''
#Collecting setuptools
#Collecting pip
#Installing collected packages: setuptools,pip
#Successfully installed pip-9.0.1setuptools-28.8.0
'''
现在输入python还是python2.6
1
2
3
4
5
[iyunv@shouke ~]# python
Python 2.6.6 (r266:84292, Jul 23 2015,15:22:56)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-11)] onlinux2
Type "help","copyright", "credits" or "license" for moreinformation.
>>>
将2.6python的程序备份
1
2
3
4
[iyunv@shouke ~]# which python
/usr/bin/python
[iyunv@shouke ~]# cd /usr/bin/
[iyunv@shouke bin]# mv python python.bak
将3.6的python软链接到/usr/bin/python
1
2
3
[iyunv@shouke bin]# ln -s/usr/local/python/bin/python3 /usr/bin/python
[iyunv@shouke bin]# python
python: error while loading sharedlibraries: libpython3.6m.so.1.0: cannot open shared object file: No such fileor directory
缺少libpython3.6m.so.1.0 将python安装目录下的libpython3.6m.so.1.0链接到/usr/lib64库下
[
1
root@shouke bin]# ln -s/usr/local/python/lib/libpython3.6m.so.1.0 /usr/lib64/
可以使用了
1
2
3
4
5
6
7
[iyunv@shouke bin]# python
Python 3.6.1 (default, Oct 26 2017,11:49:35)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-17)] onlinux
Type "help","copyright", "credits" or "license" for moreinformation.
>>> print("hello world")
hello world
>>>
现在yum无法使用了,因为yum是使用python解释器运行的,现在找不到原来版本的python了,所以无法运行了,
1
2
3
4
5
6
7
8
9
[iyunv@shouke bin]# yum
File "/usr/bin/yum", line 30
except KeyboardInterrupt, e:
^
SyntaxError: invalid syntax
[iyunv@shouke bin]# which yum
/usr/bin/yum
[iyunv@shouke bin]# cat /usr/bin/yum
1
2
3
4
5
6
7
8
#!/usr/bin/python2.6 ##修改第一行为这样
import sys
try:
import yum
except ImportError:
print >> sys.stderr, """\
There was a problem importing one of thePython mod
。。。
yum可以使用了:
1
2
3
4
5
6
[iyunv@shouke bin]# yum makecache
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
*base: mirrors.aliyuncs.com
*epel: mirrors.aliyuncs.com
*extras: mirrors.aliyuncs.com
安装 uwsgi
1
2
3
4
5
6
7
[iyunv@shouke bin]#/usr/local/python/bin/pip3 install uwsgi
Collecting uwsgi
Downloadinghttp://mirrors.aliyun.com/pypi/p ... uwsgi-2.0.15.tar.gz (795kB)
100% |████████████████████████████████| 798kB 58.5MB/s
Installing collected packages: uwsgi
Running setup.py install for uwsgi ... done
Successfully installed uwsgi-2.0.15
验证安装:
1
2
[iyunv@shouke bin]#/usr/local/python/bin/uwsgi --version
2.0.15
安装django
验证安装:
[
1
2
3
4
5
root@shouke ~]# python
Python 3.6.1 (default, Oct 26 2017,11:49:35)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-17)] on linux
Type "help","copyright", "credits" or "license" for moreinformation.
>>> import django
1
2
>>> django.VERSION
(1, 11, 6, 'final', 0)
输入[url=]url:8002[/url]验证。(提示服务器ip地址加入到允许访问的列表内)
http://lesliecheung.blog.51cto.com/e/u261/themes/default/images/spacer.gif
1
2
[iyunv@shouke demosite]# vim demosite/settings.py #修改此文件
http://lesliecheung.blog.51cto.com/e/u261/themes/default/images/spacer.gif
1
[iyunv@shouke demosite]# python manage.pyrunserver 0.0.0.0:8002
再次运行,访问成功:
http://lesliecheung.blog.51cto.com/e/u261/themes/default/images/spacer.gif
部署项目:
将项目上传到服务器:
http://lesliecheung.blog.51cto.com/e/u261/themes/default/images/spacer.gif
移动到项目/opt下面,并在/opt下面新建文件夹script
1
2
[iyunv@shouke opt]# ls
gitlab online_edit_script script
在script目录里新建uwsgi.ini配置文件
1
2
3
4
[iyunv@shouke opt]# cd script/
[iyunv@shouke script]# ls
uwsgi.ini
[iyunv@shouke script]# vim uwsgi.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已经部署了,直接修改配置文件
1
2
3
4
5
6
7
8
9
10
11
12
13
server {
server_name www.leslie.com ;
location /{
include uwsgi_params; ##加载uwsgi支持模块
uwsgi_connect_timeout 30; ##超时时间
uwsgi_pass unix:/opt /script/uwsgi.sock; #转到uwsgi这个进程
}
location/static/ { ##静态文件nginx自己处理
alias/opt/online_edit_script/static/;
indexindex.html index.htm;
}
}
检测语法:
1
2
3
[iyunv@shouke script]# /application/nginx/sbin/nginx -t
nginx: the configuration file/application/nginx-1.6.3//conf/nginx.conf syntax is ok
nginx: configuration file/application/nginx-1.6.3//conf/nginx.conf test is successful
安装mysql:
1
yum -y install mysql mysql-devel mysql-server mysql-client
1
pip3 install mysqlclient
修改配置文件将域名加入到允许访问的列表里面。
1
[iyunv@shouke ~]# vim /opt/online_edit_script/online_edit_script/settings.py
http://lesliecheung.blog.51cto.com/e/u261/themes/default/images/spacer.gif
初始化uwsgi
1
Uwsgi –ini /opt/script/uwsgi.ini
会生成一个进程监听本地的9001端口
1
tcp 0 0 127.0.0.1:9001 0.0.0.0:* LISTEN 19214/uwsgi
重启nginx:
1
2
kill all nginx
/usr/local/nginx/sbin/nginx
访问测试:
运维网声明
1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网 享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com