#检查Nginx配置
[root@i-14fe7093 nginx]# ./sbin/nginx -t -c ./conf/nginx.conf
nginx: the configuration file /usr/local/nginx/./conf/nginx.conf syntax is oknginx: configuration file /usr/local/nginx/./conf/nginx.conf test is successful
#不依靠残留进程,重新启动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()
#强制性杀死进程
[root@i-14fe7093 nginx]# /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
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()
#启动Nginx方式之一
Starting nginx (via systemctl): Job for nginx.service failed because the control process exited with error code. See "systemctl status nginx.service" and "journalctl -xe" for details. [FAILED]
#查看Nginx服务状态
â— nginx.service - SYSV: Nginx is an HTTP(S) server, HTTP(S) reverse proxy and IMAP/POP3 proxy server
Loaded: loaded (/etc/rc.d/init.d/nginx)
Active: failed (Result: exit-code) since Tue 2018-01-02 23:19:52 CST; 38s ago
Docs: man:systemd-sysv-generator(8)
Process: 15553 ExecStart=/etc/rc.d/init.d/nginx start (code=exited, status=1/FAILURE)
Jan 02 23:19:50 i-14fe7093 nginx[15553]: nginx: [emerg] bind() to 0.0.0.0:80...)
Jan 02 23:19:51 i-14fe7093 nginx[15553]: nginx: [emerg] bind() to 0.0.0.0:80...)
Jan 02 23:19:51 i-14fe7093 nginx[15553]: nginx: [emerg] bind() to 0.0.0.0:80...)
Jan 02 23:19:52 i-14fe7093 nginx[15553]: nginx: [emerg] bind() to 0.0.0.0:80...)
Jan 02 23:19:52 i-14fe7093 nginx[15553]: nginx: [emerg] still could not bind()
Jan 02 23:19:52 i-14fe7093 nginx[15553]: [FAILED]
Jan 02 23:19:52 i-14fe7093 systemd[1]: nginx.service: control process exite...=1
Jan 02 23:19:52 i-14fe7093 systemd[1]: Failed to start SYSV: Nginx is an HT...r.
Jan 02 23:19:52 i-14fe7093 systemd[1]: Unit nginx.service entered failed state.
Jan 02 23:19:52 i-14fe7093 systemd[1]: nginx.service failed.
Hint: Some lines were ellipsized, use -l to show in full.
#查看系统日志
Jan 02 23:19:49 i-14fe7093 systemd[1]: Starting SYSV: Nginx is an HTTP(S) server, HTTP(S) reverse proxy and IMAP/POP3 proxy server...
-- Subject: Unit nginx.service has begun start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit nginx.service has begun starting up.
Jan 02 23:19:50 i-14fe7093 nginx[15553]: Starting nginx: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Jan 02 23:19:50 i-14fe7093 nginx[15553]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Jan 02 23:19:51 i-14fe7093 nginx[15553]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Jan 02 23:19:51 i-14fe7093 nginx[15553]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Jan 02 23:19:52 i-14fe7093 nginx[15553]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Jan 02 23:19:52 i-14fe7093 nginx[15553]: nginx: [emerg] still could not bind()
Jan 02 23:19:52 i-14fe7093 nginx[15553]: [FAILED]
Jan 02 23:19:52 i-14fe7093 systemd[1]: nginx.service: control process exited, code=exited status=1
Jan 02 23:19:52 i-14fe7093 systemd[1]: Failed to start SYSV: Nginx is an HTTP(S) server, HTTP(S) reverse proxy and IMAP/POP3 proxy server.
-- Subject: Unit nginx.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit nginx.service has failed.
--
-- The result is failed.
Jan 02 23:19:52 i-14fe7093 systemd[1]: Unit nginx.service entered failed state.
Jan 02 23:19:52 i-14fe7093 systemd[1]: nginx.service failed.
Jan 02 23:19:52 i-14fe7093 polkitd[1300]: Unregistered Authentication Agent for unix-process:15548:1690636 (system bus name :1.71, object path /org/freedesktop/PolicyKi
Jan 02 23:19:52 i-14fe7093 root[15630]: [euid=root]:root pts/0 2018-01-02 23:07 (10.247.123.130):[/usr/local/nginx]2018-01-02 23:19:49 root /etc/init.d/nginx start
Jan 02 23:20:01 i-14fe7093 CROND[15632]: (root) CMD (/sbin/ntpdate pool.ntp.org > /dev/null 2>&1)
Jan 02 23:20:31 i-14fe7093 root[15675]: [euid=root]:root pts/0 2018-01-02 23:07 (10.247.123.130):[/usr/local/nginx]2018-01-02 23:20:31 root systemctl status nginx.servi
Jan 02 23:20:58 i-14fe7093 root[15685]: [euid=root]:root pts/0 2018-01-02 23:07 (10.247.123.130):[/usr/local/nginx]2018-01-02 23:20:31 root systemctl status nginx.servi
-- Logs begin at Tue 2018-01-02 18:38:04 CST, end at Tue 2018-01-02 23:20:58 CST. --
Jan 02 23:19:49 i-14fe7093 systemd[1]: Starting SYSV: Nginx is an HTTP(S) server, HTTP(S) reverse proxy and IMAP/POP3 proxy server...
-- Subject: Unit nginx.service has begun start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit nginx.service has begun starting up.
Jan 02 23:19:50 i-14fe7093 nginx[15553]: Starting nginx: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Jan 02 23:19:50 i-14fe7093 nginx[15553]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Jan 02 23:19:51 i-14fe7093 nginx[15553]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Jan 02 23:19:51 i-14fe7093 nginx[15553]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Jan 02 23:19:52 i-14fe7093 nginx[15553]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Jan 02 23:19:52 i-14fe7093 nginx[15553]: nginx: [emerg] still could not bind()
Jan 02 23:19:52 i-14fe7093 nginx[15553]: [FAILED]
Jan 02 23:19:52 i-14fe7093 systemd[1]: nginx.service: control process exited, code=exited status=1
Jan 02 23:19:52 i-14fe7093 systemd[1]: Failed to start SYSV: Nginx is an HTTP(S) server, HTTP(S) reverse proxy and IMAP/POP3 proxy server.
-- Subject: Unit nginx.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit nginx.service has failed.
--
-- The result is failed.
Jan 02 23:20:01 i-14fe7093 CROND[15632]: (root) CMD (/sbin/ntpdate pool.ntp.org > /dev/null 2>&1)
Jan 02 23:20:31 i-14fe7093 root[15675]: [euid=root]:root pts/0 2018-01-02 23:07 (10.247.123.130):[/usr/local/nginx]2018-01-02 23:20:31 root systemctl status nginx.servi
Jan 02 23:20:58 i-14fe7093 root[15685]: [euid=root]:root pts/0 2018-01-02 23:07 (10.247.123.130):[/usr/local/nginx]2018-01-02 23:20:31 root systemctl status nginx.servi
# -lt 列出监听的TCP端口, -u 或 --udp 显示UDP传输协议的连线状况,-n 输出中不解析主机、端口、名称, -p 显示进程ID和名称
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:11211 0.0.0.0:* LISTEN 1065/memcached
tcp 0 0 127.0.0.1:6379 0.0.0.0:* LISTEN 1005/redis-server 1
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 816/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 958/master
tcp 0 0 10.247.110.35:95 0.0.0.0:* LISTEN 891/python
tcp6 0 0 :::8080 :::* LISTEN 1160/java
tcp6 0 0 :::80 :::* LISTEN 812/httpd
tcp6 0 0 :::22 :::* LISTEN 816/sshd
tcp6 0 0 ::1:25 :::* LISTEN 958/master
tcp6 0 0 :::443 :::* LISTEN 812/httpd
tcp6 0 0 127.0.0.1:8006 :::* LISTEN 1160/java
udp 0 0 127.0.0.1:11211 0.0.0.0:* 1065/memcached
udp 0 0 0.0.0.0:68 0.0.0.0:* 756/dhclient
udp 0 0 0.0.0.0:28965 0.0.0.0:* 756/dhclient
udp6 0 0 :::50624 :::* 756/dhclient
#杀死指定PID的进程
[root@i-14fe7093 nginx]# kill 812
#检验进程是否杀死
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:11211 0.0.0.0:* LISTEN 1065/memcached
tcp 0 0 127.0.0.1:6379 0.0.0.0:* LISTEN 1005/redis-server 1
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 816/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 958/master
tcp 0 0 10.247.110.35:95 0.0.0.0:* LISTEN 891/python
tcp6 0 0 :::8080 :::* LISTEN 1160/java
tcp6 0 0 :::22 :::* LISTEN 816/sshd
tcp6 0 0 ::1:25 :::* LISTEN 958/master
tcp6 0 0 127.0.0.1:8006 :::* LISTEN 1160/java
udp 0 0 127.0.0.1:11211 0.0.0.0:* 1065/memcached
udp 0 0 0.0.0.0:68 0.0.0.0:* 756/dhclient
udp 0 0 0.0.0.0:28965 0.0.0.0:* 756/dhclient
udp6 0 0 :::50624 :::* 756/dhclient
#重启Nginx,此时没有残留进程占用80端口了