How to Install MongoDB on Your CentOS 7 VPS or Dedicated Server
MongoDB is designed for extensive databases and is mainly used for data analytics, Big data, and gaming among others. In case you are in those industries and would like to scale your database, then MongoDB is what you need.
In this article, we document the step by step instructions on how to install MongoDB on a Linux VPS box running CentOS 7.
MongoDB is one of the leading in the market of the NoSQL database. It is an open source document-oriented database. It boasts of an enormous number of users all around the world. Thanks to its data integrity as well as its integration with popular programming languages, one can see why it has such a large following (visit our best MongoDB Hosting services for a list of the best MongoDB hosts). So let’s see how to install it on our CentOS 7 Virtual private server (VPS).
Adding the MongoDB repository
MongoDB maintains a dedicated repository. So, to add it to our server we are going to use the vi editor to create a repo file for yum. Type the following command.
$ sudo vi /etc/yum.repos.d/mongodb-org.repo
Next, open a new file and add the repository information for the latest release of the file;
[mongodb-org-3.4] name=MongoDB Repository baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/3.4/x86_64/ gpgcheck=1 enabled=1 gpgkey=https://www.mongodb.org/static/pgp/server-3.4.asc
Next, save your changes and close the file. If you wish to verify that the MongoDB repository exists, you can do so by typing the repolist command. This command lists enabled directories;
$ yum repolist
You should see the following:
Now that you have installed the MongoDB repository, you are now ready to install MongoDB.
Install MongoDB from the repository.
We are going to get the mongodb-org from a different repository using the yum command,
$ sudo yum install mongodb-org
Some prompts will appear, the first one will permit the installation of MongoDB packages, and the next one will import a GPG key. Accepting both the prompts is essential. Type Y at each prompt and then press enter.
Your installation is now complete.
To start the mongod process, type;
$ sudo systemctl start mongod
You can also change the state of the MongoDB service with the reload command which requests the process to read the configuration file and save changes without requiring a restart, or the stop command. The stop command stops all running mongod processes.
That is it, now to verify if MongoDB started, you can check the end of the mongod.log file by using the tail command;
$ sudo tail /var/log/mongodb/mongod.log
The output should look like the following:
If it shows the above statement, it means that MongoDB has successfully started and we can now access the database server by typing;
Use the systemctl command to check its status
$ systemctl is-enabled mongod; echo $?
If it returns a zero, it means that the daemon is enabled.
If for some reason it returns a one, use the systemctl utility to enable the daemon/process.
$ sudo systemctl enable mongod
Not to forget its powerful management service that allows users to track databases and the data back-up machines. This not only helps in streamlining processes and procedures but also making sure your data integrity is kept in check. Installing MongoDB on a CentOS VPS is similar to installation on normal CentOS 7 server.
Check out the top 3 Dedicated server hosting services:
- Get answer to all of your queries about best VPS hosting by clicking here.