主机使用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
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

人生如路兮

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值