My MongoDB server is not starting on command mongod
Typing sudo service mongodb status yeilds
mongodb.service - High-performance, schema-free document-oriented database
Loaded: loaded (/etc/systemd/system/mongodb.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Tue 2017-11-28 20:08:25 IST; 2s ago
Process: ExecStart=/usr/bin/mongod --config /etc/mongod.conf (code=exited, status=1/FAILURE)
Main PID: 29675 (code=exited, status=1/FAILURE)
System service:
#/etc/systemd/system/mongodb.service
[Unit]
Description=High-performance, schema-free document-oriented database
After=network.target
[Service]
User=mongodb
Group=mongodb
ExecStart=/usr/bin/mongod --config /etc/mongod.conf
[Install]
WantedBy=multi-user.target
mongod conf:
#/etc/mongod.conf
storage:
dbPath: /var/lib/mongodb
journal:
enabled: true
systemLog:
destination: file
logAppend: true
path: /var/log/mongodb/mongod.log
However if i am running sudo -u mongodb mongod --config /etc/mongod.conf it runs.
Also if I run sudo mongod the server tries to start but the storage path is /data/db/ which I haven't created.
mongod --config /etc/mongod.conf gives the below error
[main] Failed global initialization: FileNotOpen: Failed to open "/var/log/mongodb/mongod.log"
I had run chown -R mongodb:mongodb /var/lib/mongodb
Permissions:
-rw-r--r-- 1 mongodb mongodb 4096 Nov 28 20:19 /var/log/mongodb/mongod.log
drwxr-xr-x 4 mongodb mongodb 20480 Nov 28 21:32 /var/lib/mongodb
Now whenever I need MongoDB server I have to run it with sudo mongod --dbpath /var/lib/mongodb/
It seems like a permission issue for me. But I cannot figure how to fix this out?
Related
I am using ubuntu16.04 on VPS.
It has been migrated to another company's VPS and is in use.
nginix works fine and my node application works fine.
When the mongodb service is run as systemlctl stat
The following error code was shown and it became Active:Failed.
● mongod.service - MongoDB Database Server
Loaded: loaded (/lib/systemd/system/mongod.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Fri 2022-03-18 08:57:04 UTC; 3s ago
Docs: https://docs.mongodb.org/manual
Process: 3558 ExecStart=/usr/bin/mongod --config /etc/mongod.conf (code=exited, status=217/USER)
Main PID: 3558 (code=exited, status=217/USER)
Mar 18 08:57:04 user systemd[1]: Started MongoDB Database Server.
Mar 18 08:57:04 user systemd[1]: mongod.service: Main process exited, code=exited, status=217/USER
Mar 18 08:57:04 user systemd[1]: mongod.service: Unit entered failed state.
Mar 18 08:57:04 user systemd[1]: mongod.service: Failed with result 'exit-code'.
Below is my mongod.conf setting.
# mongod.conf
# for documentation of all options, see:
# http://docs.mongodb.org/manual/reference/configuration-options/
# Where and how to store data.
storage:
dbPath: /var/lib/mongodb
journal:
enabled: true
# engine:
# mmapv1:
# wiredTiger:
# where to write logging data.
systemLog:
destination: file
logAppend: true
path: /var/log/mongodb/mongod.log
# network interfaces
net:
port: 27017
bindIp: 127.0.0.1
# how the process runs
processManagement:
timeZoneInfo: /usr/share/zoneinfo
#security:
#operationProfiling:
#replication:
#sharding:
## Enterprise-Only Options:
#auditLog:
#snmp:
In my system
mongod.conf Path
/etc/mongod.conf
mongodb DB path
/var/lib/mongodb
I'd appreciate it if you could let me know what I need to check.
The problem is probably with the account mongo is trying to launch with in your systemd mongod.service file. Check the user and group defined in the [Service] block are valid.
I tried to install mongoDB on Centos8, but when I run the command
systemctl status mongod.service
I get this error:
● mongod.service - MongoDB Database Server
Loaded: loaded (/usr/lib/systemd/system/mongod.service; enabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Sat 2020-08-01 14:26:53 CEST; 11min ago
Docs: https://docs.mongodb.org/manual
Process: 1875 ExecStart=/usr/bin/mongod $OPTIONS (code=exited, status=14)
Process: 1873 ExecStartPre=/usr/bin/chmod 0755 /var/run/mongodb (code=exited, status=0/SUCCESS)
Process: 1871 ExecStartPre=/usr/bin/chown mongod:mongod /var/run/mongodb (code=exited, status=0/SUCCESS)
Process: 1869 ExecStartPre=/usr/bin/mkdir -p /var/run/mongodb (code=exited, status=0/SUCCESS)
Aug 01 14:26:53 db.localhost systemd[1]: Starting MongoDB Database Server...
Aug 01 14:26:53 db.localhost mongod[1875]: about to fork child process, waiting until server is ready for>
Aug 01 14:26:53 db.localhost mongod[1875]: forked process: 1877
Aug 01 14:26:53 db.localhost mongod[1875]: ERROR: child process failed, exited with 14
Aug 01 14:26:53 db.localhost mongod[1875]: To see additional information in this output, start without th>
Aug 01 14:26:53 db.localhost systemd[1]: mongod.service: Control process exited, code=exited status=14
Aug 01 14:26:53 db.localhost systemd[1]: mongod.service: Failed with result 'exit-code'.
Aug 01 14:26:53 db.localhost systemd[1]: Failed to start MongoDB Database Server.
I tried to check privileges for the folders: /var/lib/mongo and /var/log/mongodb
#/var/lib/
drwxr-xr-x. 4 mongod mongod 4096 Aug 1 14:44 mongo
#/var/log/
drwxr-xr-x. 2 mongod mongod 50 Aug 1 14:14 mongodb
In some other posts, people told to try this command:
sudo chown -R mongodb:mongodb /var/lib/mongodb/
but in don't have the user mongodb and I get the error: invalid user: 'mongodb:mongodb'!
In my /etc/passwd file the only user for mongo is this:
mongod:x:994:992:mongod:/var/lib/mongo:/bin/false
What's the problem?
Why I cannot run mongod.service?
Thanks for your support.
Added more informations:
systemctl cat mongod
[root#db tmp]# systemctl cat mongod
# /usr/lib/systemd/system/mongod.service
[Unit]
Description=MongoDB Database Server
Documentation=https://docs.mongodb.org/manual
After=network.target
[Service]
User=mongod
Group=mongod
Environment="OPTIONS=-f /etc/mongod.conf"
EnvironmentFile=-/etc/sysconfig/mongod
ExecStart=/usr/bin/mongod $OPTIONS
ExecStartPre=/usr/bin/mkdir -p /var/run/mongodb
ExecStartPre=/usr/bin/chown mongod:mongod /var/run/mongodb
ExecStartPre=/usr/bin/chmod 0755 /var/run/mongodb
PermissionsStartOnly=true
PIDFile=/var/run/mongodb/mongod.pid
Type=forking
# file size
LimitFSIZE=infinity
# cpu time
LimitCPU=infinity
# virtual memory size
LimitAS=infinity
# open files
LimitNOFILE=64000
# processes/threads
LimitNPROC=64000
# locked memory
LimitMEMLOCK=infinity
# total threads (user+kernel)
TasksMax=infinity
TasksAccounting=false
# Recommended limits for mongod as specified in
# https://docs.mongodb.com/manual/reference/ulimit/#recommended-ulimit-settings
[Install]
WantedBy=multi-user.target
mongod.conf
[root#db tmp]# cat /etc/mongod.conf
# ..
# mongod.conf
# for documentation of all options, see:
# http://docs.mongodb.org/manual/reference/configuration-options/
# where to write logging data.
systemLog:
destination: file
logAppend: true
path: /var/log/mongodb/mongod.log
# Where and how to store data.
storage:
dbPath: /var/lib/mongo
journal:
enabled: true
# engine:
# wiredTiger:
# how the process runs
processManagement:
fork: true # fork and run in background
pidFilePath: /var/run/mongodb/mongod.pid # location of pidfile
timeZoneInfo: /usr/share/zoneinfo
# network interfaces
net:
port: 27017
bindIp: 127.0.0.1 # Enter 0.0.0.0,:: to bind to all IPv4 and IPv6 addresses or, alternatively, use the net.bindIpAll setting.
#security:
#operationProfiling:
#replication:
#sharding:
## Enterprise-Only Options
#auditLog:
#snmp:
/usr/bin/mongod -f /etc/mongod.conf
[root#db mongodb]# /usr/bin/mongod -f /etc/mongod.conf
about to fork child process, waiting until server is ready for connections.
forked process: 1959
child process started successfully, parent exiting
For some kind of reason, mongod want the folder /data/db and ignore the file mongod.conf
After I created these folders, if I run mongod command (with sudo), programme start "correctly".
But if I reboot the system, the service fails on boot and continue to have problems.
My Problem
Hi there! When I tried to start and see status I've got an error.
skozurak#danny:~$ service mongod start
skozurak#danny:~$ service mongod status
● mongod.service - MongoDB Database Server
Loaded: loaded (/lib/systemd/system/mongod.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Tue 2020-07-14 17:54:33 CEST; 3s ago
Docs: https://docs.mongodb.org/manual
Process: 77503 ExecStart=/usr/bin/mongod --auth --config /etc/mongod.conf (code=exited, status=2)
Main PID: 77503 (code=exited, status=2)
Jul 14 17:54:33 danny systemd[1]: Started MongoDB Database Server.
Jul 14 17:54:33 danny mongod[77503]: Error parsing YAML config file: yaml-cpp: error at line 32, col>
Jul 14 17:54:33 danny mongod[77503]: try '/usr/bin/mongod --help' for more information
Jul 14 17:54:33 danny systemd[1]: mongod.service: Main process exited, code=exited, status=2/INVALID>
Jul 14 17:54:33 danny systemd[1]: mongod.service: Failed with result 'exit-code'.
lines 1-12/12 (END)
What I did
Tried to reinstall
Tried to install different versions
Then I added the service to be able to run on server startup.
skozurak#danny:~$ systemctl enable mongod.service
I think that problem is in the config file. But I do not know how to fix it there.
skozurak#danny:~$ sudo nano /etc/mongod.conf
# mongod.conf
# Where and how to store data.
storage:
dbPath: /var/lib/mongodb
journal:
enabled: true
# engine:
# mmapv1:
# wiredTiger:
# where to write logging data.
systemLog:
destination: file
logAppend: true
path: /var/log/mongodb/mongod.log
# network interfaces
net:
port: 27017
bindIp: 127.0.0.1
# how the process runs
processManagement:
timeZoneInfo: /usr/share/zoneinfo
security:
authorization: enabled
#operationProfiling:
#replication:
#sharding:
## Enterprise-Only Options:
#auditLog:
#snmp:
I just changed one line of config as I saw here
skozurak#danny:~$ sudo nano /lib/systemd/system/mongod.service
[Unit]
Description=MongoDB Database Server
Documentation=https://docs.mongodb.org/manual
After=network.target
[Service]
User=mongodb
Group=mongodb
EnvironmentFile=-/etc/default/mongod
ExecStart=/usr/bin/mongod --auth --config /etc/mongod.conf #i changed this line
PIDFile=/var/run/mongodb/mongod.pid
# file size
LimitFSIZE=infinity
# cpu time
LimitCPU=infinity
# virtual memory size
LimitAS=infinity
# open files
LimitNOFILE=64000
# processes/threads
LimitNPROC=64000
# locked memory
LimitMEMLOCK=infinity
# total threads (user+kernel)
TasksMax=infinity
TasksAccounting=false
# Recommended limits for mongod as specified in
# http://docs.mongodb.org/manual/reference/ulimit/#recommended-settings
[Install]
WantedBy=multi-user.target
Your error lies here:
security:
authorization: enabled
You can't use any other indentation than exactly 2 spaces.
I am attempting to update the dbpath for mongo db. I am following the steps as below:
1) Create new directory : sudo mkdir /mnt/database/mongo
2) Change owner : sudo cp -R /var/lib/mongo/ /mnt/database/
3) Copy DB files: sudo chown mongod:mongod -R /mnt/database/mongo
4) Update mongo configuration file:
storage:
dbPath: /mnt/database/mongo
5) Restart mongod service: sudo systemctl restart mongod
The service restart command gives the following error:
Job for mongod.service failed because the control process exited with error code. See systemctl status mongod.service and journalctl -xe for details.
Logfile contents:
I CONTROL [initandlisten] options: { config: "/etc/mongod.conf", net: { bindIp: "127.0.0.1", port: 27017 }, processManagement: { fork: true, pidFilePath: "/var/run/mongodb/mongod.pid", timeZoneInfo: "/usr/share/zoneinfo" }, storage: { dbPath: "/mnt/database/mongo", journal: { enabled: true } }, systemLog: { destination: "file", logAppend: true, path: "/var/log/mongodb/mongod.log" } }
2020-04-17T04:56:00.666+0000 I STORAGE [initandlisten] exception in initAndListen: Location28596: Unable to determine status of lock file in the data directory /mnt/database/mongo: boost::filesystem::status: Permission denied: "/mnt/database/mongo/mongod.lock", terminating
Am I missing any steps with regards to permission.
System logs: /var/log/messages
systemd: Stopping MongoDB Database Server...
systemd: Starting MongoDB Database Server...
mongod: about to fork child process, waiting until server is ready for connections.
mongod: forked process: 17968
mongod: ERROR: child process failed, exited with error number 100
mongod: To see additional information in this output, start without the "--fork" option.
systemd: mongod.service: control process exited, code=exited status=100
systemd: Failed to start MongoDB Database Server.
systemd: Unit mongod.service entered failed state.
systemd: mongod.service failed.
Directory permissions:
/mnt :
drwxr-xr-x. 6 mongod mongod mnt
/mnt/database:
drwxrwxrwx. 3 mongod mongod database
/mnt/database/mongo:
drwxrwxrwx. 4 mongod mongod mongo
Files under /mnt/database/mongo:
-rwxrwxrwx. 1 mongod mongod 20480 collection-0-1788044936069962496.wt
-rwxrwxrwx. 1 mongod mongod 36864 collection-2-1788044936069962496.wt
-rwxrwxrwx. 1 mongod mongod 4096 collection-4-1788044936069962496.wt
drwxrwxrwx. 2 mongod mongod 90 diagnostic.data
-rwxrwxrwx. 1 mongod mongod 20480 index-1-1788044936069962496.wt
-rwxrwxrwx. 1 mongod mongod 36864 index-3-1788044936069962496.wt
-rwxrwxrwx. 1 mongod mongod 4096 index-5-1788044936069962496.wt
-rwxrwxrwx. 1 mongod mongod 12288 index-6-1788044936069962496.wt
drwxrwxrwx. 2 mongod mongod 110 journal
-rwxrwxrwx. 1 mongod mongod 20480 _mdb_catalog.wt
-rwxrwxrwx. 1 mongod mongod 36864 sizeStorer.wt
-rwxrwxrwx. 1 mongod mongod 114 storage.bson
-rwxrwxrwx. 1 mongod mongod 47 WiredTiger
-rwxrwxrwx. 1 mongod mongod 4096 WiredTigerLAS.wt
-rwxrwxrwx. 1 mongod mongod 21 WiredTiger.lock
-rwxrwxrwx. 1 mongod mongod 1185 WiredTiger.turtle
-rwxrwxrwx. 1 mongod mongod 61440 WiredTiger.wt
The security context of mongodb directoreies:
ls -Z /mnt/database
drwxrwxrwx. mongod mongod unconfined_u:object_r:mnt_t:s0 mongo
Resolved the issue executing chcon -R --reference=/var/lib/mongo /mnt/database/mongo
I try to start service with mongo and get an error:
* mongod.service - MongoDB Database Server
Loaded: loaded (/lib/systemd/system/mongod.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Fri 2019-04-12 12:55:29 MSK; 9s ago
Docs: https://docs.mongodb.org/manual
Process: 15162 ExecStart=/usr/bin/mongod --config /etc/mongod.conf (code=exited, status=1/FAILURE)
Main PID: 15162 (code=exited, status=1/FAILURE)
Apr 12 12:55:29 mx systemd[1]: Started MongoDB Database Server.
Apr 12 12:55:29 mx systemd[1]: mongod.service: Main process exited, code=exited, status=1/FAILURE
Apr 12 12:55:29 mx systemd[1]: mongod.service: Failed with result 'exit-code'.
If I start mongod by manual, all works good.
mongod.service:
[Unit]
Description=High-performance, schema-free document-oriented database
After=network.target
[Service]
User=mongodb
ExecStart=/usr/bin/mongod --quiet --config /etc/mongod.conf
[Install]
WantedBy=multi-user.target
mongod.config:
# mongod.conf
# for documentation of all options, see:
# http://docs.mongodb.org/manual/reference/configuration-options/
# Where and how to store data.
storage:
dbPath: /var/lib/mongodb
journal:
enabled: true
# engine:
# mmapv1:
# wiredTiger:
# where to write logging data.
systemLog:
destination: file
logAppend: true
path: /var/log/mongodb/mongod.log
# network interfaces
net:
port: 27017
bindIp: 127.0.0.1
# how the process runs
processManagement:
timeZoneInfo: /usr/share/zoneinfo
I've set permissions for /var/lib/mongodb and /var/log/mongodb/mongod.log
chown mongodb:mongodb /var/lib/mongodb -R
chown mongodb:mongodb /var/log/mongodb/mongod.log -R
What's wrong? What should I do? Any ideas?
I've solved my porblem. The solution is very simple, but I had a lot of headace.
Free disk space. I have no anought free disk space in my server. Thats it!
I hope this will be helpfull for anybody...