Installing Percona Mongo from a tarball

Hi,

I am trying to install Percona MongoDB from the tarball on a RHEL server.

I noticed the documentation doesn’t cover:

  • how to create the mongod user/group

  • how to set up the systemd service file

Could you please guide me on the correct way to handle this?
Also, let me know if there is any documentation that I might have missed which covers these steps.

Additionally, I am not looking to set up a sharded cluster — this is intended to be a 3-node replica set deployment.

Thanks.

Hi @Wasef ,

Welcome to the Percona Forums!

We have one for mongos. But yes, I will check internally for mongod systemd configuration doc. However, it is simple and you can create the systemd file /etc/systemd/system/mongod.service like mentioned here - percona-server-mongodb/rpm/mongod.service at master · percona/percona-server-mongodb · GitHub . You can also add parameters to handle PID file related to that systemd service file. Refer here for more about systemd - systemd man page

You can test with the steps below and do customisation as per your requirements:

a. Create /etc/systemd/system/mongod.service with details like below:

[Unit]
Description=MongoDB Database Server instance
After=time-sync.target network.target

[Service]
User=mongod
Group=mongod
PermissionsStartOnly=true

# Recommended limits for mongod as specified in
# https://docs.mongodb.com/manual/reference/ulimit/#recommended-ulimit-settings
LimitFSIZE=infinity
LimitCPU=infinity
LimitAS=infinity
LimitNOFILE=64000
LimitNPROC=64000
LimitMEMLOCK=infinity
TasksMax=infinity
TasksAccounting=false

Environment="OPTIONS=-f /etc/mongod.conf"
Environment="MONGODB_CONFIG_OVERRIDE_NOFORK=1"
Environment="GLIBC_TUNABLES=glibc.pthread.rseq=0"
EnvironmentFile=-/etc/sysconfig/mongod
ExecStart=/usr/bin/mongod $OPTIONS
RuntimeDirectory=mongodb

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
PIDFile=/var/run/mongodb/mongod.pid
ExecReload=/bin/kill -s HUP $MAINPID
Restart=always
RestartSec=5
# Needed to prevent "forked" systemd processes, requires PrivateTmp=true
# PrivateTmp=true

[Install]
WantedBy=multi-user.target

b. Keep /etc/mongod.conf file, data directory and log Path with permission of user mongod. To create mongod user (here assuming that /var/lib/mongo is the home directory):

$ groupadd -r mongod
$ useradd -M -r -g mongod -d /var/lib/mongo -s /bin/false -c mongod mongod

c. Enable the MongoD process:

$ sudo systemctl enable mongod

d. Start the first instance:

$ sudo systemctl start mongod

Hope this helps you!

Regards,

Vinodh Guruji