V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
314x
V2EX  ›  问与答

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

  •  
  •   314x · 2013-12-28 12:07:21 +08:00 · 6965 次点击
    这是一个创建于 4013 天前的主题,其中的信息可能已经有所发展或是发生改变。
    第一次启动supervisor后,只起来一个进程,重启电脑后进程全部fatal,显示socket.error: [Errno 98] Address already in use,tornado肯定是没起来,本地访问localhost,nginx显示502 Bad Gateway
    10 条回复    1970-01-01 08:00:00 +08:00
    314x
        1
    314x  
    OP
       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
        2
    jerry  
       2013-12-28 12:10:53 +08:00
    Address already in use 的意思是端口被占用了
    314x
        3
    314x  
    OP
       2013-12-28 12:13:00 +08:00
    @jerry 是的,但是我用sudo lsof -i:8001-8004,发现这四个端口都是空的,根本没有占用,用9001的管理端口看到状态全部是fatal
    314x
        4
    314x  
    OP
       2013-12-28 12:19:00 +08:00
    刚刚kill掉nginx占用的端口,重启supervisor后发现有一个进程可以起来,其他三个还是fatal,本地访问8080端口可以看到程序,这是怎么回事?
    lerry
        5
    lerry  
       2013-12-28 12:22:47 +08:00 via Android
    tornado怎么写的,端口参数传进去了吗
    314x
        6
    314x  
    OP
       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
        7
    muxi  
       2013-12-28 12:45:11 +08:00   ❤️ 1
    你端口的参数根本没传进去
    试试:
    command = python /srv/www/website/run.py --port=80%(process_num)02d
    lerry
        8
    lerry  
       2013-12-28 12:47:09 +08:00   ❤️ 2
    怎么是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
        9
    lerry  
       2013-12-28 12:48:19 +08:00
    手误,上面应该是sys.argv[1]
    314x
        10
    314x  
    OP
       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;
    }
    }
    }
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   5115 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 42ms · UTC 09:40 · PVG 17:40 · LAX 01:40 · JFK 04:40
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.