博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
tornado nginx supervisor
阅读量:4710 次
发布时间:2019-06-10

本文共 3799 字,大约阅读时间需要 12 分钟。

安装:sudo apt-get install python-tornado

        sudo apt-get install nginx

        sudo apt-get install supervisor

 

1. 配置nginx。我安装的nginx的目录为2个配置文件。/etc/nginx/nginx.conf   和  /etc/nginx/conf.d/foo.conf.

实际上是nginx.conf包含了文件foo.conf

所以如果没有特殊需求,就不需要更改nginx.conf了,在conf.d文件夹下新建你的conf文件。

 

 

 

foo.conf的内容;

upstream  foo  {    #ip_hash;    #consistent_hash $args;这里就是你需要nginx帮你代理的端口,下面的意思是将访问80端口的请求分配到6900,6901,6902上去。其他的无需更改。如果你不用supervisor,那就需要手工运行你的web程序,监听6900,6901,6902    server   127.0.0.1:6900 weight=1 max_fails=2 fail_timeout=30s;    server   127.0.0.1:6901 weight=1 max_fails=2 fail_timeout=30s;    server   127.0.0.1:6902 weight=1 max_fails=2 fail_timeout=30s;    }server {    listen  80;    server_tag off;    index index.html;    charset utf-8;         location / {        proxy_read_timeout  100;        proxy_pass_header   User-Agent;        proxy_set_header    Host             $http_host;        proxy_set_header    X-Real-IP        $remote_addr;        proxy_set_header    X-Forwarded-For  $proxy_add_x_forwarded_for;        proxy_set_header    X-Scheme         $scheme;        proxy_set_header    Accept-Encoding  'gzip';        proxy_pass          http://foo;        proxy_redirect      off;        proxy_store         off;            }            location /stat {        stub_status    on;        access_log    off;    }               proxy_buffering off;}

3. 运行nginx:sudo /usr/sbin/nginx

如果发生这个错误:

nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)

原因是80已经被占用了,很有可能是被nginx占用了,

找到进程结束掉或者结束掉nginx进程。/usr/sbin/nginx -s stop

4. /etc/supervisor/supervisord.conf内容:()

[unix_http_server] file=/var/run//supervisor.sock   ; (the path to the socket file) chmod=0700                       ; sockef file mode (default 0700) [supervisord] logfile=/var/log/supervisor/supervisord.log ; (main log file;default $CWD/supervisord.log) pidfile=/var/run/supervisord.pid ; (supervisord pidfile;default supervisord.pid) childlogdir=/var/log/supervisor            ; ('AUTO' child log dir, default $TEMP) ; the below section must remain in the config file for RPC ; (supervisorctl/web interface) to work, additional interfaces may be ; added by defining them in separate rpcinterface: sections [rpcinterface:supervisor] supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface [supervisorctl] serverurl=unix:///var/run//supervisor.sock ; use a unix:// URL  for a unix socket ; The [include] section can just contain the "files" setting.  This ; setting can list multiple files (separated by whitespace or ; newlines).  It can also contain wildcards.  The filenames are ; interpreted as relative to this file.  Included files *cannot* ; include files themselves. [include] files = /etc/supervisor/conf.d/*.conf##这里就是include了具体的配置文件,你需要在/etc/supervisor/conf.d/文件夹下新建conf文件。

比如你在conf.d文件夹下新建的tornado.conf的文件

[program:tornado-80]command=python /var/www/starter.py 6901 #这里就是运行web,如果跟nginx结合,还需要监听6902,6900端口directory=/var/www/user=www-dataautorestart=trueredirect_stderr=truestdout_logfile=/var/log/tornado.logloglevel=info

 

启动supervisor:

Usage: /etc/init.d/supervisord {start|stop|restart|force-reload|status|force-stop}

进入supervisor命令行:

sudo supervisorctl

 

 

5. 守护supervisor进程:

#!/bin/shpywebn=`ps aux | grep supervisord | grep -v "grep" | wc -l`; #wc -l  的意思是输出文件的行数,如果不等于1,则说明没有运行了,需要再启动下if [ "$pywebn" != "1" ]; then    sleep 1;    /usr/bin/python /usr/local/bin/supervisord -c /etc/supervisord.conf;else    break;fi

 

 6. 排错

INFO gave up: tornado entered FATAL state, too many start retries too quickly

这个网上有很多个情况,基本上是因为你的程序执行了就退出了,然后又执行,又退出,导致的

要看看你的程序是否有问题,我的情况是python web.py 80 的时候就有问题,换成python web.py 8888 就没问题了。

直接在shell中执行python  web.py 80  就没有问题

 

 

如果supervisor有问题,除了需要看/var/log/supervisor/supervisord.log还要看你配置的log,如/var/log/tornado.log

 

 

转载于:https://www.cnblogs.com/maseng/p/3497745.html

你可能感兴趣的文章
Java语法训练-打印各种三角形
查看>>
spring-dao.xml配置问题(一)
查看>>
SQLServer语句大使
查看>>
The Run-Time Constant Pool The Constant Pool
查看>>
剑指Offer-用两个栈实现队列
查看>>
Picker 移动端下拉框
查看>>
erlang局域网内通信
查看>>
ELMAH记录太多404错误,导致数据库超级大
查看>>
python接口自动化测试三十三:获取时间戳(10位和13位)和昨天、今天、明天
查看>>
表达式括号匹配
查看>>
“耐撕”团队2016.04.19站立会议
查看>>
JQuery:empty选择器
查看>>
[NOI2016]优秀的拆分 后缀数组
查看>>
菜鸟的逆袭 - 自我介绍
查看>>
<Bootstrap> 学习笔记二. 栅格系统的使用
查看>>
Codeforces Round #404 (Div. 2) E. Anton and Permutation 分块
查看>>
xml
查看>>
this 和 new 构造函数
查看>>
阅读和提问作业3
查看>>
【杂谈接口】接口对象的生命周期-对象所占用的内存块清理
查看>>