2

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
Berzohr
  • 306
  • 3
  • 16
  • 1
    Check if `/tmp/mongodb-27017.sock` is owned by `root`. Also post please `systemctl cat mongod` – Valijon Aug 01 '20 at 11:02
  • Hi @Valijon, thanks for your quickly answer. Yes mongodb-27017.sock is owned by root. I added information about systemctl at the end of my post. – Berzohr Aug 01 '20 at 12:22
  • 1
    `mongod.service` configuration looks fine. Just remove `/tmp/mongodb-27017.sock` and it should fix it (run again `systemctl start mongod`). Probably, when you ran it the 1st time, mongodb binary files were `root` owner and now these are `mongod` owner – Valijon Aug 01 '20 at 12:28
  • 1
    I removed ```mongodb-27017.sock``` and reboot the machine. Now is owned by mongod user. But service is failed again with same errors. – Berzohr Aug 01 '20 at 12:35
  • I see. post then `/etc/mongod.conf` please – Valijon Aug 01 '20 at 12:36
  • Done. Added at the end of this post :) – Berzohr Aug 01 '20 at 12:40
  • Make sure `/var/run/mongodb/mongod.pid` or `/var/run/mongodb/` is not `root` owner – Valijon Aug 01 '20 at 12:49
  • This folder is owned by mongod: ```drwxr-xr-x. 2 mongod mongod 40 Aug 1 16:51 mongodb```. Unfortunatelly this folder is empty. I don't have ***mongod.pid*** – Berzohr Aug 01 '20 at 12:57
  • Try to run manually (let's see if it's mongod issue or systemctl issue) `/usr/bin/mongod -f /etc/mongod.conf` – Valijon Aug 01 '20 at 13:01
  • ```about to fork child process, waiting until server is ready for connections. forked process: 1959 child process started successfully, parent exiting``` – Berzohr Aug 01 '20 at 13:05
  • Ok, if we run it manually, it works. Now, check again directories mentioned previously, since you are looged as `root`. Try to login as user and run `systemctl start mongod` – Valijon Aug 01 '20 at 13:10
  • /etc/run/mongod is still owned by ***mongod*** user. mongodb-27017.sock is now owned by ***root***, /var/lib/mongo (***mongod***) and /var/log/mongodb(***mongod***) I logged in with local user (db) and I ran the command but it failed. ```Job for mongod.service failed because the control process exited with error code.``` – Berzohr Aug 01 '20 at 13:19
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/219043/discussion-between-valijon-and-berzohr). – Valijon Aug 01 '20 at 13:21
  • rhel/centos 8 is not an officially supported platform. What documentation/instructions are you following? – D. SM Aug 01 '20 at 13:45
  • Hi @D.SM, I followed this from official website: https://docs.mongodb.com/manual/tutorial/install-mongodb-on-red-hat/ – Berzohr Aug 01 '20 at 13:52
  • My bad, 4.4 is supported on centos 8. – D. SM Aug 01 '20 at 13:53
  • @Valijon answer comment helped me! – Maximus Sep 28 '20 at 23:50

2 Answers2

1

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.

Berzohr
  • 306
  • 3
  • 16
0

Problem is that /etc/mongod.conf file now asks for the pid to be written to /var/run/mongodb/mongod.pid, however this directory does not exist (on my system anyway).

So do: sudo mkdir /var/run/mongodb sudo chown root:mongod /var/run/mongodb sudo chmod g+w /var/run/mongodb

This fixed my problem, but if you ran mongod as root you have to first clean up the files created by root. To see what is happening do: tail -f /var/log/mongod/mongod.log