Nginx + Django + uwsgi + celery + supervisor 여러 django 프로젝트 배치

18708 단어 uwsgisupervisorcelery
아 리 클 라 우 드 CentOS 7 에 여러 django 프로젝트 배치
  • 1. nginx
  • 2. uwsgi
  • 3. 슈퍼 visor 데 몬 으로 celery 시작
  • 1. 설치
  • 2. 설정
  • 3. 상용 명령
  • 4. 켜 기 자동 켜 기
  • nginx
    server {
        listen 80;
        server_name   ip  ;
    
        location / {
            include /etc/nginx/uwsgi_params;
            uwsgi_read_timeout 3600;
            uwsgi_send_timeout 300;
            proxy_read_timeout 300;
            proxy_connect_timeout 300;
            proxy_send_timeout 300;
            uwsgi_pass 127.0.0.1:8000;
        }
        location  ~/static/ {
            root /data/wwwroot/product/django_package;
        }
    }
    
    server {
        listen 8001;   #            ,                
        server_name   ip  ;
    
        location / {
            include /etc/nginx/uwsgi_params;
            uwsgi_read_timeout 3600;
            uwsgi_send_timeout 300;
            proxy_read_timeout 300;
            proxy_connect_timeout 300;
            proxy_send_timeout 300;
            uwsgi_pass 127.0.0.1:8002;   #      uwsgi    ,      listen     
        }
        location  ~/static/ {
            root /data/wwwroot/develop/django_package;
        }
    }
    
    

    nginx 자동 시작: / lib / systemd / system / nginx. service
    [Unit]
    Description=nginx - high performance web server
    Documentation=http://nginx.org/en/docs/
    After=network-online.target remote-fs.target nss-lookup.target
    Wants=network-online.target
    
    [Service]
    Type=forking
    PIDFile=/var/run/nginx.pid
    ExecStartPre=/usr/sbin/nginx -t -c /etc/nginx/nginx.conf
    ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf
    ExecReload=/bin/kill -s HUP $MAINPID
    ExecStop=/bin/kill -s TERM $MAINPID
    
    [Install]
    WantedBy=multi-user.target
    
    

    uwsgi
    uwsgi 시작 파일: vim / etc / uwsgi. ini
    [uwsgi]
    uid = uwsgi
    gid = uwsgi
    pidfile = /run/uwsgi/uwsgi.pid
    emperor = /etc/uwsgi.d
    stats = /run/uwsgi/stats.sock
    chmod-socket = 660
    emperor-tyrant = true
    cap = setgid,setuid
    
    

    공식 환경: / etc / uwsgi. d / product. ini
    [uwsgi]
    plugins       = python36u
    master        = true
    protocol      = uwsgi
    socket        = 127.0.0.1:8000
    wsgi-file     = /data/wwwroot/product/django_package/django_package/wsgi.py
    home          = /data/wwwroot/django_project/env
    chdir         = /data/wwwroot/product/django_package
    buffer-size   = 8192
    enable-threads= true
    close-on-exec = true
    

    테스트 환경: / etc / uwsgi. d / develop. ini
    [uwsgi]
    plugins       = python36u
    master        = true
    protocol      = uwsgi
    socket        = 127.0.0.1:8002
    wsgi-file     = /data/wwwroot/develop/django_package/django_package/wsgi.py
    home          = /data/wwwroot/django_project/env
    chdir         = /data/wwwroot/develop/django_package
    buffer-size   = 8192
    enable-threads= true
    close-on-exec = true
    

    메모: 상기 두 개의 produt. ini 와 develop. ini 설정 파일 의 권한 은 루트 일 수 없습니다. nobody 또는 uwsgi 로 변경 해 야 합 니 다.
    uwsgi 자동 시작 설정: / lib / systemd / system / uwsgi. service
    [Unit]
    Description=uWSGI Emperor Service
    After=syslog.target
    
    [Service]
    EnvironmentFile=-/etc/sysconfig/uwsgi
    ExecStartPre=/bin/mkdir -p /run/uwsgi
    ExecStartPre=/bin/chown uwsgi:uwsgi /run/uwsgi
    ExecStart=/usr/sbin/uwsgi --ini /etc/uwsgi.ini
    ExecReload=/bin/kill -HUP $MAINPID
    KillSignal=SIGINT
    Restart=always
    Type=notify
    StandardError=syslog
    NotifyAccess=all
    
    [Install]
    WantedBy=multi-user.target
    

    3. 슈퍼 visor 데 몬 으로 celery 시작
    설치 하 다
    pip3 install supervisor
    

    배치
    mkdir /etc/supervisor
    echo_supervisord_conf > /etc/supervisor/supervisord.conf
    vim /etc/supervisor/supervisord.conf
    
    [include]
    files = conf.d/*.conf
    
    mkdir /etc/supervisor/conf.d
    vim /etc/supervisor/conf.d/celery.conf
    
    [program:celery]
    command=/data/wwwroot/django_project/env/bin/python manage.py celery worker -l info
    directory=/data/wwwroot/develop/django_package
    user=root
    autostart=true
    autorestart=true
    stderr_logfile=/var/log/celery.err.log
    stdout_logfile=/var/log/celery.out.log
    
    supervisord -c /etc/supervisor/supervisord.conf
    

    3. 상용 명령
    #     
    supervisord -c /etc/supervisor/supervisord.conf
            
    #   
    supervisorctl reload
    
    #   
    supervisorctl shutdown
    

    넷 째, 자동 작 동
    vim /etc/systemd/system/supervisord.service
    [Unit]
    Description=supervisord - Supervisor process control system for UNIX
    Documentation=http://supervisord.org
    After=network.target
    
    [Service]
    Type=forking
    ExecStart=/usr/bin/supervisord -c /etc/supervisor/supervisord.conf
    ExecReload=/usr/bin/supervisorctl reload
    ExecStop=/usr/bin/supervisorctl shutdown
    User=root
    
    [Install]
    WantedBy=multi-user.target
    

    systemctl daemon-reload systemctl start supervisord.service systemctl status supervisord.service systemctl enable supervisord.service

    좋은 웹페이지 즐겨찾기