mongodb 3.4.3 Permission denied wiredtiger_kv_engine.cpp 267 error with ubuntu 16

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

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

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.

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.

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.

Assertion: 28595:13: Permission denied 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).

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.

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

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


Have same problem.

What been in /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:

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/

There are three set-ups that triggers this kind of problem :

  1. 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 dbpath in mongo.

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.

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.

  1. MongoDB does not have the permission to read one or more files or directories corresponding to its dbpath.

chown mongodb:mongodb dbpath -R.

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

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 :

sudo apt-get purge mongodb-org*

sudo rm -r dbpath

sudo apt-get install mongodb-org

Edit : Or copy dbpath from one of your replicas.

Tags:

Ubuntu

Mongodb