部署配置

nginx.conf

user root;
worker_processes 1;

#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;

#pid logs/nginx.pid;

events {
worker_connections 1024;
}

http {
include mime.types;
default_type application/octet-stream;

#log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
#                  '$status $body_bytes_sent "$http_referer" '
#                  '"$http_user_agent" "$http_x_forwarded_for"';

#access_log  logs/access.log  main;

sendfile        on;
#tcp_nopush     on;

#keepalive_timeout  0;
keepalive_timeout  65;

#gzip  on;

include /app/tools/nginx/conf/conf.d/*.conf;
include /app/tools/nginx/conf/conf.d/uwsgi/*.upstream.conf;

server {
    listen       80;
    server_name  localhost;

    #charset koi8-r;

    #access_log  logs/host.access.log  main;

include /app/tools/nginx/conf/conf.d/uwsgi/*.location.conf;

#location ~/serverapi/  {
#    rewrite /serverapi/(.*)$ /$1 break;
    #    proxy_pass   http://10.116.216.54;
    #}


    location / {
        root   html;
        index  index.html index.htm;
    }

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   html;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    #location ~ \.php$ {
    #    root           html;
    #    fastcgi_pass   127.0.0.1:9000;
    #    fastcgi_index  index.php;
    #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
    #    include        fastcgi_params;
    #}

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}
}


# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
#    listen       8000;
#    listen       somename:8080;
#    server_name  somename  alias  another.alias;

#    location / {
#        root   html;
#        index  index.html index.htm;
#    }
#}


# HTTPS server
#
#server {
#    listen       443 ssl;
#    server_name  localhost;

#    ssl_certificate      cert.pem;
#    ssl_certificate_key  cert.key;

#    ssl_session_cache    shared:SSL:1m;
#    ssl_session_timeout  5m;

#    ssl_ciphers  HIGH:!aNULL:!MD5;
#    ssl_prefer_server_ciphers  on;

#    location / {
#        root   html;
#        index  index.html index.htm;
#    }
#}

}

dtqr.location.conf

location /dtqr/static {
alias /app/tools/static/dtqr/static;
}

location /dtqr/ {
#proxy_pass http://192.168.252.108:9901;
uwsgi_pass dtqr;
include uwsgi_params;
uwsgi_connect_timeout 300;
uwsgi_param UWSGI_PYHOME /app/tools/uwsgi/bin/python;
uwsgi_param UWSGI_CHDIR /app/tools/app/dtqr;

}

dtqr.upstream.conf

upstream dtqr {
#server 192.168.252.108:9901;
server unix:/app/tools/uwsgi/tmp/dtqr.sock;dtqr.ini # for a file socket
}

uwsgi dtqr.ini

[uwsgi]
#http = :9901
base = /app/tools
socket = %(base)/uwsgi/tmp/dtqr.sock
virtualenv = %(base)/pyenv/dtqr
wsgi-file = %(base)/app/dtqr/dtqr/wsgi.py
module = dtqr.wsgi:application
chdir = %(base)/app/dtqr
pidfile = %(base)/uwsgi/tmp/dtqr.pid
#daemonize = %(base)/uwsgi/logs/EMGC.log
stats = %(base)/uwsgi/tmp/dtqr.status
processes = 2
threads = 10
max-requests = 1000
#limit-as = 512
reload-mercy = 10
post-buffering = 65536
buffer-size = 65536
log-maxsize = 50000000
disable-logging = False
vacuum = True
master = True
chmod-socket = 777
chown-socket = root
gid = root
uid = root

supervisord dtqr.ini

; ================================
; uwsgi supervisor
; ================================

[program:dtqr]

command=/app/tools/uwsgi/bin/uwsgi --ini dtqr.ini
directory=/app/tools/uwsgi/conf
environment=PATH="/app/tools/pyenv/dtqr/bin"
stdout_logfile=/app/tools/uwsgi/logs/dtqr_info.log
stderr_logfile=/app/tools/uwsgi/logs/dtqr_err.log
user=root
numprocs=1
autostart=true
autorestart=true
startsecs=10
priority=997

supervisor设置开机启动

新建一个“supervisord.service”文件
[Unit] 
Description=Supervisor daemon
[Service] 
Type=forking 
ExecStart=/var/local/data/pyenv/xls/bin/supervisord 
ExecStop=/var/local/data/pyenv/xls/bin/supervisorctl shutdown 
ExecReload=/var/local/data/pyenv/xls/bin/supervisorctl reload 
KillMode=process 
Restart=on-failure 
RestartSec=42s
[Install] 
WantedBy=multi-user.target	
====================================================================
将文件拷贝至:“/usr/lib/systemd/system/supervisord.service”
开机启动: systemctl enable supervisord
验证否开机启动:systemctl is-enabled supervisord

keepslived.conf

1.** MASTER **
global_defs {
router_id LVS_DEVE
}

vrrp_script chk_nginx {
script “/app/tools/chk_nginx.sh”
interval 3
weight -2
fall 1
rise 1
}

vrrp_instance lb_gateway_EXAMPLE {
state MASTER
interface eth0
virtual_router_id 66
mcast_src_ip 10.116.216.51
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
10.116.216.52
}
track_script {
chk_nginx
}
}
2.** BACKUP**
global_defs {
router_id LVS_DEVE
}

vrrp_script chk_nginx {
script “/app/tools/chk_nginx.sh”
interval 3
weight -2
fall 1
rise 1
}

vrrp_instance lb_gateway_EXAMPLE {
state BACKUP
interface eth0
virtual_router_id 66
mcast_src_ip 10.116.216.53
nopreempt
priority 99
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
10.116.216.52
}
track_script {
chk_nginx
}

3.** chk_nginx.sh **
#!/bin/bash
counter= ( p s C n g i n x n o h e a d i n g w c l ) i f [ " (ps -C nginx --no-heading|wc -l) if [ " {counter}" == “0” ]; then
#service nginx restart
/app/tools/supervisor/bin/supervisorctl restart nginx
sleep 3
counter= ( p s C n g i n x n o h e a d i n g w c l ) i f [ " (ps -C nginx --no-heading|wc -l) if [ " {counter}" == “0” ]; then
/etc/init.d/keepalived stop
fi
fi

猜你喜欢

转载自blog.csdn.net/weixin_38704176/article/details/84323529