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

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]
; environment=MODE="TEST"  ; 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

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值