在修改/etc/mongod.conf
文件storage.dbPath
或systemLog.path
前mongodb能够正常启动;修改storage.dbPath
和systemLog.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。
setenforce 0
暂时关闭,重启会重新读取/etc/selinux/config
配置文件的值,如果需要永久有效需要修改/etc/selinux/config
文件SELINUX=disable。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