centos 6.7 搭建tornado + nginx + supervisor的方法(已经实践)
首先,本来不想写这篇博客了,但是我测试了很多网上的例子包括简书的,全不行,我总结原因是自己太笨,搞了俩个晚上,后来决定,自己还是写一篇记录下来,保证自己以后使用
环境:
centos6.7 64
python2.7.11
pip 9.0.1
nginx1.4.5
1.安装nginx
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
[root@pythonS1 ~]# vim /usr/local/nginx1.4.5/conf/nginx.conf user nginx; worker_processes 5; events { worker_connections 1024; use epoll; } http{ upstream tornadoes { server 127.0.0.1:8000; server 127.0.0.1:8001; server 127.0.0.1:8002; server 127.0.0.1:8003; } server { listen 80; server_name localhost; location /static/ { root /var/www/static; if ($query_string) { expires max; } } 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://tornadoes; #proxy_pass http://www.iyunv.com/; } } }
2.tornado的代码
我把自己的代码放在了/opt/pythonweb下面
3.supervisor安装和使用
启动supervisor的时候报错pkg_resources.DistributionNotFound: meld3>=0.6.5
Traceback (most recent call last): File "/usr/bin/echo_supervisord_conf", line 5, in <module> from pkg_resources import load_entry_point File "/usr/lib/python2.6/site-packages/setuptools-0.6c11-py2.6.egg/pkg_resources.py", line 2603, in <module> File "/usr/lib/python2.6/site-packages/setuptools-0.6c11-py2.6.egg/pkg_resources.py", line 666, in require File "/usr/lib/python2.6/site-packages/setuptools-0.6c11-py2.6.egg/pkg_resources.py", line 565, in resolve pkg_resources.DistributionNotFound: meld3>=0.6.5
解决方法:pip安装的meld3不可用,手动安装。
wget https://pypi.python.org/packages/source/m/meld3/meld3-1.0.2.tar.gz tar -zxf meld3-1.0.2.tar.gz cd meld3-1.0.2 python setup.py install
生成配置文件
echo_supervisord_conf > /etc/supervisord.conf
配置文件最后添加的内容,注意没有user会报错的
启动服务
/usr/local/nginx1.4.5/sbin/nginx supervisorctl
start all
4.监控多个进程服务,监控nginx, celery等
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
[program:python] command=python /opt/pythonweb/hello.py directory=/opt/pythonweb autostart=true ; start at supervisord start (default: true) startretries=3 ; max # of serial start failures when starting (default 3) autorestart=true ; when to restart if exited after running (def: unexpected) redirect_stderr=true ; redirect proc stderr to stdout (default false) stdout_logfile=/var/log/nginx.log ; stdout log path, NONE for none; default AUTO stdout_logfile_maxbytes=1MB ; max # logfile bytes b4 rotation (default 50MB) stdout_logfile_backups=10 ; # of stdout logfile backups (default 10) stdout_capture_maxbytes=1MB ; number of bytes in 'capturemode' (default 0) stdout_events_enabled=false ; emit events on stdout writes (default false) stderr_logfile=/var/log/nginx_err.log ; stderr log path, NONE for none; default AUTO stderr_logfile_maxbytes=1MB ; max # logfile bytes b4 rotation (default 50MB) stderr_logfile_backups=10 ; # of stderr logfile backups (default 10) stderr_capture_maxbytes=1MB ; number of bytes in 'capturemode' (default 0) stderr_events_enabled=false ; emit events on stderr writes (default false) user=root
supervisorctl start nginx # 启动 nginx
supervisorctl start all # 启动所有进程
supervisorctl status # 查看进程状态
5.注意每次更新完supervisor以后一定要重启supervisor,ps -ef | grep supervisor ,,,kill
作者:沐禹辰
出处:http://www.cnblogs.com/renfanzi/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接。
出处:http://www.cnblogs.com/renfanzi/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接。