描述:在用saltstack给 minion 安装 nginx 服务 时 提示 nginx 服务下载成功,但是启动失败。
----------
ID: nginx-systemctl
Function: service.running
Name: nginx
Result: False
Comment: Service nginx failed to start
Started: ::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 -- :: CST; 15s ago
Process: ExecStart=/usr/sbin/nginx (code=exited, status=/FAILURE)
Process: ExecStartPre=/usr/sbin/nginx -t (code=exited, status=/SUCCESS)
Process: ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=/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 :: salt1-minion nginx[]: nginx: [emerg] bind() to [::]: failed (: Address already in use)
Nov :: salt1-minion nginx[]: nginx: [emerg] bind() to 0.0.0.0: failed (: Address already in use)
Nov :: salt1-minion nginx[]: nginx: [emerg] bind() to [::]: failed (: Address already in use)
Nov :: salt1-minion systemd[]: nginx.service: control process exited, code=exited status=
Nov :: salt1-minion nginx[]: nginx: [emerg] still could not bind()
Nov :: salt1-minion systemd[]: Failed to start The nginx HTTP and reverse proxy server.
Nov :: salt1-minion systemd[]: Unit nginx.service entered failed state.
Nov :: salt1-minion systemd[]: nginx.service failed.
从报错信息中会看到,Address already in use ,意思就是地址已经被使用了。当时发现了自己的失误,原来是之前下载过httpd ,也是80端口。
那就去修改一下nginx 的配置文件吧 ,修改端口,去到 /etc/nginx/nginx.conf文件里,把端口修改为443
server {
listen default_server;
listen [::]: 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.0.0:* LISTEN /sshd
tcp 127.0.0.1: 0.0.0.0:* LISTEN /master
tcp 0.0.0.0:443 0.0.0.0:* LISTEN /nginx: master
tcp6 ::: :::* LISTEN /httpd
tcp6 ::: :::* LISTEN /sshd
tcp6 ::: :::* LISTEN /master
tcp6 ::: :::* LISTEN /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 -- :: CST; 9s ago
Process: ExecStart=/usr/sbin/nginx (code=exited, status=/SUCCESS)
最后网页访问 主机加端口测试,没有问题。