故障 -> nginx启动失败
描述:在用saltstack给 minion 安装 nginx 服务 时 提示 nginx 服务下载成功,但是启动失败。
---------- ID: nginx-systemctl Function: service.running Name: nginx Result: False Comment: Service nginx failed to start Started: 09:32:48.221250 Duration: 3317.741 ms Changes: ---------- nginx: False
然后就去minion 端查看了一下 端口是否开启 netstat -lntup 发现没有nginx 进程也没有
然后手动起了一下 提示 如下报错:
[root@salt1-minion ~]# systemctl start nginx Job for nginx.service failed because the control process exited with error code. See "systemctl status nginx.service" and "journalctl -xe" for details.
意思就是Nginx服务起不来了,然后查看一下状态吧, systemctl status nginx
[root@salt1-minion ~]# systemctl status nginx ● nginx.service - The nginx HTTP and reverse proxy server Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled) Active: failed (Result: exit-code) since Wed 2018-11-21 09:33:38 CST; 15s ago Process: 1475 ExecStart=/usr/sbin/nginx (code=exited, status=1/FAILURE) Process: 1472 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=0/SUCCESS) Process: 1471 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/SUCCESS) Nov 21 09:33:37 salt1-minion nginx[1475]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use) Nov 21 09:33:37 salt1-minion nginx[1475]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use) Nov 21 09:33:37 salt1-minion nginx[1475]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use) Nov 21 09:33:38 salt1-minion nginx[1475]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use) Nov 21 09:33:38 salt1-minion nginx[1475]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use) Nov 21 09:33:38 salt1-minion systemd[1]: nginx.service: control process exited, code=exited status=1 Nov 21 09:33:38 salt1-minion nginx[1475]: nginx: [emerg] still could not bind() Nov 21 09:33:38 salt1-minion systemd[1]: Failed to start The nginx HTTP and reverse proxy server. Nov 21 09:33:38 salt1-minion systemd[1]: Unit nginx.service entered failed state. Nov 21 09:33:38 salt1-minion systemd[1]: nginx.service failed.
从报错信息中会看到,Address already in use ,意思就是地址已经被使用了。当时发现了自己的失误,原来是之前下载过httpd ,也是80端口。
那就去修改一下nginx 的配置文件吧 ,修改端口,去到 /etc/nginx/nginx.conf文件里,把端口修改为443
server { listen 443 default_server; listen [::]:443 default_server;
然后重新启动服务
[root@salt1-minion nginx]# netstat -lntup 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:22 0.0.0.0:* LISTEN 914/sshd tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1001/master tcp 0 0 0.0.0.0:443 0.0.0.0:* LISTEN 1507/nginx: master tcp6 0 0 :::80 :::* LISTEN 919/httpd tcp6 0 0 :::22 :::* LISTEN 914/sshd tcp6 0 0 ::1:25 :::* LISTEN 1001/master tcp6 0 0 :::443 :::* LISTEN 1507/nginx: master [root@salt1-minion nginx]# systemctl status nginx ● nginx.service - The nginx HTTP and reverse proxy server Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled) Active: active (running) since Wed 2018-11-21 09:35:20 CST; 9s ago Process: 1505 ExecStart=/usr/sbin/nginx (code=exited, status=0/SUCCESS)
最后网页访问 主机加端口测试,没有问题。