Watch keynotes and sessions from MongoDB.live, our virtual developer conference.

Creating mongodb service in RHEL

Hi,

How to create a mongo DB service is RHEL?

is it possible to create a mongo DB srevice in RHEL using mongod command?

Your help is really appreciated.

Br
Raghavender

Hi @Kodumuri_Raghavender, if you installed MongoDB via the yum package manager then this is already set up as a service. If you manually installed MongoDB then you would have to build your own service file to run it as a service.

1 Like

Hi @Doug_Duncan, Thank you very much for your help. yum package manager install the mongodb software in root FS. we dont want to use root FS. we are installing in custome FS using TGZ file. i want to configure the service manually using mongod. can you please share the command if you have any?

Thank you so much for your help.

Hi @Kodumuri_Raghavender the below is the default mongod.service file installed on RHEL 7 using yum:

[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 for mongod as specified in
# http://docs.mongodb.org/manual/reference/ulimit/#recommended-settings

[Install]
WantedBy=multi-user.target 

You would need to tweak the above for your system.

You can learn more about systemd files in the systemd man pages.

With this file in place you can start the service just as you would any other RHEL service with sudo systemctl start mongod.

Hi @Kodumuri_Raghavender,

If you want to manually create a service definition and config file, you can find the versions used in the RPM packages in the MongoDB source on GitHub: https://github.com/mongodb/mongo/tree/master/rpm.

If you just need a different install path, the MongoDB RPMs should also be relocatable using the --prefix option for yum/dnf.

For example: sudo rpm --prefix /home/mongodb/ mongodb.rpm.

Regards,
Stennie

2 Likes