Popular blog tags

Mongodb error:MongoDB loads but breaks, returning code=exited, status=14

Published

OS version:Ubuntu 18.04 *64

mongodb version:Mongodb server 4.2

 

Earlier i was storing all the mongodb data files in /var/lib/mongodb directory..and the dbpath entry in /etc/mongodb.conf was /var/lib/mongodb..

Now i want to change the data directory to /vol/db..so I created the directory /vol/db and changed the permissions using sudo chown -R id -u /vol/db and changed the db path entry to /vol/db in /etc/mongodb.conf

now when i start the mongodb using sudo service mongodb start..

So im trying to setup Mongodb on Ubuntu 18.04 but im running into trouble.

when running :

sudo systemctl status mongodb

I get the following:

sudo service mongod start
root@iZuf6hn15mpmrtypv9ltogZ:~# sudo systemctl status mongod
● mongod.service - MongoDB Database Server
   Loaded: loaded (/lib/systemd/system/mongod.service; enabled; vendor preset: e
   Active: failed (Result: exit-code) since Fri 2020-11-13 00:04:58 CST; 4s ago
     Docs: https://docs.mongodb.org/manual
  Process: 13548 ExecStart=/usr/bin/mongod --config /etc/mongod.conf (code=exite
 Main PID: 13548 (code=exited, status=14)

 

Step 1:run

/usr/bin/mongod --config /etc/mongod.conf

run ok

这个明显是权限的问题,你直接执行 mongod --config /etc/mongod.conf 没问题,不代表 sudo service mongod start 也没问题,两种执行方式权限是不一样的。

mongodb/这个目录的所有者必须是 mongodb,可以使用这个命令修复:

sudo chown -R mongodb:mongodb *
drwxr-xr-x 4 mongodb mongodb 4.0K Mar 20 10:55 mongodb

Step 2:

sudo service mongod start

你要用 sudo service mongod start 的方式启动,然后看那个日志文件。

Step 3: check what is the error by reading mongo log

you can immediately find the problem(including permission ones)

 

阅读/etc/mongod.conf 找到日志文件,就可以找到错误原因。

 

 

tail -50 /var/log/mongodb/mongodb.log

 

 

read mongodb log

i am getting this error in /var/log/mongodb/mongodb.log

2020-11-13T00:04:57.809+0800 I  STORAGE  [initandlisten] wiredtiger_open config: create,cache_size=1024M,cache_overflow=(file_max=0M),session_max=33000,eviction=(threads_min=4,threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000),statistics_log=(wait=0),verbose=[recovery_progress,checkpoint_progress],
2020-11-13T00:04:58.449+0800 E  STORAGE  [initandlisten] WiredTiger error (13) [1605197098:449448][13548:0x7f680fd56b00], connection: __posix_open_file, 712: /var/lib/mongodb/journal/WiredTigerLog.0000000103: handle-open: open: Permission denied Raw: [1605197098:449448][13548:0x7f680fd56b00], connection: __posix_open_file, 712: /var/lib/mongodb/journal/WiredTigerLog.0000000103: handle-open: open: Permission denied
2020-11-13T00:04:58.465+0800 E  STORAGE  [initandlisten] WiredTiger error (13) [1605197098:465052][13548:0x7f680fd56b00], connection: __posix_open_file, 712: /var/lib/mongodb/journal/WiredTigerLog.0000000103: handle-open: open: Permission denied Raw: [1605197098:465052][13548:0x7f680fd56b00], connection: __posix_open_file, 712: /var/lib/mongodb/journal/WiredTigerLog.0000000103: handle-open: open: Permission denied
2020-11-13T00:04:58.480+0800 E  STORAGE  [initandlisten] WiredTiger error (13) [1605197098:480058][13548:0x7f680fd56b00], connection: __posix_open_file, 712: /var/lib/mongodb/journal/WiredTigerLog.0000000103: handle-open: open: Permission denied Raw: [1605197098:480058][13548:0x7f680fd56b00], connection: __posix_open_file, 712: /var/lib/mongodb/journal/WiredTigerLog.0000000103: handle-open: open: Permission denied
2020-11-13T00:04:58.484+0800 W  STORAGE  [initandlisten] Failed to start up WiredTiger under any compatibility version.
2020-11-13T00:04:58.484+0800 F  STORAGE  [initandlisten] Reason: 13: Permission denied

Step 4:And now, as root, you can change the owner to mongodb user.

You need to make sure that /var/db/ is owned by mongodb.

sudo chown -R mongodb:mongodb /var/lib/mongodb/journal/WiredTigerLog.0000000103

 

Step 4:Restart and check the status of the service:

sudo service mongod restart
# sudo systemctl status mongod
● mongod.service - MongoDB Database Server
   Loaded: loaded (/lib/systemd/system/mongod.service; enabled; vendor preset: e
   Active: active (running) since Fri 2020-11-13 00:07:44 CST; 2s ago
     Docs: https://docs.mongodb.org/manual
 Main PID: 14122 (mongod)
    Tasks: 17 (limit: 4681)