简体   繁体   English

MongoDB 服务未启动。 errno:13 权限被拒绝

[英]MongoDB service doesn't start. errno:13 Permission denied

I have installed MongoDB on a Ubuntu server like is indicated in the docs http://docs.mongodb.org/manual/tutorial/install-mongodb-on-ubuntu/ .我已经在 Ubuntu 服务器上安装了 MongoDB,如文档http://docs.mongodb.org/manual/tutorial/install-mongodb-on-ubuntu/ 中所示 Then, I have modified the configuration file /etc/mongod.conf for, later, run a mongod service.然后,我修改了配置文件/etc/mongod.conf以便稍后运行 mongod 服务。

MongoDB runs correctly if I execute:如果我执行,MongoDB 会正确运行:

sudo mongod -f /etc/mongod.conf

But MongoDB stops if I execute:但是如果我执行,MongoDB 就会停止:

sudo service mongod start

In the config file /etc/mongod.conf I changed only this:在配置文件/etc/mongod.conf我只更改了以下内容:

dbpath=/data/db
logpath=/root/logs/mongod.log
port=20000

With this configuration, the log file is not created too.使用此配置,也不会创建日志文件。

If I don't modify the previous values indicated, the service starts correctly.如果我不修改先前指示的值,则服务会正确启动。 The default values are:默认值为:

dbpath=/var/lib/mongodb
logpath=/var/log/mongodb/mongod.log
port = 27017

Because the log file is not created with the custom configuration, I have only changed the dbpath for see the error:因为日志文件不是使用自定义配置创建的,所以我只更改了dbpath以查看错误:

[initandlisten] exception in initAndListen: 10309 Unable to create/open lock file: /data/db/mongod.lock errno:13 Permission denied Is a mongod instance already running?

I tried to run the following commands but without success:我尝试运行以下命令但没有成功:

sudo chown -R `id -u` /data/db

sudo rm /var/lib/mongodb/mongod.lock
mongod --repair

Stack:堆:

  • Ubuntu 14.10 Ubuntu 14.10
  • MongoDB 2.6.5 MongoDB 2.6.5

We must make all the directories/files owned by mongod user .我们必须让mongod 用户拥有所有目录/文件。 For this:为了这:

sudo chown -R mongodb:mongodb /data/db

I found a special case where the use of symlinks appears to fail:我发现了一个特殊情况,符号链接的使用似乎失败了:

Using a standard enterprise install of mongodb except I changed the /var/lib/mongodb to a symlink as I wanted to use an XFS filesystem for my database folder and a third filesystem for the log folder.使用 mongodb 的标准企业安装,除了我将 /var/lib/mongodb 更改为符号链接,因为我想为我的数据库文件夹使用 XFS 文件系统,并为日志文件夹使用第三个文件系统。

$sudo systemctl start mongod (fails with a message no permission to write to mongodb.log).. but it succceded if I started with the same configuration file: $sudo systemctl start mongod(失败并显示无权限写入 mongodb.log 的消息)。但如果我使用相同的配置文件开始,它会成功

.. as the owner of the external drives (ziggy) I was able to start $mongod -- config /etc/mongodb.conf --fork .. 作为外部驱动器(ziggy)的所有者,我能够启动 $mongod -- config /etc/mongodb.conf --fork

I eventually discovered that .. the symlinks pointed to a different filesystem and the mongodb (user) did not have permission to browse the folder that the symlink referred.我最终发现 .. 符号链接指向不同的文件系统并且 mongodb(用户)无权浏览符号链接所引用的文件夹。 Both the symlinks and the folders the symlinks referred had expansive rights to the mongod user so it made no sense?符号链接和符号链接所引用的文件夹都对 mongod 用户具有广泛的权利,所以没有意义?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM