skip to Main Content

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


  1. 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 so MongoDB.service

    2) Write the following into that file:

    [Unit]
    Description=MongoDB Service
    
    [Service]
    ExecStart=<Path to binary along with arguments>
    
    [Install]
    WantedBy=multi-user.target
    

    3) To start the serivce call sudo systemctl start <your filename>.service

    Login or Signup to reply.
  2. You could use a Centos repository from MongoDB, which will create the required configuration files and systemd scripts.

    Just add the repo to Centos:

    # sudo vi /etc/yum.repos.d/mongodb-org.repo
    

    And the repo information:

    [mongodb-org-3.6]
    name=MongoDB Repository
    baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/3.6/x86_64/
    gpgcheck=1
    enabled=1
    gpgkey=https://www.mongodb.org/static/pgp/server-3.6.asc
    

    Save the file and then, install:

    # sudo yum install mongodb-org
    

    The configuration file will be in: /etc/mongod.conf

    To start the service:

    # sudo systemctl start mongod
    

    You may check the service status:

    # sudo systemctl status mongod
    

    And to enable at startup:

    # sudo systemctl enable mongod
    

    To reload after a config file change:

    # sudo systemctl reload mongod
    

    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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search