2014-02-27 138 views
6

我已经使用Gunicorn + Nginx + Supervisor部署了一个Django 1.6应用程序。一切正常,但我一直在Gunicorn error.log发送错误。该文件很大,它每秒都会向日志文件发送错误。Django - 使用Gunicorn,Nginx和Supervisor进行部署,Gunicorn错误日志

从Gunicorn error.log中的错误:

2014-02-27 14:25:09 [9235] [INFO] Starting gunicorn 18.0 
2014-02-27 14:25:09 [9235] [ERROR] Connection in use: ('127.0.0.1', 8000) 
2014-02-27 14:25:09 [9235] [ERROR] Retrying in 1 second. 
2014-02-27 14:25:10 [9235] [ERROR] Connection in use: ('127.0.0.1', 8000) 
2014-02-27 14:25:10 [9235] [ERROR] Retrying in 1 second. 
2014-02-27 14:25:11 [9235] [ERROR] Connection in use: ('127.0.0.1', 8000) 
2014-02-27 14:25:11 [9235] [ERROR] Retrying in 1 second. 
2014-02-27 14:25:12 [9235] [ERROR] Connection in use: ('127.0.0.1', 8000) 
2014-02-27 14:25:12 [9235] [ERROR] Retrying in 1 second. 
2014-02-27 14:25:13 [9235] [ERROR] Connection in use: ('127.0.0.1', 8000) 
2014-02-27 14:25:13 [9235] [ERROR] Retrying in 1 second. 
2014-02-27 14:25:14 [9235] [ERROR] Can't connect to ('127.0.0.1', 8000) 
2014-02-27 14:25:16 [9250] [INFO] Starting gunicorn 18.0 
    2014-02-27 14:25:16 [9250] [ERROR] Connection in use: ('127.0.0.1', 8000) 
2014-02-27 14:25:16 [9250] [ERROR] Retrying in 1 second. 
2014-02-27 14:25:17 [9250] [ERROR] Connection in use: ('127.0.0.1', 8000) 
2014-02-27 14:25:17 [9250] [ERROR] Retrying in 1 second. 
2014-02-27 14:25:18 [9250] [ERROR] Connection in use: ('127.0.0.1', 8000) 
2014-02-27 14:25:18 [9250] [ERROR] Retrying in 1 second. 
2014-02-27 14:25:19 [9250] [ERROR] Connection in use: ('127.0.0.1', 8000) 
2014-02-27 14:25:19 [9250] [ERROR] Retrying in 1 second. 
2014-02-27 14:25:20 [9250] [ERROR] Connection in use: ('127.0.0.1', 8000) 
2014-02-27 14:25:20 [9250] [ERROR] Retrying in 1 second. 
2014-02-27 14:25:21 [9250] [ERROR] Can't connect to ('127.0.0.1', 8000) 
2014-02-27 14:25:24 [9261] [INFO] Starting gunicorn 18.0 
2014-02-27 14:25:24 [9261] [ERROR] Connection in use: ('127.0.0.1', 8000) 
2014-02-27 14:25:24 [9261] [ERROR] Retrying in 1 second. 
2014-02-27 14:25:25 [9261] [ERROR] Connection in use: ('127.0.0.1', 8000) 
2014-02-27 14:25:25 [9261] [ERROR] Retrying in 1 second. 
2014-02-27 14:25:26 [9261] [ERROR] Connection in use: ('127.0.0.1', 8000) 
2014-02-27 14:25:26 [9261] [ERROR] Retrying in 1 second. 
2014-02-27 14:25:27 [9261] [ERROR] Connection in use: ('127.0.0.1', 8000) 
2014-02-27 14:25:27 [9261] [ERROR] Retrying in 1 second. 
2014-02-27 14:25:28 [9261] [ERROR] Connection in use: ('127.0.0.1', 8000) 
2014-02-27 14:25:28 [9261] [ERROR] Retrying in 1 second. 
2014-02-27 14:25:29 [9261] [ERROR] Can't connect to ('127.0.0.1', 8000) 

我supervisor.conf:

[program:mydjangoapp] 
command=/home/myuser/virtualenv_mydjangoapp/bin/python manage.py run_gunicorn 
directory=/home/myuser/webapps/mydjangoapp 
user=myuser 
autostart=True 
autorestart=True 
stdout_logfile = /home/myuser/webapps/mydjangoapp_logs/gunicorn/out.log 
stderr_logfile = /home/myuser/webapps/mydjangoapp_logs/gunicorn/err.log 

我的Nginx virtual.conf:

server { 
    listen 80; 
    client_max_body_size 1G; 
    server_name 0.0.0.0; 

    keepalive_timeout 5; 
    access_log /home/myuser/webapps/mydjangoapp_logs/nginx/access.log; 
    error_log /home/myuser/webapps/mydjangoapp_logs/nginx/error.log; 

    location /static { 
     alias /home/myuser/webapps/mydjangoapp_static; 
    } 

    location/{ 
     proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 

     proxy_set_header Host $http_host; 
     proxy_redirect off; 
     proxy_pass http://localhost:8000; 
    } 
} 

我的netstat -tulpn:

Active Internet connections (only servers) 
Proto Recv-Q Send-Q Local Address   Foreign Address   State  PID/Program name 
tcp  0  0 127.0.0.1:8000   0.0.0.0:*    LISTEN  2719/python  
tcp  0  0 127.0.0.1:3306   0.0.0.0:*    LISTEN  2606/mysqld  
tcp  0  0 0.0.0.0:46028   0.0.0.0:*    LISTEN  2757/beam.smp  
tcp  0  0 0.0.0.0:80    0.0.0.0:*    LISTEN  2613/nginx  
tcp  0  0 0.0.0.0:4369   0.0.0.0:*    LISTEN  2663/epmd  
tcp  0  0 0.0.0.0:85    0.0.0.0:*    LISTEN  2613/nginx  
tcp  0  0 0.0.0.0:22    0.0.0.0:*    LISTEN  2469/sshd  
tcp6  0  0 :::5672     :::*     LISTEN  2757/beam.smp 
tcp6  0  0 :::22     :::*     LISTEN  2469/sshd  
udp  0  0 0.0.0.0:68    0.0.0.0:*       2395/dhclient3   
udp  0  0 0.0.0.0:123    0.0.0.0:*       3127/ntpd  
udp  0  0 0.0.0.0:1900   0.0.0.0:*       2551/minissdpd   
udp6  0  0 ::1:123     :::*        3127/ntpd  
udp6  0  0 :::123     :::*        3127/ntpd  

我supervisord.log:

2014-02-27 16:14:56,300 CRIT Supervisor running as root (no user in config file) 
2014-02-27 16:14:56,303 CRIT Supervisor running as root (no user in config file) 
2014-02-27 16:14:56,413 INFO RPC interface 'supervisor' initialized 
2014-02-27 16:14:56,413 CRIT Server 'unix_http_server' running without any HTTP authentication checking 
2014-02-27 16:14:56,414 INFO supervisord started with pid 2510 
2014-02-27 16:14:56,651 INFO RPC interface 'supervisor' initialized 
2014-02-27 16:14:56,651 CRIT Server 'unix_http_server' running without any HTTP authentication checking 
2014-02-27 16:14:56,657 INFO daemonizing the supervisord process 
2014-02-27 16:14:56,658 INFO supervisord started with pid 2687 
2014-02-27 16:14:57,453 INFO spawned: 'celery' with pid 2786 
2014-02-27 16:14:57,466 INFO spawned: 'mydjangoapp' with pid 2787 
2014-02-27 16:14:57,666 INFO spawned: 'celery' with pid 2842 
2014-02-27 16:14:57,673 INFO spawned: 'mydjangoapp' with pid 2846 
2014-02-27 16:14:58,471 INFO success: mydjangoapp entered RUNNING state, process has stayed up for > than 1 seconds (startsecs) 
2014-02-27 16:14:58,676 INFO success: mydjangoapp entered RUNNING state, process has stayed up for > than 1 seconds (startsecs) 
2014-02-27 16:15:09,284 INFO success: celery entered RUNNING state, process has stayed up for > than 10 seconds (startsecs) 
2014-02-27 16:15:09,313 INFO success: celery entered RUNNING state, process has stayed up for > than 10 seconds (startsecs) 
2014-02-27 16:15:13,438 INFO exited: mydjangoapp (exit status 1; not expected) 
2014-02-27 16:15:14,445 INFO spawned: 'mydjangoapp' with pid 3164 
2014-02-27 16:15:15,830 INFO success: mydjangoapp entered RUNNING state, process has stayed up for > than 1 seconds (startsecs) 
2014-02-27 16:15:20,539 INFO exited: mydjangoapp (exit status 1; not expected) 
2014-02-27 16:15:21,546 INFO spawned: 'mydjangoapp' with pid 3264 
2014-02-27 16:15:22,549 INFO success: mydjangoapp entered RUNNING state, process has stayed up for > than 1 seconds (startsecs) 
2014-02-27 16:15:27,669 INFO exited: mydjangoapp (exit status 1; not expected) 
2014-02-27 16:15:28,676 INFO spawned: 'mydjangoapp' with pid 3275 
2014-02-27 16:15:29,679 INFO success: mydjangoapp entered RUNNING state, process has stayed up for > than 1 seconds (startsecs) 
2014-02-27 16:15:35,166 INFO exited: mydjangoapp (exit status 1; not expected) 
2014-02-27 16:15:36,173 INFO spawned: 'mydjangoapp' with pid 3286 
2014-02-27 16:15:37,175 INFO success: mydjangoapp entered RUNNING state, process has stayed up for > than 1 seconds (startsecs) 
2014-02-27 16:15:42,332 INFO exited: mydjangoapp (exit status 1; not expected) 
2014-02-27 16:15:43,339 INFO spawned: 'mydjangoapp' with pid 3295 

我supervisorctl状态输出:

[email protected]:/var/log# supervisorctl status 
celery       RUNNING pid 2842, uptime 0:04:05 
mydjangoapp      RUNNING pid 3815, uptime 0:00:03 

上是什么导致在Gunicorn日志文件中的错误任何线索?正如我所说的,一切工作都没有问题。唯一的问题是这个日志不断发送错误。

最好的问候,

+1

'python manage.py run_gunicorn'作为deamon运行? – pbacterio

+0

@pbacterio,该命令是supervisord.conf中的命令。有一种像deamon一样运行“python manage.py run_gunicorn”的方法吗? –

+1

看起来像supervidor错误地重新启动程序。看看主管日志。 – pbacterio

回答

1

由于错误日志说,它看起来像有一个应用程序已经侦听端口8000 也许你启动命令行蚂蚁gunicorn它在该端口已经运行。

您可以使用netstat -tulpn来查看是否有一个python实例在该端口上侦听并将其终止。

希望有所帮助。

+0

我已经添加了我的“netstat -tulpn”输出。 Python在PID 2719上运行,与supervisord进程的PID相同。 –

5

这通常发生在gunicorn进程重试几次时,以及在前一个进程即将完成时(如果您恰好在端口启动进程(在您的情况下为8000)等等。所以,你需要单独终止所有这些过程。

  • 您可以使用netstat -tulpn看到PID
  • kill -9 PID

其他等待特效将在循环等待的情况下自动启动。所以重复检查netstat并杀死它们,直到在该端口上找不到更多进程。

Gunicorn流程应该在这一点上正常工作。

相关问题