Mongo 无法启动服务

Mongo 无法启动服务

我有 Ubuntu 16.04。并按照官方 mongo 网站上的教程重新安装 mongobd -https://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu/ 结果是:mongo -version

MongoDB shell version v4.0.5
git version: 3739429dd92b92d1b0ab120911a23d50bf03c412
OpenSSL version: OpenSSL 1.0.2g  1 Mar 2016
allocator: tcmalloc
modules: none
build environment:
    distmod: ubuntu1604
    distarch: x86_64
    target_arch: x86_64

但我无法启动 mongodb((

sudo systemctl status mongodb
● mongodb.service - High-performance, schema-free document-oriented database
   Loaded: loaded (/etc/systemd/system/mongodb.service; disabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Tue 2019-01-22 16:27:13 UTC; 10s ago
  Process: 29736 ExecStart=/usr/bin/mongod --quiet --config /etc/mongod.conf (code=exited, status=1/FAILURE)
 Main PID: 29736 (code=exited, status=1/FAILURE)

Jan 22 16:27:13 mahumachinen systemd[1]: Started High-performance, schema-free document-oriented database.
Jan 22 16:27:13 mahumachinen systemd[1]: mongodb.service: Main process exited, code=exited, status=1/FAILURE
Jan 22 16:27:13 mahumachinen systemd[1]: mongodb.service: Unit entered failed state.
Jan 22 16:27:13 mahumachinen systemd[1]: mongodb.service: Failed with result 'exit-code'.

请帮忙!

答案1

我可以通过在文件夹上设置错误的所有权来重现您的问题/var/log/mongodb

root@demo:~# ls -lh /var/log/mongodb/
total 512
-rw-r--r-- 1 root root 0 Jan 22 17:57 mongod.log
root@demo:~# systemctl restart mongod
root@demo:~# systemctl status mongod
● mongod.service - MongoDB Database Server
   Loaded: loaded (/lib/systemd/system/mongod.service; disabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Tue 2019-01-22 17:57:13 UTC; 2s ago
     Docs: https://docs.mongodb.org/manual
  Process: 795 ExecStart=/usr/bin/mongod --config /etc/mongod.conf (code=exited, status=1/FAILURE)
 Main PID: 795 (code=exited, status=1/FAILURE)

Jan 22 17:57:13 demo systemd[1]: Started MongoDB Database Server.
Jan 22 17:57:13 demo systemd[1]: mongod.service: Main process exited, code=exited, status=1/FAILURE
Jan 22 17:57:13 demo systemd[1]: mongod.service: Unit entered failed state.
Jan 22 17:57:13 demo systemd[1]: mongod.service: Failed with result 'exit-code'.

尝试更正 MongoDB 日志和数据目录的所有权:

root@demo:~# chown -Rc mongodb. /var/log/mongodb
changed ownership of '/var/log/mongodb/mongod.log' from root:root to mongodb:nogroup
changed ownership of '/var/log/mongodb' from root:root to mongodb:nogroup
root@demo:~# chown -Rc mongodb. /var/lib/mongodb
root@demo:~# systemctl restart mongod
root@demo:~# systemctl status mongod
● mongod.service - MongoDB Database Server
   Loaded: loaded (/lib/systemd/system/mongod.service; disabled; vendor preset: enabled)
   Active: active (running) since Tue 2019-01-22 17:58:30 UTC; 1s ago
     Docs: https://docs.mongodb.org/manual
 Main PID: 802 (mongod)
   CGroup: /system.slice/mongod.service
           └─802 /usr/bin/mongod --config /etc/mongod.conf

Jan 22 17:58:30 demo systemd[1]: Started MongoDB Database Server.

如果这不起作用,请尝试重新安装 MongoDB,删除所有现有数据:

sudo apt purge mongodb-org mongodb-org-mongos mongodb-org-server mongodb-org-shell mongodb-org-tools
sudo rm -rfv /etc/mongod.conf /var/log/mongodb /var/lib/mongodb
sudo find /tmp -type s -iname '*mongodb*' -delete
sudo apt install mongodb-org

相关内容