django服务部署(centos+nginx+mysql+uwsgi)

django服务部署(centos+nginx+mysql+uwsgi)

nginx安装请参考

https://blog.csdn.net/weixin_42238129/article/details/103722061

mysql安装请参考

https://blog.csdn.net/weixin_42238129/article/details/103722275

部署发布平台
    1.1 uwsgi
        1.1.1 安装uwsgi
          

 pip3 install uwsgi


        1.1.2 配置uwsgi
            

  1.  
    mkdir /etc/uwsgi
  2.  
    vim /etc/uwsgi/uwsgi.ini

[uwsgi]
uid = root
gid = root
socket = 127.0.0.1:9090

master = true 
vhost = true 
no-site = true 
workers = 2 
reload-mercy = 10 
vacuum = true 
max-requests = 1000 
limit-as = 512 
buffer-size = 30000
pidfile = /var/run/uwsgi9090.pid 
daemonize = /var/log/uwsgi9090.log
pythonpath=/usr/local/lib/python3.7/site-packages
                

1.1.3 创建按uwsgi启动脚本
            

vim /etc/init.d/uwsgi

                #!/bin/sh
                DESC="uwsgi daemon"
                NAME=uwsgi
                DAEMON=/usr/local/bin/uwsgi
                CONFIGFILE=/etc/uwsgi/$NAME.ini
                PIDFILE=/var/run/${NAME}9090.pid
                SCRIPTNAME=/etc/init.d/$NAME
                FIFOFILE=/tmp/uwsgififo
                set -e
                [ -x "$DAEMON" ] || exit 0

                do_start() {
                if [ ! -f $PIDFILE ];then
                $DAEMON $CONFIGFILE || echo -n "uwsgi  running"
                else
                echo "The PID is exist..."
                fi
                }

                do_stop() {
                if [ -f $PIDFILE ];then
                $DAEMON --stop $PIDFILE || echo -n "uwsgi not running"
                rm -f $PIDFILE
                echo "$DAEMON STOPED."
                else
                echo "The $PIDFILE doesn't found"
                fi
                }

                do_reload() {
                if [ -p $FIFOFILE ];then
                echo w > $FIFOFILE
                else
                $DAEMON --touch-workers-reload $PIDFILE || echo -n "uwsgi can't reload"
                fi
                }

                do_status() {
                ps aux|grep $DAEMON
                }

                case "$1" in
                status)
                echo -en "Status $NAME: \n"
                do_status
                ;;
                start)
                echo -en "Starting $NAME: \n"
                do_start
                ;;
                stop)
                echo -en "Stopping $NAME: \n"
                do_stop
                ;;  
                reload|graceful)
                echo -en "Reloading $NAME: \n"
                do_reload
                ;;
                *)
                echo "Usage: $SCRIPTNAME {start|stop|reload}" >&2
                exit 3
                ;;
                esac
                exit 0

          

 chmod 755 /etc/init.d/uwsgi


    2.2 安装django
      

 pip3 install django==2.1.15

    2.3 配置nginx
      

 pip3 install django==2.1.15


       server {
         listen       80;
        server_name  localhost;

            location / {
            include uwsgi_params;
            uwsgi_pass 127.0.0.1:9090;
            uwsgi_param UWSGI_SCRIPT myweb.wsgi;   //myweb改成你的项目名称
            uwsgi_param UWSGI_CHDIR /usr/local/nginx/html/myweb;  //改成项目路径
            index index.html index.htm;
            client_max_body_size 35m;
            uwsgi_cache_valid 1m;
            uwsgi_temp_file_write_size 64k;
            uwsgi_busy_buffers_size 64k;
            uwsgi_buffers 8 64k;
            uwsgi_buffer_size 64k;
            uwsgi_read_timeout 300;
            uwsgi_send_timeout 300;
            uwsgi_connect_timeout 300;
            }
            }  

 

2.4 启动

  1.  
    /usr/local/nginx/sbin/nginx
  2.  
    /etc/init.d/uwsgi start
posted @ 2020-08-24 22:43  小周同学、  阅读(27)  评论(0)    收藏  举报