欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

tornado 使用supervisor管理进程,使用nginx做负载均衡

程序员文章站 2022-05-13 17:58:37
...
tornado 使用supervisor管理进程,使用nginx做负载均衡

部署方式

采用nginx作为load banlancer

nginx的配置文件如下,放在/etc/nginx/sites-avaiable/下,然后再sites-enable下面创建软连接
nginx有一个基础配置会include sites-enable下的文件。
以下代码是被配置的http{}部分所include

upstream detect_data_server {
server 127.0.0.1:8001;
server 127.0.0.1:8002;
server 127.0.0.1:8003;
server 127.0.0.1:8004;
}

# Only retry if there was a communication error, not a timeout
# on the Tornado server (to avoid propagating "queries of death"
# to all frontends)
# proxy_next_upstream error;  # this has been in nginx.conf

server {
    listen 80;

    location / {
        proxy_pass_header Server;
        proxy_set_header Host $http_host;
        proxy_redirect off;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Scheme $scheme;
        proxy_pass http://detect_data_server;
    }
}

运行命令:

sudo cp /home/opsys/running/detect-datacollect-server/deploy/detect-datacollect-server.conf 
    /etc/nginx/sites-available
sudo ln -s /etc/nginx/sites-available/detect-datacollect-server.conf 
    /etc/nginx/sites-enabled/detect-datacollect-server.conf
sudo service nginx start

注意:

  • 启动nginx时要注意sites-available目录下面的default,在nginx.conf中不要include了这个文件
  • 不同的系统对应的目录不一样,要注意

使用supervisor进行管理

安装supervisor最好用apt-get install 安装
放在/etc/supervisor/conf.d/目录下面。和nginx一样,supervisor也有一个基础配置
为/etc/supervisor/supervisord.conf,这个文件会去include conf.d中的文件

以下为配置:

; To take advantage of multiple cores, you'll need multiple processes.
[group:gp_detect_data]
programs=detect_data

[program:detect_data]
; envir  ; TEST for test environ. 
command=python /home/opsys/running/detect-datacollect-server/code/app.py --port=80%(process_num)02d
process_name = %(program_name)s%(process_num)d
autorestart=true
redirect_stderr=true
stdout_logfile=/home/opsys/log/detect-data-stdout.log
stdout_logfile_maxbytes=50MB
stdout_logfile_backups=10
stderr_logfile=/home/opsys/log/detect-data-stderr.log
loglevel=info
numprocs = 4
numprocs_start = 1

运行命令:

sudo cp /home/opsys/running/detect-datacollect-server/conf/supervisor/detect_data.conf
    /etc/supervisor/conf.d/
sudo service supervisor start

log目录

具体的要看配置文件中的配置

  • 程序log:/home/opsys/log/detect-data-stdout.log
  • supervisor的log: /var/log/supervisor/supervisord.log
  • nginx log:/var/log/nginx/

参考

https://github.com/tornadoweb/tornado/wiki/Deployment

https://gist.github.com/didip/802561

http://gracece.com/2014/03/Tornado-supervisor+nginx/

http://www.tornadoweb.org/en/stable/guide/running.html

第八章:https://github.com/alioth310/itt2zh/blob/master/ch8.html

').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); });

以上就介绍了tornado 使用supervisor管理进程,使用nginx做负载均衡,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。