除非以root身份运行,否则启动mongod将会失败 [英] Starting mongod fails unless run as root

查看:287
本文介绍了除非以root身份运行,否则启动mongod将会失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以使用以下命令启动mongo服务器:

I am able to start my mongo server with the following command:

[lucas@ecoinstance]~/node/nodetest2$ sudo mongod --dbpath /home/lucas/node/nodetest2/data
 --fork --logpath /var/log/mongodb/mongod-nodetest2.log                                  
about to fork child process, waiting until server is ready for connections.
forked process: 10293
child process started successfully, parent exiting

但是当我尝试删除sudo时,出现以下错误:

but when I try to remove the sudo, I get the following error:

[lucas@ecoinstance]~/node/nodetest2$ mongod --dbpath /home/lucas/node/nodetest2/
data --fork --logpath /var/log/mongodb/mongod-nodetest2.log
about to fork child process, waiting until server is ready for connections.
forked process: 10284
ERROR: child process failed, exited with error number 1

以下是其他信息:

[lucas@ecoinstance]~/node/nodetest2$ ls -l data/*
-rw------- 1 mongodb mongodb 67108864 Jun  7 20:57 data/local.0
-rw------- 1 mongodb mongodb 16777216 Jun  7 20:57 data/local.ns
-rwxr-xr-x 1 mongodb mongodb        6 Jun  7 20:57 data/mongod.lock
-rw------- 1 mongodb mongodb 67108864 Jun  7 02:08 data/nodetest1.0
-rw------- 1 mongodb mongodb 16777216 Jun  7 02:08 data/nodetest1.ns
-rw------- 1 mongodb mongodb 67108864 Jun  7 23:01 data/nodetest2.0
-rw------- 1 mongodb mongodb 16777216 Jun  7 23:01 data/nodetest2.ns

data/journal:
total 3145744
-rw------- 1 mongodb mongodb 1073741824 Jun  7 23:01 j._0
-rw------- 1 root    root            88 Jun  7 23:01 lsn
-rw------- 1 mongodb mongodb 1073741824 Jun  6 03:10 prealloc.1
-rw------- 1 mongodb mongodb 1073741824 Jun  6 03:12 prealloc.2

[lucas@ecoinstance]~/node/nodetest2$ ls -l /etc/mongod.conf 
-rw-r--r-- 1 mongodb mongodb 1701 May  5 15:07 /etc/mongod.conf

[lucas@ecoinstance]~/node/nodetest2$ ls -l /var/log/mongodb/
total 120
-rw-r--r-- 1 mongodb mongodb 96801 Jun  7 05:48 mongod.log
-rw-r--r-- 1 root    root    15625 Jun  8 00:18 mongod-nodetest2.log
-rw-r--r-- 1 mongodb mongodb  2805 Jun  7 20:38 mongod-nodetest2.log.2014-06-07T20-57-47

我找不到类似的问题.是什么原因造成的?

I cannot find a similar problem. What is the cause of this issue?

更新 感谢以下Asya的回答,我运行了一个类似的命令,但是将日志文件的位置更改为不需要root访问权限的位置:

Update Thanks to Asya's answer below, I ran a similar command, but changed the location of the log file to one which does not need root access privileges:

mongod --dbpath /home/lucas/node/nodetest2/data --fork --logpath /home/lucas/data/log/mongodb/mongod-nodetest2.log

我还遇到了mongod在后台运行的问题,类似于这个问题.在运行上述命令之前停止该过程对我有用.

I also encountered an issue where mongod was running in the background, similar to this question. Stopping that process before running the above command worked for me.

感谢Asya!

推荐答案

如果您以用户xxx身份启动mongod,则它需要使用的所有目录和文件都必须由用户xxx拥有-在您的情况下,我看到了root拥有几个文件,因此mongod无法操纵这些文件.

If you start mongod as user xxx then all the directories and files it needs to use must be owned by user xxx - in your case I see several files owned by root so mongod cannot manipulate those files.

修复权限,并确保不再以root用户身份运行mongod.另外,当您从mongod中收到错误消息时,在日志文件中查找会告诉您造成错误的确切原因. (在所有情况下,除非用户mongod不可写该文件的运行方式).

Fix the permissions and make sure you never run mongod as root again. Also, when you get an error from mongod looking in the log file will tell you exactly what caused an error. (In all cases except where the file is not writable by the user mongod is running as).

这篇关于除非以root身份运行,否则启动mongod将会失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆