I downloaded MongoDB from the website: https://www.mongodb.org/dl/linux/x86_64-rhel70
The version I downloaded: linux/mongodb-linux-x86_64-rhel70-3.6.9.tgz
I extracted the downloaded MongoDB package on my CentOS 7 machine and I am able to start Mongod using the binary.
I would like to start MongoDB as a service with a configuration file.
I know the command for the Windows side of things which is:
"C:Program FilesMongoDBServer3.2binmongod.exe" --config "C:Program FilesMongoDBServer3.2mongod.cfg" –install
However, I do not know how to accomplish this on a Linux box?
2
Answers
If MongoDB doesn’t install a service, you can make your own:
1) Create a file in
/etc/systemd/system/
called whatever you like, with.service
as the file extension, like soMongoDB.service
2) Write the following into that file:
3) To start the serivce call
sudo systemctl start <your filename>.service
You could use a Centos repository from MongoDB, which will create the required configuration files and systemd scripts.
Just add the repo to Centos:
And the repo information:
Save the file and then, install:
The configuration file will be in: /etc/mongod.conf
To start the service:
You may check the service status:
And to enable at startup:
To reload after a config file change:
If you prefer to have the one you downloaded, you may use it somewhat like in Windows, the command would be ‘mongod’ without the .exe, and you will need to manually create the config file and also a systemd init script.