无法在 CentOS 7 上启动 MongoDB 3.2.1
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35035088/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Can not start MongoDB 3.2.1 on CentOS 7
提问by Brick Yang
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
.
我跟着这个文档上的CentOS 7安装的MongoDB 3.2.1安装完成后,我改变了所有者和组var/lib/mongo
和var/log/mongodb/mongod.log
到root:root
。
When I start the mongodb with service mongod start
, it just shows
当我用 启动 mongodb 时service mongod start
,它只显示
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
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
shows
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.
I accessed the server with ssh key, no password.
我使用 ssh 密钥访问了服务器,没有密码。
回答by Alex Blex
Is the any reason to change ownership to root?
是否有任何理由将所有权更改为 root?
Both /var/lib/mongo
and /var/log/mongodb
should be writable by mongodb user.
双方/var/lib/mongo
并/var/log/mongodb
应该是MongoDB的用户可写。
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.
默认情况下是mongodb:mongodb
. 检查哪个用户在/etc/init.d/mongodb
. 如果是这样,DAEMONUSER=${DAEMONUSER:-mongodb}
则将您的目录返回给该用户。
回答by Mark
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:
一个非常相似的问题可能是由 selinux 权限引起的,它在 CentOS 7 中默认启用。 这可以通过禁用 selinux 或使用以下方法将正确的上下文添加到 mongo 数据库路径来解决:
chcon -R -t mongod_var_lib_t /var/lib/mongod
回答by David Chaverri
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).
好吧,我尝试了人们提到的一切都没有运气,所以我结束了为它构建一个简单的单元服务文件,因为在我的情况下,问题看起来与 init 脚本(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.
我希望这可以帮助其他人。