tornado 使用supervisor管理進程,使用nginx做負載平衡
部署方式
採用nginx作為load banlancer
nginx的設定檔如下,放在/etc/nginx/sites-avaiable/下,然後再sites-enable下面建立軟串連nginx有一個基礎配置會include sites-enable下的檔案。以下代碼是被配置的http{}部分所includeupstream 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.confserver { 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-availablesudo ln -s /etc/nginx/sites-available/detect-datacollect-server.conf /etc/nginx/sites-enabled/detect-datacollect-server.confsudo 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)02dprocess_name = %(program_name)s%(process_num)dautorestart=trueredirect_stderr=truestdout_logfile=/home/opsys/log/detect-data-stdout.logstdout_logfile_maxbytes=50MBstdout_logfile_backups=10stderr_logfile=/home/opsys/log/detect-data-stderr.logloglevel=infonumprocs = 4numprocs_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 <= lines; i++) { $numbering.append($('
').text(i)); }; $numbering.fadeIn(1700); }); });
以上就介紹了tornado 使用supervisor管理進程,使用nginx做負載平衡,包括了方面的內容,希望對PHP教程有興趣的朋友有所協助。