当前位置: 首页 > 工具软件 > pam-mongodb > 使用案例 >

centos下mongodb自定义数据目录或日志目录后无法启动

伯博
2023-12-01

描述现象

在修改/etc/mongod.conf文件storage.dbPathsystemLog.path前mongodb能够正常启动;修改storage.dbPathsystemLog.path后使用sudo systemctl restart mongod报错:

Restarting mongod (via systemctl): Job for mongod.service failed. See ‘systemctl status mongod.service’ and ‘journalctl -xn’ for details.

使用sudo systemctl start mongo查看状态显示启动失败,展示信息类似如下(我的测试截图不方便粘贴):

 mongod.service - SYSV: Mongo is a scalable, document-oriented database.
 Loaded: loaded (/etc/rc.d/init.d/mongod; bad; vendor preset: disabled)
 Active: failed (Result: exit-code) since Fri 2017-06-23 06:07:56 UTC; 19h ago
 Docs: man:systemd-sysv-generator(8)
 Process: 2547 ExecStop=/etc/rc.d/init.d/mongod stop (code=exited, status=0/SUCCESS)
 Process: 2588 ExecStart=/etc/rc.d/init.d/mongod start (code=exited, status=1/FAILURE)
 Main PID: 2350 (code=exited, status=0/SUCCESS)
Jun 23 06:07:56 localhost.localdomain systemd[1]: Starting SYSV: Mongo is a scalable, documentoriented database....
Jun 23 06:07:56 localhost.localdomain runuser[2597]: pam_unix(runuser:session): session opened
for user mongod by (uid=0)
Jun 23 06:07:56 localhost.localdomain mongod[2588]: Starting mongod: [FAILED]
Jun 23 06:07:56 localhost.localdomain systemd[1]: mongod.service: control process exited,
code=exited status=1
Jun 23 06:07:56 localhost.localdomain systemd[1]: Failed to start SYSV: Mongo is a scalable,
document-oriented database..
Jun 23 06:07:56 localhost.localdomain systemd[1]: Unit mongod.service entered failed state.
Jun 23 06:07:56 localhost.localdomain systemd[1]: mongod.service failed.

如果自定义数据和日志目录需要赋予权限给mongod用户

sudo chown -R mongod:mongod directory

确定问题

使用cat /etc/selinux/config查看系统配置,查看SELINUX配置项,Disable: 禁用SELinux,不会给任何新资源打Label,如果重新启用的话,将会给资源重新打上Lable,过程会比较缓慢。Permissive:如果违反安全策略,并不会真正的执行拒绝操作,替代的方式是记录一条log信息。Enforcing: 默认模式,SELinux的正常状态,会实际禁用违反策略的操作。

# 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
# SELINUXTYPE= can take one of these two values:
#       targeted - Targeted processes are protected,
#       mls - Multi Level Security protection.
SELINUXTYPE=targeted

使用getenforce 命令返回值为enforcing表示当前系统为安全增强式Linux。

解决问题

  1. 如果不需要安全增强式Linux则可以使用setenforce 0暂时关闭,重启会重新读取/etc/selinux/config配置文件的值,如果需要永久有效需要修改/etc/selinux/config文件SELINUX=disable。
  2. 需要安全增强式Linux,参考官网的安装指导;官网的指导有专门提及的只是未指明如何判断是否是SELINUX。

参考链接

https://docs.mongodb.com/manual/tutorial/install-mongodb-on-red-hat/
https://zhuanlan.zhihu.com/p/86813709
https://dba.stackexchange.com/questions/95539/mongodb-doesnt-start-after-changing-the-data-directory

 类似资料: