我按照此文档在CentOS 7上安装MongoDB 3.2.1。安装完成后,我将var/lib/mongo
和var/log/mongodb/mongod.log
的所有者和组更改为root:root
。
当我使用service mongod start
启动mongodb时,它只显示
Starting mongod (via systemctl): Job for mongod.service failed. See 'systemctl status mongod.service' and 'journalctl -xn' for details.[FAILED]
我已经运行了两个命令来显示详细信息。
systemctl status mongod.service
显示
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
显示
-- 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.
我使用ssh密钥访问服务器,没有密码。
答案 0 :(得分:5)
是否有任何理由将所有权更改为root?
mongodb用户应该可以写/var/lib/mongo
和/var/log/mongodb
。
默认情况下为mongodb:mongodb
。检查哪个用户在/etc/init.d/mongodb
中运行mongodb服务。如果它类似于DAEMONUSER=${DAEMONUSER:-mongodb}
,则将您的目录重新命名为该用户。
答案 1 :(得分:3)
一个非常类似的问题可能是由selinux权限引起的,这在CentOS 7中是默认启用的。这可以通过禁用selinux或使用以下方法将正确的上下文添加到mongo数据库路径来解决:
chcon -R -t mongod_var_lib_t /var/lib/mongod
答案 2 :(得分:1)
我尝试了人们提到的所有内容都没有运气,所以我结束了为它构建一个简单的单元服务文件,因为在我的情况下,问题看起来与init脚本(https://jira.mongodb.org/plugins/servlet/mobile#issue/SERVER-18439/comment/915785)有关。
我在这里创建了服务文件:
/etc/systmd/system/mongodb.service
以此为内容:
[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
之后我所做的就是以:
开始$ sudo systemctl start mongodb
我希望这可以帮助其他人。