被此问题困扰数天,用supervisor管理tornado时出错了!怎么办?

2013-12-28 12:07:21 +08:00
 314x
第一次启动supervisor后,只起来一个进程,重启电脑后进程全部fatal,显示socket.error: [Errno 98] Address already in use,tornado肯定是没起来,本地访问localhost,nginx显示502 Bad Gateway
6877 次点击
所在节点    问与答
10 条回复
314x
2013-12-28 12:10:17 +08:00
supervisor的conf配置如下:

[unix_http_server]
file=/tmp/supervisor.sock
[inet_http_server]
port=9001
username = admin
password = 123456
[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
[supervisorctl]
serverurl=unix:///tmp/supervisor.sock
[supervisord]
logfile=/var/log/supervisord.log
logfile_maxbytes=50MB
logfile_backups=10
loglevel=info
pidfile=/var/run/supervisord.pid
nodaemon=false
minfds=1024
minprocs=200
[program:f2e]
command = python /srv/www/website/run.py 80%(process_num)02d
process_name=%(program_name)s_80%(process_num)02d ; process_name expr (default %(program_name)s)
numprocs=4
numprocs_start=1
autostart=true
autorestart=true
startsecs=5
startretries=3
stopsignal=QUIT
redirect_stderr=true
stdout_logfile=/var/log/flask-access.log
jerry
2013-12-28 12:10:53 +08:00
Address already in use 的意思是端口被占用了
314x
2013-12-28 12:13:00 +08:00
@jerry 是的,但是我用sudo lsof -i:8001-8004,发现这四个端口都是空的,根本没有占用,用9001的管理端口看到状态全部是fatal
314x
2013-12-28 12:19:00 +08:00
刚刚kill掉nginx占用的端口,重启supervisor后发现有一个进程可以起来,其他三个还是fatal,本地访问8080端口可以看到程序,这是怎么回事?
lerry
2013-12-28 12:22:47 +08:00
tornado怎么写的,端口参数传进去了吗
314x
2013-12-28 12:30:57 +08:00
@lerry 用的8080端口

def main():
tornado.options.parse_command_line()
http_server = tornado.httpserver.HTTPServer(Application())
http_server.listen(options.port)
tornado.ioloop.IOLoop.instance().start()
muxi
2013-12-28 12:45:11 +08:00
你端口的参数根本没传进去
试试:
command = python /srv/www/website/run.py --port=80%(process_num)02d
lerry
2013-12-28 12:47:09 +08:00
怎么是8080?不应该是supervisor传过去的8001~8004?

只有一个端口参数的话,你用http_server.listen(sys.argc[1])就可以了

parse_command_line()我没用过,大概看了一下,应该是这么写的吧

command = python /srv/www/website/run.py --port=80%(process_num)02d
lerry
2013-12-28 12:48:19 +08:00
手误,上面应该是sys.argv[1]
314x
2013-12-28 12:57:19 +08:00
@muxi @lerry

谢谢两位,确实改成command = python /srv/www/website/run.py --port=80%(process_num)02d后,supervisor四个进程都起来了,但是启动nginx后,访问127.0.0.1:8080后,出现500: Internal Server Error。之前有一个进程起来的时候,至少可以访问localhost,我是用ngxin监听8080端口,反向代理tornado 8001-8004四个端口的,配置如下:

user nginx;
worker_processes 1;

error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;

events {
worker_connections 1024;
use epoll;
}

http {
# Enumerate all the Tornado servers here
upstream frontends {
server 127.0.0.1:8001;
server 127.0.0.1:8002;
server 127.0.0.1:8003;
server 127.0.0.1:8004;
}

include /etc/nginx/mime.types;
default_type application/octet-stream;

access_log /var/log/nginx/access.log;

keepalive_timeout 65;
proxy_read_timeout 200;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
gzip on;
gzip_min_length 1000;
gzip_proxied any;
gzip_types text/plain text/css text/xml
application/x-javascript application/xml
application/atom+xml text/javascript;

# 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;

server {
listen 8080;
server_name localhost;
# Allow file uploads
client_max_body_size 50M;

location static/ {
root /srv/www/website/;
if ($query_string) {
expires max;
}
}
location = /favicon.ico {
rewrite (.*) /static/favicon.ico;
}
location = /robots.txt {
rewrite (.*) /static/robots.txt;
}

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://frontends;
}
}
}

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/94837

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX