Django Web Deployment Platform

Source: Internet
Author: User
Tags switches vars install django egrep

I. BASIC Environment Django web deployment Platform 1, role, IP, version, kernel, software Servera 10.1.10.236 3.16.0-4-amd64 8.1 nginx  uwsgi django pythonpython-2.7.9nginx-1.6.2uwsgi-2.0.11.2django-1.8.62, install Base Pack 1) Install the base package Apt-get  -y install gcc make python-dev python-setuptools python curl  TREE2) Install PIPEASY_INSTALL PIP using the Easy_install command, install UWSGI and test access 1, install UWSGIPIP INSTALL UWSGI2, view installed module PIP  listchardet  (2.3.0) defusedxml  (0.4.1) docutils  (0.12) pillow  (2.6.1) pip  (7.1.2) pygments  (2.0.1) python-apt  (0.9.3.11) python-debian  (0.1.27) python-debianbts  (1.11) reportbug  (6.6.3) roman  (2.0.0) setuptools  (5.5.1) six  (1.8.0) soappy  (0.12.22) Uwsgi   (2.0.11.2) wstools  (0.4.3) 3, view related commands [email protected]:~# ll /usr/local/bintotal  1340-rwxr-xr-x 1 root staff     281 nov 19 09:32  Pip-rwxr-xr-x 1 root staff     283 nov 19 09:32 pip2-rwxr-xr-x 1 root staff      287 Nov 19 09:32 pip2.7-rwxr-xr-x 1 root  Staff 1357088 nov 19 09:34 uwsgi4, creating test.py[email protected]:~# cat / root/test.py #!/usr/bin/python# -*- coding: utf-8 -*-#------------------------------- -------------------#Author: jimmygong#email:[email protected] #FileName:test.py#function:  #Version: 1.0   #Created: 2015-11-19#--------------------------------------------------def application (env,start_ Response):    start_response (' 200 ok ', [(' Content_Type ', ' text/html ')])     return  "uwsgi testing ok!" 5. Start the service [Email protected]:~# uwsgi --http :9999 --wsgi-file test.py6, view process [email  protected]:~# ps -ef |grep uwsgiroot       2037   1833  0 10:01 pts/1    00:00:00  uwsgi --http :9999 --wsgi-file test.pyroot       2038    2037  0 10:01 pts/1    00:00:00 uwsgi -- http :9999 --wsgi-file test.pyroot       2042     731  0 10:02 pts/0    00:00:00 grep --color=auto  uwsgi7, viewing Port [email protected]:~# netstat -tupnl |grep 9999tcp         0      0 0.0.0.0:9999             0.0.0.0:*                listen      2037/uwsgi
8. Visit

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M00/76/3D/wKioL1ZNvSeAy6g2AAAfR0ge51Q596.png "title=" Ccc.png "alt=" Wkiol1znvseay6g2aaafr0ge51q596.png "/>

9. Close the service kill-9 20,373, install Django and test access 1, install the DJANGOPIP installation Django2, verify the module and view the version

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/76/3D/wKioL1ZNvTezFrK-AAAlY464KVY803.png "title=" Aaa.png "alt=" Wkiol1znvtezfrk-aaaly464kvy803.png "/>

3. Create the directory where the Django project is stored [EMAIL PROTECTED]:~# MKDIR /OPT/DJANGO -P4, create aaabbbcom project [email  PROTECTED]:~# CD /OPT/DJANGO/ && DJANGO-ADMIN STARTPROJECT AAABBBCOM5, View the next aaabbbcom project directory structure 1) [email protected]:d jango# tree aaabbbcom/aaabbbcom/├── aaabbbcom│    ├── __init__.py│   ├── settings.py│   ├──  URLS.PY│   └── WSGI.PY└── MANAGE.PY1 DIRECTORY, 5 FILES2) directory Structure Description __init_ _.py  directory structure   calls about settings.py  project Settings urls.py      Address profile wsgi.py       Deploy server file 6, start service cd aaabbbcom/ && nohup python manage.py  Runserver 0.0.0.0:8888 &7, viewing process ps -ef |grep pythonroot        2413   2412  0 15:14 pts/2     00:00:00 python manage.py runserver 0.0.0.0:8888root       2416   2413   1 15:14 pts/2    00:00:04 /usr/bin/python manage.py  runserver 0.0.0.0:88888, viewing Port netstat -tupnl |grep pythontcp         0      0 0.0.0.0:8888             0.0.0.0:*                listen      2416/python9, visit

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M01/76/3D/wKioL1ZNvUfgGz4xAABz6TwxU58592.png "title=" Bbb.png "alt=" Wkiol1znvufggz4xaabz6twxu58592.png "/>

10. Close the service kill -9 241611, create the TestApp application under the Aaabbbcom project cd /opt/django/aaabbbcom &&  PYTHON&NBSP;MANAGE.PY&NBSP;STARTAPP&NBSP;TESTAPP12, view the TESTAPP directory structure [email protected]:aaabbbcom# tree  testapp/testapp/├── admin.py├── __init__.py├── migrations│   └── __ INIT__.PY├──&NBSP;MODELS.PY├──&NBSP;TESTS.PY└──&NBSP;VIEWS.PY1&NBSP;DIRECTORY,&NBSP;6&NBSP;FILES13, Backup under settings.py configuration cp /opt/django/aaabbbcom/aaabbbcom/settings.py /opt/django/aaabbbcom/aaabbbcom/ SETTINGS.PY.BAK14, modifying the settings.py configuration [email protected]:~# diff /opt/django/aaabbbcom/aaabbbcom/ settings.py /opt/django/aaabbbcom/aaabbbcom/settings.py.bak40d39<      ' TestApp ', 15, define the View function views.py[email protected]:~# cat /opt/django/aaabbbcom/testapp/views.py#!/usr /bin/python# -*- coding: utf-8 -*-#--------------------------------------------------# Author:jimmygong#email:[email protected] #Filename:test.py#function:  #Version:1.0  #Created: 2015-11-19#----------------------------------------- ---------From django.http import httpresponsedef index (Request):     Return httpresponse ("welcome django web!") 16, define the view function related urls.py[email protected]:~# cat /opt/django/aaabbbcom/aaabbbcom/urls.pyfrom  django.conf.urls import patterns,include,urlfrom django.contrib import  Adminadmin.autodiscover () urlpatterns=patterns (", url (r ' ^$ ', ' testapp.views.index ', name= ' home '), url (r ' ^admin/', Include (Admin.site.urls)), 17, start service cd /opt/django/aaabbbcom/ && nohup python  MANAGE.PY&NBSP;RUNSERVER&NBSP;0.0.0.0:8888&NBSP;&AMP;18, visit

650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M02/76/3D/wKioL1ZNvV_T2kvHAAAkaATK31I259.png "title=" Fff.png "alt=" Wkiol1znvv_t2kvhaaakaatk31i259.png "/>

19, close service Four, configure Django and Uwsgi combined 1, start the service uwsgi --http :7777 --chdir /opt/django/aaabbbcom/ -- Module aaabbbcom.wsgi2, viewing Port netstat -tupnl |grep uwsgitcp         0      0 127.0.0.1:42415          0.0.0.0:*                listen      2587/uwsgi      tcp         0      0 0.0.0.0:7777             0.0.0.0:*                listen      2587/ Uwsgi 3, viewing process ps -ef |grep wsgiroot       2587     779  0 15:43 pts/1    00:00:00 uwsgi --http :7777 --chdir /opt/ django/aaabbbcom/ --module aaabbbcom.wsgiroot       2588    2587  0 15:43 pts/1    00:00:00 uwsgi --http  :7777 --chdir /opt/django/aaabbbcom/ --module aaabbbcom.wsgiroot        2604    740  0 15:47 pts/0    &NBSP;00:00:00&NBSP;GREP&NBSP;--COLOR=AUTO&NBSP;WSGI4, visit

650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M00/76/3D/wKioL1ZNvWux16ooAAAhENhGAtg249.png "title=" Ddd.png "alt=" Wkiol1znvwux16ooaaahenhgatg249.png "/>

5, close service kill -9 2587 Five, configuration nginx and Uwsgi combined 1, installation nginxapt-get -y install nginx2, Create Aaabbbcom site Cat /etc/nginx/sites-enabled/aaabbbcom server {    listen  10.1.10.236:80;    server_name 10.1.10.236;    access_log  /opt/django/access.log;    error_log /opt/django/error.log;     location / {        include      /etc/nginx/uwsgi_params;        uwsgi_pass   127.0.0.1:8630;&NBSP;&NBSP;&NBSP;&NBSP;}}3, delete default defaults node Rm -f /etc/nginx/sites-enabled/default4, Create Django.ini configuration file cat /opt/django/django.ini [uwsgi]vhost=truesocket=127.0.0.1:8630chdir=/opt/django/ aaabbbcommodule=aaabbbcom.wsgimaster=trueprocesses=2threads=2max-requests=6000chmod-socket=664vacuum= Truedaemonize=/opt/django/django.log5, Kai Uwsgi service nohup /usr/local/bin/uwsgi --ini /opt/django/django.ini &6, restart Nginx service/etc/init.d/nginx restart[  ok ] Restarting nginx  (VIA&NBSP;SYSTEMCTL):  nginx.service.7, viewing Port netstat - tupnl|egrep  "Uwsgi|nginx" tcp        0       0 10.1.10.236:80          0.0.0.0:*                LISTEN       3433/nginx -g daemotcp        0       0 127.0.0.1:8630           0.0.0.0:*                Listen      3408/uwsgi  8, viewing process ps -ef |egrep  "uwsgi| Nginx "root       3408    740  0 16:12 pts/0    00:00:00  /usr/local/bin/uwsgi --ini /opt/django/django.iniroot        3411   3408  0 16:12 pts/0    00:00:00 /usr/ local/bin/uwsgi --ini /opt/django/django.iniroot       3412    3408  0 16:12 pts/0    00:00:00 /usr/local/bin/uwsgi  --ini /opt/django/django.iniroot       3433       1  0 16:13 ?        00:00:00  nginx: master process /usr/sbin/nginx -g daemon on; master_process  on;www-data   3435   3433  0 16:13 ?         00:00:00 nginx: worker process                            www-data    3436   3433  0 16:13 ?         00:00:00 nginx: worker process                             www-data   3437   3433  0 16:13 ?         00:00:00 nginx: worker process                             www-data   3438   3433  0 16:13  ?        00:00:00 nginx: worker process                             root       3476    779  0  16:16&NBSP;PTS/1&NBSP;&NBSP;&NBSP;&NBSP;00:00:00&NBSP;GREP&NBSP;-E&NBSP;UWSGI|NGINX9, visit

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/76/3D/wKioL1ZNvXyDl436AAAhPCRvgn0296.png "title=" Eee.png "alt=" Wkiol1znvxydl436aaahpcrvgn0296.png "/>

10. View related log 1) cat /opt/django/access.log10.1.10.131 - - [19/nov/2015:15:44:27 +0800]   "get / http/1.1"  200 50  "-"   "mozilla/5.0  (windows nt 6.1;  wow64; rv:42.0)  gecko/20100101 firefox/42.0 "2) cat /opt/django/django.log ***  Starting uWSGI 2.0.11.2  (64bit)  on [Thu Nov 19 14:44:02  2015] ***compiled with version: 4.9.2 on 19 november 2015  09:33:34os: linux-3.16.0-4-amd64  #1  SMP Debian 3.16.7-ckt11-1  (2015-05-24) nodename: 10.1.10.236machine: x86_64clock source: unixdetected number of  Cpu cores: 1current working directory: /rootdetected binary path: /usr /LOCAL/BIN/UWSGI!!!  no internal routing support, rebuild with pcre support !!! uwsgi running As root, you can use --uid/--gid/--chroot options*** warning: you  are running uWSGI as root !!!   (Use the --uid flag)  *** chdir ()  to /opt/django/aaabbbcomyour  processes number limit is 850your memory page size is 4096  bytesdetected max file descriptor number: 819200virtualhosting mode  enabled.lock engine: pthread robust mutexesthunder lock: disabled  (You  can enable it with --thunder-lock) uwsgi socket 0 bound to  tcp address 127.0.0.1:8630 fd 3python version: 2.7.9  (Default, Mar &NBSP;&NBSP;1&NBSP;2015,&NBSP;13:01:26)   [GCC 4.9.2]Python main interpreter  Initialized at 0xc65b20python threads support enabledyour server socket listen backlog is limited to 100 connectionsyour  mercy for graceful operations on workers is 60 secondsmapped  249168 bytes  (243&NBSP;KB)  for 4 cores*** operational mode: preforking +threaded ***wsgi app 0  (mountpoint= ")  ready in 1 seconds on  interpreter 0xc65b20 pid: 3258  (Default app) *** uwsgi is running  in multiple interpreter mode ***spawned uWSGI master process  ( pid: 3258) spawned uwsgi worker 1  (pid: 3261, cores: 2) spawned  uwsgi worker 2  (pid: 3262, cores: 2) 10.1.10.236 [pid: 3262|app: 0 |req: 1/1] 10.1.10.131  ()  {42 vars in 686 bytes} [thu nov  19 06:47:06 2015] get / => generated 19 bytes in 20 msecs  (HTTP/1.1  200)  2 headers in 88 bytes  (1 switches on core 0) 10.1.10.236 [pid: 3262|app: 0|req: 2/2] 10.1.10.131  ()  {40 vars  in 631 bytes} [thu nov 19 07:44:27 2015] get / =>  generated 19 bytes in 192 msecs  (http/1.1 200)  2 headers in  88 bytes  (1 switches on core 1) 11, configuration instructions     socket: Specifies the path of the socket that the UWSGI client will connect to processes: Number of open processes workers: number of open processes, equivalent to processes (the official website says Spawn the specified  number of workers / processes) ChDir: Specifies the Run directory (chdir to specified  directory before apps loading) Wsgi-file: Load the specified WSGI file (compatible with Graham's Mod_wsgi form) stats: At the specified address, Turn on status service (enable the stats server on the specified address) Threads: Turn on thread operation mode. You must specify the number of threads per worker process master: Start the main process daemonize: Make the process run in the background and hit the log to the specified log file or UDP server Pidfile: Specify the location of the PID file, and record the PID number vacuum of the main process: Automatically delete unix socket files and PID files when the server exits Vhost: Turn on Virtual host mode module: Load the specified python  WSGI Module (module path must be in Pythonpath) Max-requests: Set the maximum number of requests per worker process Limit-as: Posix/unix by using Setrlimit () function to limit the number of virtual memory usage per UWSGI process Chmod-socket:unix socket is a file, so it is restricted by the UNIX system's permissions. If your UWSGI client does not have permission to access Uwsgi socket, you can use this option to set permissions for Unix socket six, reference article https://docs.djangoproject.com/en/1.8/ howto/deployment/wsgi/https://docs.djangoproject.com/en/1.8/topics/http/urls/https://docs.djangoproject.com/en /1.8/topics/settings/http://uwsgi-docs.readthedocs.org/en/latest/wsgiquickstart.html     Http://projects.unbit.it/uwsgi/wiki/Example

This article is from the "7928217" blog, please be sure to keep this source http://7938217.blog.51cto.com/7928217/1714816

Django Web Deployment Platform

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.