主机使用ansible指令,控制多台从机安装nginx软件并自动化运行,出现报错:Unable to start service nginx: Job for nginx.service faile

主机使用ansible指令,控制多台从机安装nginx软件并自动化运行,在主机的位置运行最后出现报错:

TASK [Start nginx] *************************************************************************************************************************************************************************************************************
fatal: [192.168.0.108]: FAILED! => {"changed": false, "msg": "Unable to start service nginx: Job for nginx.service failed because the control process exited with error code. See \"systemctl status nginx.service\" and \"journalctl -xe\" for details.\n"}
fatal: [192.168.0.110]: FAILED! => {"changed": false, "msg": "Unable to start service nginx: Job for nginx.service failed because the control process exited with error code. See \"systemctl status nginx.service\" and \"journalctl -xe\" for details.\n"}

PLAY RECAP *********************************************************************************************************************************************************************************************************************
192.168.0.108              : ok=4    changed=1    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0   
192.168.0.110              : ok=4    changed=1    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0  
 

[root@localhost ansible-demo]# ansible-playbook nginx.yml

PLAY [group1] ******************************************************************************************************************************************************************************************************************

TASK [Gathering Facts] *********************************************************************************************************************************************************************************************************
ok: [192.168.0.110]
ok: [192.168.0.108]

TASK [Add repo] ****************************************************************************************************************************************************************************************************************
ok: [192.168.0.110]
ok: [192.168.0.108]

TASK [Install nginx] ***********************************************************************************************************************************************************************************************************
changed: [192.168.0.110]
changed: [192.168.0.108]

TASK [Copy nginx configuration file] *******************************************************************************************************************************************************************************************
ok: [192.168.0.110]
ok: [192.168.0.108]

TASK [Start nginx] *************************************************************************************************************************************************************************************************************
fatal: [192.168.0.108]: FAILED! => {"changed": false, "msg": "Unable to start service nginx: Job for nginx.service failed because the control process exited with error code. See \"systemctl status nginx.service\" and \"journalctl -xe\" for details.\n"}
fatal: [192.168.0.110]: FAILED! => {"changed": false, "msg": "Unable to start service nginx: Job for nginx.service failed because the control process exited with error code. See \"systemctl status nginx.service\" and \"journalctl -xe\" for details.\n"}

PLAY RECAP *********************************************************************************************************************************************************************************************************************
192.168.0.108              : ok=4    changed=1    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0   
192.168.0.110              : ok=4    changed=1    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0   

然而我在从机的位置启动NGINX却出现报错:

[root@agent1 ~]# 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.
[root@agent1 ~]# systemctl status nginx
● nginx.service - nginx - high performance web server
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since Wed 2020-05-20 14:40:30 UTC; 6s ago
     Docs: http://nginx.org/en/docs/
  Process: 2226 ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf (code=exited, status=1/FAILURE)

May 20 14:40:30 agent1.cluster.com systemd[1]: Starting nginx - high performance web server...
May 20 14:40:30 agent1.cluster.com nginx[2226]: nginx: [emerg] bind() to 0.0.0.0:90 failed (13: Permission denied)
May 20 14:40:30 agent1.cluster.com systemd[1]: nginx.service: control process exited, code=exited status=1
May 20 14:40:30 agent1.cluster.com systemd[1]: Failed to start nginx - high performance web server.
May 20 14:40:30 agent1.cluster.com systemd[1]: Unit nginx.service entered failed state.
May 20 14:40:30 agent1.cluster.com systemd[1]: nginx.service failed.

这个原因可能有两种,我建议你都试一下:

第一个原因就是你的NGINX端口冲突了,你改一下NGINX的默认端口吧!!

解决方案是:

vim /etc/nginx/conf.d/default.conf 
  • 注意:更改listen的端口,因为原来的端口被占用( Address already in use)

第二个原因就是你的centos7系统有些默认配置使用问题的,你需要改一下!(selinux引起nginx启动失败)

解决方法:

发现是因为selinux状态是enforcing,关闭了selinux再启动nginx就好了

[root@test101 nginx]# vim /etc/selinux/config 
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=enforcing         #改成disabled就OK了
# SELINUXTYPE= can take one of three two values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected. 
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章