Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can not start MongoDB 3.2.1 on CentOS 7

I followed this doc to install MongoDB 3.2.1 on CentOS 7. After installing, I change the owner and group of var/lib/mongo and var/log/mongodb/mongod.log to root:root.

When I start the mongodb with service mongod start, it just shows

Starting mongod (via systemctl):  Job for mongod.service failed. See 'systemctl status mongod.service' and 'journalctl -xn' for details.[FAILED]

I have run the two commands to show details.

systemctl status mongod.service shows

mongod.service - SYSV: Mongo is a scalable, document-oriented database.
   Loaded: loaded (/etc/rc.d/init.d/mongod)
   Active: failed (Result: exit-code) since Wen 2016-01-27 18:32:46 CST; 14s ago
  Process: 24913 ExecStart=/etc/rc.d/init.d/mongod start (code=exited, status=1/FAILURE)
 Main PID: 23711 (code=exited, status=0/SUCCESS)

1月 27 18:32:45 server1 systemd[1]: Starting SYSV: Mongo is a scalable, document-oriented database....
1月 27 18:32:45 server1 runuser[24920]: pam_unix(runuser:session): session opened for user mongod by (uid=0)
1月 27 18:32:46 server1 mongod[24913]: Starting mongod: [FAILED]
1月 27 18:32:46 server1 systemd[1]: mongod.service: control process exited, code=exited status=1
1月 27 18:32:46 server1 systemd[1]: Failed to start SYSV: Mongo is a scalable, document-oriented database..
1月 27 18:32:46 server1 systemd[1]: Unit mongod.service entered failed state.

journalctl -xn shows

-- Logs begin at 日 2016-01-24 16:33:05 CST, end at Wen 2016-01-27 18:32:46 CST. --
1月 27 18:32:15 server1 sshd[24879]: pam_succeed_if(sshd:auth): requirement "uid >= 1000" not met by user "root"
1月 27 18:32:17 server1 sshd[24879]: Failed password for root from 182.100.67.59 port 10013 ssh2
1月 27 18:32:45 server1 sudo[24896]: root : TTY=pts/0 ; PWD=/var/log/mongodb ; USER=root ; COMMAND=/sbin/service mongod start
1月 27 18:32:45 server1 systemd[1]: Starting SYSV: Mongo is a scalable, document-oriented database....
-- Subject: Unit mongod.service has begun with start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit mongod.service has begun starting up.
1月 27 18:32:45 server1 runuser[24920]: pam_unix(runuser:session): session opened for user mongod by (uid=0)
1月 27 18:32:46 server1 runuser[24920]: pam_unix(runuser:session): session closed for user mongod
1月 27 18:32:46 server1 mongod[24913]: Starting mongod: [FAILED]
1月 27 18:32:46 server1 systemd[1]: mongod.service: control process exited, code=exited status=1
1月 27 18:32:46 server1 systemd[1]: Failed to start SYSV: Mongo is a scalable, document-oriented database..
-- Subject: Unit mongod.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit mongod.service has failed.
-- 
-- The result is failed.
1月 27 18:32:46 server1 systemd[1]: Unit mongod.service entered failed state.

I accessed the server with ssh key, no password.

like image 749
Brick Yang Avatar asked Jan 27 '16 10:01

Brick Yang


3 Answers

Is the any reason to change ownership to root?

Both /var/lib/mongo and /var/log/mongodb should be writable by mongodb user.

By default it is mongodb:mongodb. Check which user runs mongodb service in /etc/init.d/mongodb. If it is something like DAEMONUSER=${DAEMONUSER:-mongodb} then chown your directories back to this user.

like image 124
Alex Blex Avatar answered Nov 17 '22 17:11

Alex Blex


A very similar issue can be caused by selinux permissions, which is enabled by default in CentOS 7. This can be fixed by disabling selinux or adding the correct context to the mongo database path using:

chcon -R -t mongod_var_lib_t /var/lib/mongod
like image 23
Mark Avatar answered Nov 17 '22 18:11

Mark


Well I tried everything people mentioned with no luck, so I ended building a simple unit service file for it, since in my case the problem looks to be related to the init script (https://jira.mongodb.org/plugins/servlet/mobile#issue/SERVER-18439/comment/915785).

I created the service file here:

/etc/systmd/system/mongodb.service

with this as the content:

[Unit]
Description=MongoDB Database Service
Wants=network.target
After=network.target
[Service]
Type=forking
PIDFile=/var/run/mongodb/mongod.pid
ExecStart=/usr/bin/mongod --config /etc/mongod.conf
ExecReload=/bin/kill -HUP $MAINPID
Restart=always
User=mongod
Group=mongod
StandardOutput=syslog
StandardError=syslog
[Install]
WantedBy=multi-user.target

After that all I do was to start it as:

$ sudo systemctl start mongodb

I hope this can help anybody else.

like image 1
David Chaverri Avatar answered Nov 17 '22 18:11

David Chaverri