您的位置:首页 > 运维架构 > Nginx

nginx端口被占用的问题

2015-06-16 00:00 621 查看
摘要: nginx port

问题描述:在保存修改后的nginx配置文件后,在/usr/sbin 目录下 nginx -s reload,出现如下的错误。

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

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

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

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

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

nginx: [emerg] still could not bind()

考虑安装lsof来解决问题。

yum install lsof

lsof -i:80 找到占用80端口的程序和服务

kill -9 <id of the program that occupys port 80>

结果出现了新的问题,nginx杀不掉。

后来, ss -nap | grep 80,试图找到占用80端口的那个进程。得到的结果如下:

tcp LISTEN 0 128 *:80 *:*

结果那个进程没显示出来。

ps -aux | grep nginx

root 15975 0.0 0.0 109600 2184 ? Ss 09:56 0:00 nginx: master process nginx

www 15976 0.0 0.0 130816 23728 ? S 09:56 0:00 nginx: worker process

www 15977 0.0 0.0 130816 23728 ? S 09:56 0:00 nginx: worker process

www 15978 0.0 0.0 130816 23728 ? S 09:56 0:00 nginx: worker process

www 15979 0.0 0.0 130816 23728 ? S 09:56 0:00 nginx: worker process

www 15980 0.0 0.0 130816 23728 ? S 09:56 0:00 nginx: worker process

www 15981 0.0 0.0 130816 23728 ? S 09:56 0:00 nginx: worker process

www 15982 0.0 0.0 130816 23728 ? S 09:56 0:00 nginx: worker process

www 15983 0.0 0.0 130816 23728 ? S 09:56 0:00 nginx: worker process

root 16089 0.0 0.0 9032 668 pts/0 S+ 10:27 0:00 grep --color=auto nginx

ss -nat

State Recv-Q Send-Q Local Address:Port Peer Address:Port

LISTEN 0 128 *:22 *:*

LISTEN 0 50 *:3306 *:*

LISTEN 0 128 *:80 *:*

ESTAB 0 264 172.17.0.42:22 192.168.2.144:65509

ESTAB 0 0 172.17.0.42:22 192.168.2.144:50007

ESTAB 0 0 172.17.0.42:22 192.168.2.144:49753

LISTEN 0 128 :::22 :::*

可以看到,依然没有显示出80端口的进程。

ps -ef

UID PID PPID C STIME TTY TIME CMD

root 1 0 0 Jun10 ? 00:18:03 /usr/bin/python /usr/bin/supervisord

root 16 1 0 Jun10 ? 00:00:00 /usr/sbin/sshd -D

root 17 1 0 Jun10 ? 00:00:19 php-fpm: master process (/etc/php-fpm.conf)

apache 77 17 0 Jun10 ? 00:00:00 php-fpm: pool www

apache 78 17 0 Jun10 ? 00:00:00 php-fpm: pool www

apache 79 17 0 Jun10 ? 00:00:00 php-fpm: pool www

apache 81 17 0 Jun10 ? 00:00:00 php-fpm: pool www

apache 82 17 0 Jun10 ? 00:00:00 php-fpm: pool www

mysql 170 1 0 Jun10 ? 00:06:12 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --user=mysql --log-error

www 15478 1 0 01:59 ? 00:00:01 nginx: worker process

www 15479 1 0 01:59 ? 00:00:01 nginx: worker process

www 15480 1 0 01:59 ? 00:00:01 nginx: worker process

www 15481 1 0 01:59 ? 00:00:01 nginx: worker process

www 15482 1 0 01:59 ? 00:00:01 nginx: worker process

www 15483 1 0 01:59 ? 00:00:00 nginx: worker process

www 15484 1 0 01:59 ? 00:00:01 nginx: worker process

www 15485 1 0 01:59 ? 00:00:01 nginx: worker process

root 15621 16 0 02:32 ? 00:00:00 sshd: root@pts/0

root 15623 15621 0 02:32 pts/0 00:00:00 -bash

root 15653 16 0 02:39 ? 00:00:00 sshd: root@notty

root 15655 15653 0 02:39 ? 00:00:00 /usr/libexec/openssh/sftp-server

root 15659 16 0 02:47 ? 00:00:00 sshd: root@notty

root 15661 15659 0 02:47 ? 00:00:00 /usr/libexec/openssh/sftp-server

root 15833 15623 0 09:52 pts/0 00:00:00 ps -ef

pkill nginx

supervisorctl

mysql FATAL Exited too quickly (process log may have details)

nginx FATAL Exited too quickly (process log may have details)

php-fpm RUNNING pid 17, uptime 6 days, 2:34:32

sshd RUNNING pid 16, uptime 6 days, 2:34:32

wushuu_manager.sh EXITED Jun 10 12:18 PM

看看杀掉nginx之后的进程的情况。

supervisor> start nginx

ps -ef

UID PID PPID C STIME TTY TIME CMD

root 1 0 0 Jun10 ? 00:18:03 /usr/bin/python /usr/bin/supervisord

root 16 1 0 Jun10 ? 00:00:00 /usr/sbin/sshd -D

root 17 1 0 Jun10 ? 00:00:19 php-fpm: master process (/etc/php-fpm.conf)

apache 77 17 0 Jun10 ? 00:00:00 php-fpm: pool www

apache 78 17 0 Jun10 ? 00:00:00 php-fpm: pool www

apache 79 17 0 Jun10 ? 00:00:00 php-fpm: pool www

apache 81 17 0 Jun10 ? 00:00:00 php-fpm: pool www

apache 82 17 0 Jun10 ? 00:00:00 php-fpm: pool www

mysql 170 1 0 Jun10 ? 00:06:12 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --user=mysql --log-error

root 15621 16 0 02:32 ? 00:00:00 sshd: root@pts/0

root 15623 15621 0 02:32 pts/0 00:00:00 -bash

root 15653 16 0 02:39 ? 00:00:00 sshd: root@notty

root 15655 15653 0 02:39 ? 00:00:00 /usr/libexec/openssh/sftp-server

root 15659 16 0 02:47 ? 00:00:00 sshd: root@notty

root 15661 15659 0 02:47 ? 00:00:00 /usr/libexec/openssh/sftp-server

root 15838 1 0 09:52 ? 00:00:00 nginx: master process /usr/sbin/nginx

www 15839 15838 0 09:52 ? 00:00:00 nginx: worker process

www 15840 15838 0 09:52 ? 00:00:00 nginx: worker process

www 15841 15838 0 09:52 ? 00:00:00 nginx: worker process

www 15842 15838 0 09:52 ? 00:00:00 nginx: worker process

www 15843 15838 0 09:52 ? 00:00:00 nginx: worker process

www 15844 15838 0 09:52 ? 00:00:00 nginx: worker process

www 15845 15838 0 09:52 ? 00:00:00 nginx: worker process

www 15846 15838 0 09:52 ? 00:00:00 nginx: worker process

root 15850 1 1 09:52 ? 00:00:00 /usr/sbin/nginx

root 15851 15623 0 09:52 pts/0 00:00:00 ps -ef

pkill nginx

ps -ef

UID PID PPID C STIME TTY TIME CMD

root 1 0 0 Jun10 ? 00:18:03 /usr/bin/python /usr/bin/supervisord

root 16 1 0 Jun10 ? 00:00:00 /usr/sbin/sshd -D

root 17 1 0 Jun10 ? 00:00:19 php-fpm: master process (/etc/php-fpm.conf)

apache 77 17 0 Jun10 ? 00:00:00 php-fpm: pool www

apache 78 17 0 Jun10 ? 00:00:00 php-fpm: pool www

apache 79 17 0 Jun10 ? 00:00:00 php-fpm: pool www

apache 81 17 0 Jun10 ? 00:00:00 php-fpm: pool www

apache 82 17 0 Jun10 ? 00:00:00 php-fpm: pool www

mysql 170 1 0 Jun10 ? 00:06:12 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --user=mysql --log-error

root 15621 16 0 02:32 ? 00:00:00 sshd: root@pts/0

root 15623 15621 0 02:32 pts/0 00:00:00 -bash

root 15653 16 0 02:39 ? 00:00:00 sshd: root@notty

root 15655 15653 0 02:39 ? 00:00:00 /usr/libexec/openssh/sftp-server

root 15659 16 0 02:47 ? 00:00:00 sshd: root@notty

root 15661 15659 0 02:47 ? 00:00:00 /usr/libexec/openssh/sftp-server

root 15857 1 0 09:53 ? 00:00:00 nginx: master process /usr/sbin/nginx

www 15858 15857 0 09:53 ? 00:00:00 nginx: worker process

www 15859 15857 0 09:53 ? 00:00:00 nginx: worker process

www 15860 15857 0 09:53 ? 00:00:00 nginx: worker process

www 15861 15857 0 09:53 ? 00:00:00 nginx: worker process

www 15862 15857 0 09:53 ? 00:00:00 nginx: worker process

www 15863 15857 0 09:53 ? 00:00:00 nginx: worker process

www 15864 15857 0 09:53 ? 00:00:00 nginx: worker process

www 15865 15857 0 09:53 ? 00:00:00 nginx: worker process

root 15866 1 1 09:53 ? 00:00:00 /usr/sbin/nginx

root 15867 15623 0 09:53 pts/0 00:00:00 ps -ef

pkill nginx

ps -ef | grep ^www | awk '{print $2}' | xargs kill -9杀掉nginx进程

./init.sh 启动脚本

ps -ef

UID PID PPID C STIME TTY TIME CMD

root 1 0 0 Jun10 ? 00:18:04 /usr/bin/python /usr/bin/supervisord

root 16 1 0 Jun10 ? 00:00:00 /usr/sbin/sshd -D

root 17 1 0 Jun10 ? 00:00:19 php-fpm: master process (/etc/php-fpm.conf)

apache 77 17 0 Jun10 ? 00:00:00 php-fpm: pool www

apache 78 17 0 Jun10 ? 00:00:00 php-fpm: pool www

apache 79 17 0 Jun10 ? 00:00:00 php-fpm: pool www

apache 81 17 0 Jun10 ? 00:00:00 php-fpm: pool www

apache 82 17 0 Jun10 ? 00:00:00 php-fpm: pool www

mysql 170 1 0 Jun10 ? 00:06:13 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --user=mysql --log-error

root 15621 16 0 02:32 ? 00:00:01 sshd: root@pts/0

root 15623 15621 0 02:32 pts/0 00:00:00 -bash

root 15653 16 0 02:39 ? 00:00:00 sshd: root@notty

root 15655 15653 0 02:39 ? 00:00:00 /usr/libexec/openssh/sftp-server

root 15659 16 0 02:47 ? 00:00:00 sshd: root@notty

root 15661 15659 0 02:47 ? 00:00:00 /usr/libexec/openssh/sftp-server

root 15975 1 0 09:56 ? 00:00:00 nginx: master process nginx

www 15976 15975 0 09:56 ? 00:00:00 nginx: worker process

www 15977 15975 0 09:56 ? 00:00:00 nginx: worker process

www 15978 15975 0 09:56 ? 00:00:00 nginx: worker process

www 15979 15975 0 09:56 ? 00:00:00 nginx: worker process

www 15980 15975 0 09:56 ? 00:00:00 nginx: worker process

www 15981 15975 0 09:56 ? 00:00:00 nginx: worker process

www 15982 15975 0 09:56 ? 00:00:00 nginx: worker process

www 15983 15975 0 09:56 ? 00:00:00 nginx: worker process

root 16087 15623 0 09:56 pts/0 00:00:00 ps -ef

接下来就是启动mysql的任务了。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: