主機使用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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章