红联Linux门户
Linux帮助

Centos7安装mongodb出现的问题:服务无法启动

发布时间:2017-01-03 11:31:21来源:linux网站作者:Baojia-Wang
问题描述:
Centos7安装MongoDB刚开始安装成功时执行sudo service mongod start 能启动,执行sudo service mongod status显示Active: active (running),但如果我重新启动系统,service又不能启动了。如果我卸载和再次安装,刚安装成功能启动服务,但在重新启动后,还是出现原来的状况,上代码:
[brody@localhost Desktop]$ sudo systemctl status  mongod.service
mongod.service - High-performance, schema-free document-oriented database
Loaded: loaded (/usr/lib/systemd/system/mongod.service; enabled; vendor preset: disabled)
Active: failed (Result: exit-code)
Docs: https://docs.mongodb.org/manual
Process: 1570 ExecStart=/usr/bin/mongod $OPTIONS run (code=exited, status=1/FAILURE) 
Main PID: 1570 (code=exited, status=1/FAILURE)
localhost.localdomain systemd[1]: Started High-performance, s...
localhost.localdomain systemd[1]: Starting High-performance, ...
localhost.localdomain mongod[1570]: about to fork child proce...
localhost.localdomain mongod[1570]: forked process: 1591
localhost.localdomain systemd[1]: mongod.service: main proces...
localhost.localdomain systemd[1]: Unit mongod.service entered...
localhost.localdomain systemd[1]: mongod.service failed.
Hint: Some lines were ellipsized, use -l to show in full.
 
解决办法:
1.编辑mongod.conf
sudo vim /etc/mongod.conf
把fork修改为 false , pidFilePath修改为dbPath的路径,我这里在storage显示为dbPath: /var/lib/mongo,即设置为:
fork: false # fork and run in background
pidFilePath: /var/lib/mongo/mongod.pid # location of
如下所是:
# Where and how to store data.
storage:
dbPath: /var/lib/mongo
journal:
enabled: true
#  engine:
#  mmapv1:
#  wiredTiger:
# how the process runs
processManagement:
fork: false  # fork and run in background
pidFilePath: /var/lib/mongo/mongod.pid  # location of pidfile
2.设置firewall
sudo firewall-cmd --zone=public --permanent --add-port=27017/tcp; firewall-cmd --reload
3.重启查看验证
sudo tail -f /var/log/mongodb/mongod.log  & systemctl restart mongod; systemctl status mongod
4.重启电脑
 
参考文献:
[1]
Centos7安装mongodb出现的问题:服务无法启动
[2]官方文档:https://docs.mongodb.com/manual/reference/configuration-options/#storage.wiredTiger
 
本文永久更新地址:http://www.linuxdiyf.com/linux/27488.html