之前已经成功运行gunicorn,这次是:
断开了远程CentOS服务器后
重新连上后,进入虚拟环境,
重新去运行,结果出错:
➜ SIPEvents gunicorn -w 4 -b 127.0.0.1:8080 wechat_auth:app zsh: command not found: gunicorn ➜ SIPEvents workon SIPEvents (SIPEvents) ➜ SIPEvents gunicorn -w 4 -b 127.0.0.1:8080 wechat_auth:app [2016-08-19 09:13:01 +0000] [28428] [INFO] Starting gunicorn 19.6.0 [2016-08-19 09:13:01 +0000] [28428] [ERROR] Connection in use: (‘127.0.0.1’, 8080) [2016-08-19 09:13:01 +0000] [28428] [ERROR] Retrying in 1 second. [2016-08-19 09:13:02 +0000] [28428] [ERROR] Connection in use: (‘127.0.0.1’, 8080) [2016-08-19 09:13:02 +0000] [28428] [ERROR] Retrying in 1 second. [2016-08-19 09:13:03 +0000] [28428] [ERROR] Connection in use: (‘127.0.0.1’, 8080) [2016-08-19 09:13:03 +0000] [28428] [ERROR] Retrying in 1 second. [2016-08-19 09:13:04 +0000] [28428] [ERROR] Connection in use: (‘127.0.0.1’, 8080) [2016-08-19 09:13:04 +0000] [28428] [ERROR] Retrying in 1 second. [2016-08-19 09:13:05 +0000] [28428] [ERROR] Connection in use: (‘127.0.0.1’, 8080) [2016-08-19 09:13:05 +0000] [28428] [ERROR] Retrying in 1 second. [2016-08-19 09:13:06 +0000] [28428] [ERROR] Can’t connect to (‘127.0.0.1’, 8080) |
gunicorn [ERROR] Connection in use: (‘127.0.0.1’, 8080)
怀疑是之前的gunicorn没停掉
去看进程:
(SIPEvents) ➜ SIPEvents ps aux | grep 8080 root 22853 0.0 0.4 201736 15584 ? S Aug18 0:08 /root/Envs/SIPEvents/bin/python /root/Envs/SIPEvents/bin/gunicorn -w 4 -b 127.0.0.1:8080 wechat_auth:app root 23825 0.0 0.5 223600 21632 ? S Aug18 0:00 /root/Envs/SIPEvents/bin/python /root/Envs/SIPEvents/bin/gunicorn -w 4 -b 127.0.0.1:8080 wechat_auth:app root 23826 0.0 0.5 223612 21644 ? S Aug18 0:00 /root/Envs/SIPEvents/bin/python /root/Envs/SIPEvents/bin/gunicorn -w 4 -b 127.0.0.1:8080 wechat_auth:app root 23827 0.0 0.5 223604 21648 ? S Aug18 0:00 /root/Envs/SIPEvents/bin/python /root/Envs/SIPEvents/bin/gunicorn -w 4 -b 127.0.0.1:8080 wechat_auth:app root 23828 0.0 0.5 223744 21656 ? S Aug18 0:00 /root/Envs/SIPEvents/bin/python /root/Envs/SIPEvents/bin/gunicorn -w 4 -b 127.0.0.1:8080 wechat_auth:app root 28441 0.0 0.0 103364 820 pts/0 S+ 09:13 0:00 grep –color=auto –exclude-dir=.bzr –exclude-dir=CVS –exclude-dir=.git –exclude-dir=.hg –exclude-dir=.svn 8080 |
参考:
去:
(SIPEvents) ➜ SIPEvents netstat -tulpn Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:10022 0.0.0.0:* LISTEN 17286/docker-proxy tcp 0 0 0.0.0.0:9000 0.0.0.0:* LISTEN 19706/docker-proxy tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 17220/mysqld tcp 0 0 0.0.0.0:9003 0.0.0.0:* LISTEN 19669/docker-proxy tcp 0 0 127.0.0.1:8080 0.0.0.0:* LISTEN 22853/python tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 20841/nginx tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1335/sshd tcp 0 0 0.0.0.0:3000 0.0.0.0:* LISTEN 17240/docker-proxy tcp 0 0 0.0.0.0:8088 0.0.0.0:* LISTEN 29962/docker-proxy tcp 0 0 0.0.0.0:5432 0.0.0.0:* LISTEN 18421/docker-proxy tcp 0 0 0.0.0.0:8000 0.0.0.0:* LISTEN 19505/docker-proxy tcp 0 0 0.0.0.0:32771 0.0.0.0:* LISTEN 8748/docker-proxy tcp 0 0 0.0.0.0:32772 0.0.0.0:* LISTEN 8782/docker-proxy udp 0 0 192.168.42.1:123 0.0.0.0:* 1346/ntpd udp 0 0 115.29.173.126:123 0.0.0.0:* 1346/ntpd udp 0 0 10.161.170.247:123 0.0.0.0:* 1346/ntpd udp 0 0 127.0.0.1:123 0.0.0.0:* 1346/ntpd udp 0 0 0.0.0.0:123 0.0.0.0:* 1346/ntpd |
其中有:
tcp 0 0 127.0.0.1:8080 0.0.0.0:* LISTEN 22853/python
对应着:
22853就是占用了8080的进程的PID
所以去:
kill -9 22853
(SIPEvents) ➜ SIPEvents kill -9 22853 (SIPEvents) ➜ SIPEvents netstat -tulpn Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:10022 0.0.0.0:* LISTEN 17286/docker-proxy tcp 0 0 0.0.0.0:9000 0.0.0.0:* LISTEN 19706/docker-proxy tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 17220/mysqld tcp 0 0 0.0.0.0:9003 0.0.0.0:* LISTEN 19669/docker-proxy tcp 0 0 127.0.0.1:8080 0.0.0.0:* LISTEN 23825/python tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 20841/nginx tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1335/sshd tcp 0 0 0.0.0.0:3000 0.0.0.0:* LISTEN 17240/docker-proxy tcp 0 0 0.0.0.0:8088 0.0.0.0:* LISTEN 29962/docker-proxy tcp 0 0 0.0.0.0:5432 0.0.0.0:* LISTEN 18421/docker-proxy tcp 0 0 0.0.0.0:8000 0.0.0.0:* LISTEN 19505/docker-proxy tcp 0 0 0.0.0.0:32771 0.0.0.0:* LISTEN 8748/docker-proxy tcp 0 0 0.0.0.0:32772 0.0.0.0:* LISTEN 8782/docker-proxy udp 0 0 192.168.42.1:123 0.0.0.0:* 1346/ntpd udp 0 0 115.29.173.126:123 0.0.0.0:* 1346/ntpd udp 0 0 10.161.170.247:123 0.0.0.0:* 1346/ntpd udp 0 0 127.0.0.1:123 0.0.0.0:* 1346/ntpd udp 0 0 0.0.0.0:123 0.0.0.0:* 1346/ntpd |
然后就可以正常运行gunicorn了:
(SIPEvents) ➜ SIPEvents gunicorn -w 4 -b 127.0.0.1:8080 wechat_auth:app [2016-08-19 09:21:00 +0000] [28545] [INFO] Starting gunicorn 19.6.0 [2016-08-19 09:21:00 +0000] [28545] [INFO] Listening at: http://127.0.0.1:8080 (28545) [2016-08-19 09:21:00 +0000] [28545] [INFO] Using worker: sync [2016-08-19 09:21:00 +0000] [28550] [INFO] Booting worker with pid: 28550 [2016-08-19 09:21:00 +0000] [28551] [INFO] Booting worker with pid: 28551 [2016-08-19 09:21:00 +0000] [28552] [INFO] Booting worker with pid: 28552 [2016-08-19 09:21:00 +0000] [28553] [INFO] Booting worker with pid: 28553 |
[总结]
此处运行gunicorn出现:
[ERROR] Connection in use: (‘127.0.0.1’, 8080)
的原因是:
此处的8080端口被占用了
-》
估计是之前某次运行了gunicorn而占用了该端口
-》所以去杀掉对应进程就可以了
-》找到对应的使用了8080端口的进程,有两种方法:
ps aux | grep 8080 |
或:
netstat -tulpn |
-》找到对应的进程,记住对应的PID
-》然后去用:
kill -9 占用了8080端口的进程的PID |
即可杀掉对应进程。
然后再去:
[整理]kill -9的含义
转载请注明:在路上 » [已解决]运行gunicorn失败:[ERROR] Connection in use 127.0.0.1 8080