报错来了不要崩!nginx服务启动失败排错分析!

1.报错提示信息

Job for nginx.service failed because the control process exited with error code. See “systemctl status nginx.service” and “journalctl -xe” for details.

2.报错背景

在完成源码安装LNMP架构完成的情况下,对nginx服务进行优化,选择修改源码方式隐藏版本号,当修改过源码后,重新编译然后make && make install 后,停止服务重启nginx服务时候报错,服务起不来

具体报错信息

[root@localhost nginx-1.15.9]# 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.

3.排错过程分析

根据错误信息内容,nginx的工作。由于控制进程带有错误代码退出,服务失败。参见systemctl status nginx。详细信息请参见“journalctl -xe”。

然后查看详细信息

[root@localhost nginx-1.15.9]# systemctl status nginx
● nginx.service - nginx
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since 六 2021-06-26 19:50:33 CST; 13min ago
  Process: 90630 ExecStop=/bin/kill -s QUIT $MAINPID (code=exited, status=0/SUCCESS)
  Process: 90772 ExecStart=/usr/local/nginx/sbin/nginx (code=exited, status=1/FAILURE)
 Main PID: 87718 (code=exited, status=0/SUCCESS)

626 19:50:33 localhost.localdomain systemd[1]: Starting nginx...
626 19:50:33 localhost.localdomain nginx[90772]: nginx: [emerg] getpwnam(...
626 19:50:33 localhost.localdomain systemd[1]: nginx.service: control pro...
626 19:50:33 localhost.localdomain systemd[1]: Failed to start nginx.
626 19:50:33 localhost.localdomain systemd[1]: Unit nginx.service entered...
626 19:50:33 localhost.localdomain systemd[1]: nginx.service failed.
Hint: Some lines were ellipsized, use -l to show in full.



[root@localhost nginx-1.15.9]# journalctl -xe
-- The result is failed.
626 19:50:33 localhost.localdomain systemd[1]: Unit nginx.service entered fai
626 19:50:33 localhost.localdomain systemd[1]: nginx.service failed.
626 19:50:33 localhost.localdomain polkitd[6314]: Unregistered Authentication
626 20:00:01 localhost.localdomain systemd[1]: Started Session 372 of user ro
-- Subject: Unit session-372.scope has finished start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit session-372.scope has finished starting up.
--
-- The start-up result is done.
626 20:00:01 localhost.localdomain CROND[90855]: (root) CMD (/usr/lib64/sa/sa
626 20:01:01 localhost.localdomain systemd[1]: Started Session 373 of user ro
-- Subject: Unit session-373.scope has finished start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit session-373.scope has finished starting up.
--
-- The start-up result is done.
626 20:01:01 localhost.localdomain CROND[90869]: (root) CMD (run-parts /etc/c
626 20:01:01 localhost.localdomain run-parts(/etc/cron.hourly)[90872]: starti
626 20:01:01 localhost.localdomain run-parts(/etc/cron.hourly)[90878]: finish
lines 2946-2969/2969 (END)

在检查下配置文件

[root@localhost nginx-1.15.9]# nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: [emerg] getpwnam("nging") failed
nginx: configuration file /usr/local/nginx/conf/nginx.conf test failed

Nginx:配置文件/usr/local/nginx/conf/nginx.conf语法是ok的
Nginx: [emerg] getpwnam(“nging”)失败
Nginx:配置文件/usr/local/nginx/conf/nginx.conf测试失败

查看防火墙是关闭状态

[root@localhost nginx-1.15.9]# systemctl status firewalld.service
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
   Active: inactive (dead) since 四 2021-06-24 11:31:04 CST; 2 days ago
     Docs: man:firewalld(1)
  Process: 6428 ExecStart=/usr/sbin/firewalld --nofork --nopid $FIREWALLD_ARGS (code=exited, status=0/SUCCESS)
 Main PID: 6428 (code=exited, status=0/SUCCESS)

617 19:00:44 localhost.localdomain systemd[1]: Starting firewalld - dynam...
617 19:00:44 localhost.localdomain systemd[1]: Started firewalld - dynami...
624 11:31:02 localhost.localdomain systemd[1]: Stopping firewalld - dynam...
624 11:31:04 localhost.localdomain systemd[1]: Stopped firewalld - dynami...
Hint: Some lines were ellipsized, use -l to show in full.

防火墙是关闭的,结合以上的一些信息进行分析,找出主要出现错误的原因位置在哪里
在这里插入图片描述
nginx: [emerg] getpwnam(“nging”) failed

结合百度查找,应该是没有创建nginx用户导致的,然后我又想了一下我之前装好LNMP架构的时候nginx的服务是正常的,只是改了配置文件后,重新编译后出问题的,那是不是我在编译时设置出错了

再仔细查看一下错误信息里内容
6月 26 19:50:33 localhost.localdomain nginx[90772]: nginx: [emerg] getpwnam(“nging”) failed

我才恍然大悟,确实是用户问题,为什么没有,这里说的是没有nging这个用户,我的用户应该是nginx,那应该是我编译之前的指定用户输错了,跑回去在看一下
果然
在这里插入图片描述
那么这里就找到了问题的原因了。

4.解决办法

找到问题就好解决了,既然是编译时指定用户错了,那就改掉指定用户重新编译应该就行了.

[root@localhost nginx-1.15.9]# ./configure \
> --prefix=/usr/local/nginx \
> --user=nginx \
> --group=nginx \
> --with-http_stub_status_module



[root@localhost nginx-1.15.9]# make && make install

5.验证是否成功

编译安装后再启动服务查看是否能够成功


[root@localhost nginx-1.15.9]# systemctl stop nginx
[root@localhost nginx-1.15.9]# systemctl start nginx

[root@localhost nginx-1.15.9]# systemctl status nginx
● nginx.service - nginx
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
   Active: active (running) since 六 2021-06-26 21:10:14 CST; 23s ago
  Process: 90630 ExecStop=/bin/kill -s QUIT $MAINPID (code=exited, status=0/SUCCESS)
  Process: 94103 ExecStart=/usr/local/nginx/sbin/nginx (code=exited, status=0/SUCCESS)
 Main PID: 94104 (nginx)
    Tasks: 2
   CGroup: /system.slice/nginx.service
           ├─94104 nginx: master process /usr/local/nginx/sbin/nginx
           └─94105 nginx: worker process

626 21:10:14 localhost.localdomain systemd[1]: Starting nginx...
626 21:10:14 localhost.localdomain systemd[1]: Started nginx.
[root@localhost nginx-1.15.9]#

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值