mongodb is returning errors related to access files when trying to start:
mongodb在尝试启动时返回与访问文件相关的错误:
root@mongo01:~# sudo service mongodb start
mongodb start/running, process 4118
root@mongo01:~# Mon Jul 25 17:03:54 [initandlisten] MongoDB starting : pid=4118 port=27017 dbpath=/var/lib/mongodb 64-bit
Mon Jul 25 17:03:54 [initandlisten] db version v1.8.2, pdfile version 4.5
Mon Jul 25 17:03:54 [initandlisten] git version: 433bbaa14aaba6860da15bd4de8edf600f56501b
Mon Jul 25 17:03:54 [initandlisten] build sys info: Linux bs-linux64.10gen.cc 2.6.21.7-2.ec2.v1.2.fc8xen #1 SMP Fri Nov 20 17:48:28 EST 2009 x86_64 BOOST_LIB_VERSION=1_41
Mon Jul 25 17:03:54 [initandlisten] couldn't open /var/lib/mongodb/adrise.ns errno:13 Permission denied
Mon Jul 25 17:03:54 [initandlisten] error couldn't open file /var/lib/mongodb/adrise.ns terminating
Mon Jul 25 17:03:54 dbexit:
Mon Jul 25 17:03:54 [initandlisten] shutdown: going to close listening sockets...
Mon Jul 25 17:03:54 [initandlisten] shutdown: going to flush diaglog...
Mon Jul 25 17:03:54 [initandlisten] shutdown: going to close sockets...
Mon Jul 25 17:03:54 [initandlisten] shutdown: waiting for fs preallocator...
Mon Jul 25 17:03:54 [initandlisten] shutdown: closing all files...
Mon Jul 25 17:03:54 closeAllFiles() finished
Mon Jul 25 17:03:54 [initandlisten] shutdown: removing fs lock...
Mon Jul 25 17:03:54 dbexit: really exiting now
or
或
Mon Jul 25 17:03:22 [initandlisten] MongoDB starting : pid=4095 port=27017 dbpath=/var/lib/mongodb 64-bit
Mon Jul 25 17:03:22 [initandlisten] db version v1.8.2, pdfile version 4.5
Mon Jul 25 17:03:22 [initandlisten] git version: 433bbaa14aaba6860da15bd4de8edf600f56501b
Mon Jul 25 17:03:22 [initandlisten] build sys info: Linux bs-linux64.10gen.cc 2.6.21.7-2.ec2.v1.2.fc8xen #1 SMP Fri Nov 20 17:48:28 EST 2009 x86_64 BOOST_LIB_VERSION=1_41
Mon Jul 25 17:03:22 [initandlisten] journal dir=/var/lib/mongodb/journal
Mon Jul 25 17:03:22 [initandlisten] recover : no journal files present, no recovery needed
Mon Jul 25 17:03:22 [initandlisten] info preallocateIsFaster couldn't run; returning false
Mon Jul 25 17:03:22 [initandlisten] exception in initAndListen std::exception: couldn't open file /var/lib/mongodb/journal/j._0 for writing errno:13 Permission denied, terminating
Mon Jul 25 17:03:22 dbexit:
Mon Jul 25 17:03:22 [initandlisten] shutdown: going to close listening sockets...
Mon Jul 25 17:03:22 [initandlisten] shutdown: going to flush diaglog...
Mon Jul 25 17:03:22 [initandlisten] shutdown: going to close sockets...
Mon Jul 25 17:03:22 [initandlisten] shutdown: waiting for fs preallocator...
Mon Jul 25 17:03:22 [initandlisten] shutdown: lock for final commit...
Mon Jul 25 17:03:22 [initandlisten] shutdown: final commit...
Mon Jul 25 17:03:22 [initandlisten] shutdown: closing all files...
Mon Jul 25 17:03:22 closeAllFiles() finished
Mon Jul 25 17:03:22 [initandlisten] shutdown: journalCleanup...
Mon Jul 25 17:03:22 [initandlisten] removeJournalFiles
Mon Jul 25 17:03:22 [initandlisten] shutdown: removing fs lock...
Mon Jul 25 17:03:22 dbexit: really exiting now
when I try :
当我尝试:
root@mongo01:~# mongodb -f /etc/mongodb.conf
root@mongo01:~ # mongodb - f /etc/mongodb.conf
it starts properly, any idea what it causing the issues?
它开始的很好,有什么问题吗?
Thanks
谢谢
5 个解决方案
#1
48
Mon Jul 25 17:03:54 [initandlisten] couldn't open /var/lib/mongodb/adrise.ns errno:13 Permission denied
Mon Jul 25 17:03:54 [initandlisten]不能打开/ var/lib/mongodb/adrise。ns errno:13没有权限
It is a permissions issue, run the following command:
它是一个权限问题,运行以下命令:
sudo chown -R mongodb:mongodb /var/lib/mongodb
#2
21
So I had this problem rather suddenly, and I'm not sure why. The problem is that the upstart file wants to run mongo as the user mongodb. From /etc/init/mongodb.conf
:
所以我突然有了这个问题,我不知道为什么。问题是upstart文件想要运行mongo作为用户mongodb。从/etc/init/mongodb.conf:
if [ "x$ENABLE_MONGODB" = "xyes" ]; then exec start-stop-daemon --start --quiet --chuid mongodb --exec /usr/bin/mongod -- --config /etc/mongodb.conf; fi
The chuid part tells it to run as a different user, even though you're running this script as root. For some reason, when I did ls -l
in /var/lib/mongodb
, I noticed that all the files were owned by root, which is why our mongodb user couldn't ge to them. I just did this:
chuid部分告诉它作为一个不同的用户运行,即使您正在运行这个脚本作为根。出于某种原因,当我在/var/lib/mongodb中执行ls -l时,我注意到所有的文件都是root所拥有的,这就是为什么我们的mongodb用户不能使用它们。我只是这样做:
sudo chown mongodb:mongodb /var/lib/mongodb
And all was well. How did the issue happen in the first place? Not sure.
,一切都好。这个问题是怎么发生的?不确定。
#3
1
This file is your first data file /var/lib/mongodb/adrise.ns
. Actually to be specific it's a namespace file that identifies other DB files.
该文件是您的第一个数据文件/var/lib/mongodb/adrise.ns。具体来说,它是一个名称空间文件,用来标识其他的DB文件。
For MongoDB to work, the mongod
process will need access to two folders:
对于MongoDB来说,mongod进程需要访问两个文件夹:
-
Data folder: in your case
/var/lib/mongodb/
- 数据文件夹:在您的示例中/var/lib/mongodb/。
- Log folder: not sure where you've put this
- 日志文件夹:不确定你把它放在哪里了。
Now, if you run this as the root user, it should have access to every every folder. But you should ensure that no one else is locking this folder.
现在,如果作为根用户运行它,它应该可以访问每个文件夹。但是您应该确保没有其他人锁定这个文件夹。
However, you should be able to run this with lower permissions. Typically you only need user-level permissions, just ensure that the user has access to those folder. If possible you'll want to run this at a level lower than root. Many people actually make a mongodb
user and run it in its own context.
但是,您应该能够使用较低的权限运行此操作。通常,您只需要用户级权限,只需要确保用户可以访问这些文件夹。如果可能,您将希望以低于root的级别运行此操作。许多人实际上会创建一个mongodb用户并在自己的上下文中运行它。
#4
0
I had this problem when I remove mongo 3.6 and install mongo 2.4! My solution:
当我移除mongo 3.6并安装mongo 2.4时,我遇到了这个问题。我的解决方案:
- Create new dir for you'r DB (some /var/lib/mongodb)
- 为您创建新的dir(一些/var/lib/mongodb)
- Edit config /etc/mongod.conf (dbpath=/var/lib/mongodb)
- 编辑配置/etc/mongod.配置(dbpath = / var / lib / mongodb)
- Start mongod
- 开始mongod
#5
0
Just try this command.
试试这个命令。
sudo chown -R mongodb:mongodb /var/lib/mongodb
sudo chown -R mongodb:mongodb /var/lib/mongodb。
And
和
sudo service mongod restart
sudo mongod重启服务
may help you.
可能会帮助你。
#1
48
Mon Jul 25 17:03:54 [initandlisten] couldn't open /var/lib/mongodb/adrise.ns errno:13 Permission denied
Mon Jul 25 17:03:54 [initandlisten]不能打开/ var/lib/mongodb/adrise。ns errno:13没有权限
It is a permissions issue, run the following command:
它是一个权限问题,运行以下命令:
sudo chown -R mongodb:mongodb /var/lib/mongodb
#2
21
So I had this problem rather suddenly, and I'm not sure why. The problem is that the upstart file wants to run mongo as the user mongodb. From /etc/init/mongodb.conf
:
所以我突然有了这个问题,我不知道为什么。问题是upstart文件想要运行mongo作为用户mongodb。从/etc/init/mongodb.conf:
if [ "x$ENABLE_MONGODB" = "xyes" ]; then exec start-stop-daemon --start --quiet --chuid mongodb --exec /usr/bin/mongod -- --config /etc/mongodb.conf; fi
The chuid part tells it to run as a different user, even though you're running this script as root. For some reason, when I did ls -l
in /var/lib/mongodb
, I noticed that all the files were owned by root, which is why our mongodb user couldn't ge to them. I just did this:
chuid部分告诉它作为一个不同的用户运行,即使您正在运行这个脚本作为根。出于某种原因,当我在/var/lib/mongodb中执行ls -l时,我注意到所有的文件都是root所拥有的,这就是为什么我们的mongodb用户不能使用它们。我只是这样做:
sudo chown mongodb:mongodb /var/lib/mongodb
And all was well. How did the issue happen in the first place? Not sure.
,一切都好。这个问题是怎么发生的?不确定。
#3
1
This file is your first data file /var/lib/mongodb/adrise.ns
. Actually to be specific it's a namespace file that identifies other DB files.
该文件是您的第一个数据文件/var/lib/mongodb/adrise.ns。具体来说,它是一个名称空间文件,用来标识其他的DB文件。
For MongoDB to work, the mongod
process will need access to two folders:
对于MongoDB来说,mongod进程需要访问两个文件夹:
-
Data folder: in your case
/var/lib/mongodb/
- 数据文件夹:在您的示例中/var/lib/mongodb/。
- Log folder: not sure where you've put this
- 日志文件夹:不确定你把它放在哪里了。
Now, if you run this as the root user, it should have access to every every folder. But you should ensure that no one else is locking this folder.
现在,如果作为根用户运行它,它应该可以访问每个文件夹。但是您应该确保没有其他人锁定这个文件夹。
However, you should be able to run this with lower permissions. Typically you only need user-level permissions, just ensure that the user has access to those folder. If possible you'll want to run this at a level lower than root. Many people actually make a mongodb
user and run it in its own context.
但是,您应该能够使用较低的权限运行此操作。通常,您只需要用户级权限,只需要确保用户可以访问这些文件夹。如果可能,您将希望以低于root的级别运行此操作。许多人实际上会创建一个mongodb用户并在自己的上下文中运行它。
#4
0
I had this problem when I remove mongo 3.6 and install mongo 2.4! My solution:
当我移除mongo 3.6并安装mongo 2.4时,我遇到了这个问题。我的解决方案:
- Create new dir for you'r DB (some /var/lib/mongodb)
- 为您创建新的dir(一些/var/lib/mongodb)
- Edit config /etc/mongod.conf (dbpath=/var/lib/mongodb)
- 编辑配置/etc/mongod.配置(dbpath = / var / lib / mongodb)
- Start mongod
- 开始mongod
#5
0
Just try this command.
试试这个命令。
sudo chown -R mongodb:mongodb /var/lib/mongodb
sudo chown -R mongodb:mongodb /var/lib/mongodb。
And
和
sudo service mongod restart
sudo mongod重启服务
may help you.
可能会帮助你。