本文介绍了mongodb 3.4.3权限被拒绝,ubuntu 16的wiredtiger_kv_engine.cpp 267错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在启动mongod服务时遇到问题:当我执行sudo mongod -f/etc/mongod.conf时,它如何工作,但是当使用sudo service mongod start启动它时,我在日志中出现错误

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

Assertion: 28595:13: Permission denied src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp 267

我正在Ubuntu 16上运行mongodb

I'm running mongodb on 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服务启动脚本如下所示,并以mongodb用户身份运行,这是否可能与错误相关?lib/systemd/system/mongodb.service:

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:

[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

推荐答案

sudo命令以root权限启动mongod(又名超级用户访问 ).如果将mongod作为服务运行,则在服务定义中配置用户和组(示例中为mongodb).

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).

不需要以root用户身份运行mongod进程,并且根据最低特权原则.

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.

如果要从命令行测试配置,则可以使用sudo与指定用户而不是默认(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 -u mongodb mongod -f /etc/mongod.conf 

通常,最好使用服务配置,而不是手动运行mongod.使用手动调用时,您还必须记住要包括诸如配置文件路径之类的参数(因为没有默认的配置路径).在没有配置文件的情况下,mongod还使用默认选项,例如/data/dbdbPath.

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.

您的权限错误的可能原因是先前以root用户身份启动mongod.现在,某些目录和文件可能由root用户拥有,因此mongodb用户无法访问它们.您的特定错误与访问数据目录(即在mongod.conf中配置的storage.dbPath)中的文件有关.

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.conf文件中的默认路径,则应该能够递归地调整权限以匹配mongod.service定义的期望.

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实例(如果它正在运行).

First, ensure you have stopped your mongod instance if it is currently running.

然后,递归地调整对预期用户和组的权限:

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

现在,您应该能够将mongod作为服务启动.如果服务无法启动,则mongod日志文件中应该有更多详细信息(假定日志文件可由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).

这篇关于mongodb 3.4.3权限被拒绝,ubuntu 16的wiredtiger_kv_engine.cpp 267错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-22 06:04