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

问题描述:

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) since Sat 2016-12-17 21:35:08 CST; 3s ago
     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)

Dec 17 21:35:08 localhost.localdomain systemd[1]: Started High-performance, s...
Dec 17 21:35:08 localhost.localdomain systemd[1]: Starting High-performance, ...
Dec 17 21:35:08 localhost.localdomain mongod[1570]: about to fork child proce...
Dec 17 21:35:08 localhost.localdomain mongod[1570]: forked process: 1591
Dec 17 21:35:08 localhost.localdomain systemd[1]: mongod.service: main proces...
Dec 17 21:35:08 localhost.localdomain systemd[1]: Unit mongod.service entered...
Dec 17 21:35:08 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]Stack Overflow http://stackoverflow.com/questions/40829306/mongodb-cant-start-centos-7
[2]官方文档https://docs.mongodb.com/manual/reference/configuration-options/#storage.wiredTiger

阅读更多

没有更多推荐了,返回首页