一、安装PYTHON2.7.7:
0 1 2 3 4 5 6 7 8 9 10 11 |
[root@hz tools]# pwd /byrd/tools [root@hz tools]# wget https://www.python.org/ftp/python/2.7.7/Python-2.7.7.tgz [root@hz tools]# tar zxf Python-2.7.7.tgz [root@hz tools]# cd Python-2.7.7 [root@hz Python-2.7.7]# ./configure --prefix=/byrd/server/Python-2.7.7 [root@hz Python-2.7.7]# make && make install [root@hz Python-2.7.7]# mv /usr/bin/python /usr/bin/python_2.6.6 [root@hz Python-2.7.7]# ln -s /byrd/server/Python-2.7.7/bin/python2.7 /usr/bin/python ######################################################################## 注意:vim /usr/bin/yum #将!/usr/bin/python改成!/usr/bin/python2.6。 ######################################################################## |
二、安装uWSGI:
方式1:pip方式
0 1 2 3 4 |
[root@hz tools]# wget https://bootstrap.pypa.io/get-pip.py [root@hz tools]# python get-pip.py [root@hz tools]# sed -i "s#PATH=\$PATH:\$HOME\/bin#PATH=\$PATH:\$HOME\/bin:\/byrd\/server\/Python-2.7.7\/bin#g" ~/.bash_profile [root@hz tools]# source ~/.bash_profile [root@hz tools]# pip install uwsgi |
方式2:编译安装
0 1 2 3 4 5 6 7 8 9 10 11 12 |
[root@hz tools]# wget https://pypi.python.org/packages/source/s/setuptools/setuptools-5.2.tar.gz [root@hz setuptools-5.2]# python setup.py build [root@hz setuptools-5.2]# python setup.py install [root@hz tools]# wget http://projects.unbit.it/downloads/uwsgi-2.0.5.tar.gz #安装uwsgi必须安装setuptools [root@hz tools]# tar zxf uwsgi-2.0.5.tar.gz [root@hz tools]# cd uwsgi-2.0.5 [root@hz uwsgi-2.0.5]# python setup.py build [root@hz uwsgi-2.0.5]# python setup.py install #make也可以 Copying uWSGI.egg-info to /byrd/server/Python-2.7.7/lib/python2.7/site-packages/uWSGI-2.0.5-py2.7.egg-info running install_scripts [root@hz uwsgi-2.0.5]# make [root@hz uwsgi-2.0.5]# cp uwsgi /usr/bin [root@hz uwsgi-2.0.5]# chmod +x /usr/bin/uwsgi |
三、安装Django:
其他:
0 1 2 3 4 5 |
[root@hz tools]# wget https://pypi.python.org/packages/source/M/MySQL-python/MySQL-python-1.2.5.zip#md5=654f75b302db6ed8dc5a898c625e030c [root@hz tools]# unzip MySQL-python-1.2.5.zip [root@hz tools]# cd MySQL-python-1.2.5 [root@hz MySQL-python-1.2.5]# sed -i 's#\#mysql_config = /usr/local/bin/mysql_config#mysql_config = /usr/local/mysql/bin/mysql_config#g' site.cfg #改成/usr/local/mysql/bin/mysql_config [root@hz MySQL-python-1.2.5]# python setup.py build [root@hz MySQL-python-1.2.5]# python setup.py install |
方式1:
0 |
[root@hz tools]# pip install Django==1.6.5 |
方式2:
0 1 2 3 4 |
[root@hz tools]# wget https://www.djangoproject.com/m/releases/1.6/Django-1.6.5.tar.gz [root@hz tools]# tar zxf Django-1.6.5.tar.gz [root@hz tools]# cd Django-1.6.5 [root@hz Django-1.6.5]# python setup.py build [root@hz Django-1.6.5]# python setup.py install |
四、建立项目
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
[root@hz tools]# cd /web/site/ [root@hz site]# sed -i 's#\$HOME/bin#\$HOME/bin:/byrd/tools/Django-1.6.8/django/bin#g' ~/.bash_profile [root@hz site]# source ~/.bash_profile [root@hz site]# django-admin.py startproject Byrd [root@hz site]# cd Byrd/ [root@hz Byrd]# /usr/local/mysql/bin/mysql -uroot -p mysql> create database django default character set utf8 collate utf8_general_ci; mysql> create user 'django'@'localhost' identified by 'admin'; mysql> grant all on django.* to 'django'@'localhost' identified by 'admin'; mysql> flush privileges; [root@hz Byrd]# vim Byrd/settings.py ####58-63行修改为#### DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', 'NAME':'django', 'USER': 'django', 'PASSWORD': 'admin', 'HOST': '127.0.0.1', 'PORT': '3306', } } ####58-63行修改为#### [root@hz Byrd]# python manage.py runserver 0.0.0.0:8080 #It worked!证明django配置成功 |
五、Django+uWSGI:
0 1 2 3 4 5 6 7 8 9 |
[root@hz ~]# cat /usr/local/nginx/conf/uwsgi.ini [uwsgi] socket = 127.0.0.1:9001 chdir = /web/site/Byrd pythonpath = .. env = DJANGO_SETTINGS_MODULE=Byrd.settings module = django.core.handlers.wsgi:WSGIHandler() processes = 4 threads = 2 stats = 127.0.0.1:9191 |
六、Nginx:
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
server { listen 80; server_name localhost; location / { root /web/site/Byrd; include uwsgi_params; uwsgi_pass 127.0.0.1:9001; #uwsgi_param UWSGI_CHDIR /; #uwsgi_param UWSGI_SCRIPT /; index index.py index.htm; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } |
七、开机启动
0 |
[root@hz conf]# echo "uwsgi /usr/local/nginx/conf/uwsgi.ini >/dev/null 2>&1 &" >> /etc/rc.local |
八、uWSGI启动脚本:
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
#!/bin/bash # uwsgi script # it is v.0.0.1 version. # chkconfig: - 89 19 # description: uwsgi script # processname: uwsgi PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin export PATH uwsgi_config=/usr/local/nginx/conf/uwsgi.ini uwsgi_pn=`ps aux|grep -v "grep"|grep -c "uwsgi"` uwsgi_pid=`ps -eo pid,comm|grep uwsgi|sed -n 1p|awk '{print $1}'` uwsgi_PID=/usr/local/nginx/logs/uwsgi.pid uwsgi=/usr/bin/uwsgi RETVAL=0 prog="uwsgi" # Source function library. . /etc/rc.d/init.d/functions if [ $(id -u) != "0" ]; then printf "Error: You must be root to run this script!\n" exit 1 fi # Start nginx daemons functions. start() { if [ $uwsgi_pn -gt 5 ];then action "uwsgi is running!" /bin/true exit 0 fi daemon $uwsgi -x ${uwsgi_config} action "uwsgi start ..." /bin/true } # Stop nginx daemons functions. stop() { if [ $uwsgi_pn -gt 5 ] then kill -9 `ps -eo pid,comm|grep uwsgi|sed -n 1p|awk '{print $1}'` RETVAL=$? action "uwsgi stopping ..." /bin/true else action "uwsgi not running!" /bin/false fi } # See how we were called. case "$1" in start) start ;; stop) stop ;; reload) reload ;; restart) stop start ;; *) echo $"Usage: $prog {start|stop|restart}" exit 1 esac exit $RETVAL |
报错参考: http://note.t4x.org/system/django-mysql-database/
报错参考: http://note.t4x.org/system/importerror-no-module-named-setuptools/SourceByrd's Weblog-https://note.t4x.org/system/nginx-uwsgi-django-python/
申明:本文由BYRD原创,未经许可禁止转载!本文参考了一下众多文章,再次特别表示感谢。SourceByrd's Weblog-https://note.t4x.org/system/nginx-uwsgi-django-python/
参考:http://ichon.me/post/912.html
参考:http://www.nowamagic.net/academy/part/13/302/
参考:http://projects.unbit.it/uwsgi/
参考:http://www.linuxyw.com/353.html
参考:http://www.server110.com/nginx/201308/204.html
参考:http://www.kankanews.com/ICkengine/archives/113005.shtml
参考:http://blog.csdn.net/sgbfblog/article/details/8948820
参考:http://mdba.cn/?p=109
参考:http://my.oschina.net/quanpower/blog/152013
参考:http://wiki.nginx.org/HttpUwsgiModule#uwsgi_param
参考:http://www.cnblogs.com/zhouej/archive/2012/03/25/2379646.html
参考:http://blog.csdn.net/fwenzhou/article/details/8772974
参考:http://uwsgi-docs.readthedocs.org/en/latest/Nginx.html
参考:http://uwsgi-docs.readthedocs.org/en/latest/tutorials/Django_and_nginx.html
参考:http://www.cnblogs.com/einyboy/archive/2012/11/30/2796926.html
参考:http://uwsgi-docs.readthedocs.org/en/latest/WSGIquickstart.html
参考:http://www.cnblogs.com/txwsqk/archive/2011/03/15/1984792.html
参考:https://library.linode.com/web-servers/nginx/python-uwsgi/centos-5
参考:http://felixc.at/uWSGI-Python
参考:http://www.cnblogs.com/fnng/p/3737964.htmlSourceByrd's Weblog-https://note.t4x.org/system/nginx-uwsgi-django-python/
SourceByrd's Weblog-https://note.t4x.org/system/nginx-uwsgi-django-python/
Trackbacks