mongodb 3.4.3 ubuntu 16 权限被拒绝wiredtiger_kv_engine.cpp 267 错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/43137250/
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
mongodb 3.4.3 Permission denied wiredtiger_kv_engine.cpp 267 error with ubuntu 16
提问by Nickpick
I'm having problems lauching mongod as a service: How is it possible that it works when I do sudo mongod -f /etc/mongod.conf but when launching it with sudo service mongod start I get an error in the log
我在将 mongod 作为服务启动时遇到问题:当我执行 sudo mongod -f /etc/mongod.conf 时它怎么可能工作,但是当使用 sudo service mongod start 启动它时,我在日志中收到错误
Assertion: 28595:13: Permission denied src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp 267
Assertion: 28595:13: Permission denied src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp 267
I'm running mongodb on ubuntu 16
我在 ubuntu 16 上运行 mongodb
I followed exactly the instructions in the mongodb documentation for installation of that version, so is this a bug? Any suggestions how to solve this are appreciated.
我完全按照 mongodb 文档中的说明安装该版本,这是一个错误吗?任何解决此问题的建议表示赞赏。
Additional information:
附加信息:
The mongodb service startup script looks like this and runs it as user mongodb, could this be connected to the error? lib/systemd/system/mongodb.service:
mongodb服务启动脚本是这样的,以mongodb用户运行,请问这与报错有关吗?lib/systemd/system/mongodb.service:
[Unit]
Description=MongoDB Database Service
Wants=network.target
After=network.target
[Service]
ExecStart=/usr/bin/mongod --config /etc/mongod.conf
ExecReload=/bin/kill -HUP $MAINPID
Restart=always
User=mongodb
Group=mongodb
StandardOutput=syslog
StandardError=syslog
[Install]
WantedBy=multi-user.target
回答by Stennie
I'm having problems lauching mongod as a service: How is it possible that it works when I do sudo mongod -f /etc/mongod.conf but when launching it with sudo service mongod start I get an error in the log
我在将 mongod 作为服务启动时遇到问题:当我执行 sudo mongod -f /etc/mongod.conf 时它怎么可能工作,但是当使用 sudo service mongod start 启动它时,我在日志中收到错误
The sudo
command starts mongod
with root
permissions (aka superuser access). If you run mongod
as a service the user and group are configured in the service definition (mongodb
for both in your example).
该sudo
命令mongod
以root
权限(又名超级用户访问)开头。如果您mongod
作为服务运行,则在服务定义中配置用户和组(mongodb
在您的示例中两者)。
There is no need to run the mongod
process as the root
user, and this is strongly discouraged as per the common security practice of Principle of least privilege.
不需要以用户身份运行mongod
进程,根据最小权限原则root
的常见安全实践,强烈建议不要这样做。
If you want to test a configuration from the command-line, you could use sudo
to run with a specified user instead of the default (root) user.
如果您想从命令行测试配置,您可以使用sudo
指定用户而不是默认(root)用户运行。
For example:
例如:
sudo -u mongodb mongod -f /etc/mongod.conf
In general, it's best to use a service configuration rather than running mongod
manually. With manual invocation you will also have to remember to include parameters like the config file path (as there is no default config path). Without a configuration file, mongod
also uses default options such as a dbPath
of /data/db
.
一般来说,最好使用服务配置而不是mongod
手动运行。通过手动调用,您还必须记住包含配置文件路径等参数(因为没有默认配置路径)。在没有配置文件的mongod
情况下,也使用默认选项,例如 a dbPath
of /data/db
。
Assertion: 28595:13: Permission denied src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp 267
断言:28595:13:权限被拒绝 src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp 267
The likely cause of your permission errors is having previously started mongod
as the root
user. Some directories and files may now be owned by the root user, so the mongodb
user cannot access those. Your specific error relates to accessing files in the data directory (i.e. the configured storage.dbPath
in mongod.conf
).
您的权限错误的可能原因是之前mongod
以root
用户身份启动。某些目录和文件现在可能归 root 用户所有,因此 mongodb
用户无法访问它们。您的具体错误与访问数据目录中的文件(即 中配置storage.dbPath
的mongod.conf
)有关。
Assuming you haven't changed the default paths in your mongod.conf
file, you should be able to recursively adjust permissions to match what the mongod.service
definition expects.
假设您没有更改mongod.conf
文件中的默认路径,您应该能够递归调整权限以匹配mongod.service
定义期望的内容。
First, ensure you have stopped your mongod
instance if it is currently running.
首先,mongod
如果您的实例当前正在运行,请确保您已将其停止。
Then, recursively adjust permissions to the expected user and group:
然后,递归地调整预期用户和组的权限:
# storage.dbPath
sudo chown -R mongodb:mongodb /var/lib/mongodb
# systemLog.path
sudo chown -R mongodb:mongodb /var/log/mongodb
Now you should be able to start mongod
as a service. If the service fails to start, there should be further detail in the mongod
log file (assuming the log file is writable by the mongodb
service user).
现在您应该可以mongod
作为服务启动了。如果服务无法启动,mongod
日志文件中应该有更多详细信息(假设日志文件可由mongodb
服务用户写入)。
回答by FreeStyler
Have same problem.
有同样的问题。
What been in /var/log/mongodb/mongod.log:
/var/log/mongodb/mongod.log 中的内容:
2017-05-13T13:46:41.152+0700 E STORAGE [initandlisten] WiredTiger error (13) [1494658001:152518][15821:0x7fb843803cc0], connection: /var/lib/mongodb/journal/WiredTigerPreplog.0000000002: file-remove: unlink: Permission denied
2017-05-13T13:46:41.159+0700 I - [initandlisten] Assertion: 28595:13: Permission denied src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp 267
So wee see that something can't remove file "WiredTigerPreplog.0000000002" in /var/lib/mongodb/journal/ So id just gave permissions, i just did:
所以我们看到有些东西无法删除 /var/lib/mongodb/journal/ 中的文件“WiredTigerPreplog.0000000002”所以id只是给了权限,我只是做了:
sudo chmod 764 /var/lib/mongodb/journal/
If not help, try:
如果没有帮助,请尝试:
sudo chown -R mongodb:mongodb /var/lib/mongodb/ && sudo chmod 764 /var/lib/mongodb/journal/
回答by Pobe
There are three set-ups that triggers this kind of problem :
有三种设置会触发此类问题:
- MongoDB installation is configured to create database files at a given path and this path does not exist on your current system. This path is called dbpathin mongo.
- MongoDB 安装配置为在给定路径创建数据库文件,并且当前系统上不存在此路径。此路径在 mongo 中称为 dbpath。
In your case, check if /data/db
exist. If it doesn't or if it is empty, mongod is trying the wrong dbpath. You need to find it, it's usually under /var/lib/mongodb
.
在你的情况下,检查是否/data/db
存在。如果没有或者它为空,则 mongod 正在尝试错误的 dbpath。你需要找到它,它通常在/var/lib/mongodb
.
Once you found it there's two thing you can do. First, copy all the file from there to /data/db
. Second, change your dbpath under the mongod.conf file, which is located (in linux) at /etc/mongod.conf
. Make sure to start mongod with the --config
specifying the configuration file.
一旦你找到它,你可以做两件事。首先,将所有文件从那里复制到/data/db
. 其次,更改 mongod.conf 文件下的 dbpath,该文件位于(在 linux 中)在/etc/mongod.conf
. 确保在--config
指定配置文件的情况下启动 mongod 。
- MongoDB does not have the permission to read one or more files or directories corresponding to its dbpath.
- MongoDB 无权读取与其 dbpath 对应的一个或多个文件或目录。
chown mongodb:mongodb dbpath -R
.
chown mongodb:mongodb dbpath -R
.
- MongoDB is missing WiredTiger.wt . This can happen if you remove files under the dbpath or if there's a device failure. We do it for testing a recovery strategy for example.
- MongoDB 缺少 WiredTiger.wt 。如果您删除 dbpath 下的文件或设备出现故障,就会发生这种情况。例如,我们这样做是为了测试恢复策略。
If you're sure dbpath is correct and that there's no instance of WiredTiger.wt there. Your database is broken. There are no ways to ensure integrity if you lose this file. Reinstall mongodb by :
如果您确定 dbpath 是正确的,并且那里没有 WiredTiger.wt 的实例。你的数据库坏了。如果丢失此文件,则无法确保完整性。通过以下方式重新安装mongodb:
sudo apt-get purge mongodb-org*
sudo apt-get purge mongodb-org*
sudo rm -r dbpath
sudo rm -r dbpath
sudo apt-get install mongodb-org
sudo apt-get install mongodb-org
Edit : Or copy dbpath from one of your replicas.
编辑:或从您的副本之一复制 dbpath。
回答by mwans
I have a similar issue but with custom log path and data dir. updating the owner and group access to them did not fix the issue for running as a service updating the group and owner to mongodb:mongodb works on running mongod by itself as stated earlier
我有一个类似的问题,但有自定义日志路径和数据目录。更新所有者和组对它们的访问并没有解决作为服务运行的问题 将组和所有者更新为 mongodb:mongodb 如前所述自行运行 mongod
sudo -u mongodb mongod -f /etc/mongod.conf
or
或者
sudo mongod -f /etc/mongod.conf
回答by jakodev
I wish append a comment to the previous answer, but unfortunately I cannot yet.
我希望在上一个答案中附加评论,但不幸的是我还不能。
I completely agree with the explanation of Stennie. It is exactly what was happened to me.
I've always run mongod as a service but today, because some changes that I've made, I've tried to run the process using sudo mongod --auth --dbpath /data/mongodb/
.. to test authorizations and db changing location.
After that the mongod service didn't run anymore, due to this permissions problem.
我完全同意 Stennie 的解释。这正是发生在我身上的事情。我一直将 mongod 作为服务运行,但今天,由于我进行了一些更改,我尝试使用sudo mongod --auth --dbpath /data/mongodb/
..运行该过程以测试授权和数据库更改位置。之后,由于此权限问题,mongod 服务不再运行。
I've to say that the command sudo chown -R mongodb:mongodb /data/mongodb/
didn't immediately fix the problem as expected. I've had to reboot several times, remove the mongod.lock
file under /data/mongodb/
, reissue the sudo chown
command again.. and finally everything gone well.
我不得不说该命令sudo chown -R mongodb:mongodb /data/mongodb/
并没有像预期的那样立即解决问题。我不得不重新启动几次,删除下的mongod.lock
文件/data/mongodb/
,sudo chown
再次重新发出命令......最后一切顺利。