centos7 · 2023年7月3日

Job for mongod.service failed ——一次因为Linux权限问题导致的MongoDB启动失败

前言
最新因为安全性问题修改了MongoDB的配置文件,结果在重启MongoDB服务时却爆出了这个错误:

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

不明觉厉,那就先照着指引一步一步来,首先复制指令:systemctl status mongod.service

运行之后果然发现了一个错误:

● mongod.service – MongoDB Database Server
Loaded: loaded (/usr/lib/systemd/system/mongod.service; enabled; vendor preset: disabled)
Active: active (running) since Fri 2021-04-23 09:45:33 CST; 13min ago
Docs: https://docs.mongodb.org/manual
Process: 8633 ExecStart=/usr/bin/mongod $OPTIONS (code=exited, status=14)
Process: 8631 ExecStartPre=/usr/bin/chmod 0755 /var/run/mongodb (code=exited, status=0/SUCCESS)
Process: 8629 ExecStartPre=/usr/bin/chown mongod:mongod /var/run/mongodb (code=exited, status=0/SUCCESS)
Process: 8628 ExecStartPre=/usr/bin/mkdir -p /var/run/mongodb (code=exited, status=0/SUCCESS)
Main PID: 8636 (mongod)
CGroup: /system.slice/mongod.service
└─8636 /usr/bin/mongod -f /etc/mongod.conf

Apr 23 09:45:31 VM-4-13-centos systemd[1]: Starting MongoDB Database Server…
Apr 23 09:45:31 VM-4-13-centos mongod[8633]: about to fork child process, waiting until server is ready for connections.
Apr 23 09:45:31 VM-4-13-centos mongod[8633]: forked process: 8636
Apr 23 09:45:33 VM-4-13-centos systemd[1]: Started MongoDB Database Failed.
Process: 8633 ExecStart=/usr/bin/mongod $OPTIONS (code=exited, status=14)

这里报了个错误,导致MongoDB服务无法启动,谷歌一下发现应该是属于Linux系统的权限问题。

解决方案
以CentOS系统为例,我们进入到/tmp目录并找到mongodb-27017.sock文件

[root@centos ~]# cd /tmp
[root@centos ~]# ls -l *.sock
修改文件权限:

chown mongod:mongod mongodb-27017.sock
重启MongoDB,发现没有问题,已经成功启动:

 

通过http方式访问:

 

至此,问题解决
————————————————
版权声明:本文为CSDN博主「阿小宅宅」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/weixin_39549527/article/details/116043820