Try Vultr Today with $50 Free On Us!Get Started Now
MongoDB is one of the leading NoSQL databases that is commonly used in modern web applications. This tutorial will walk you through setting up MongoDB on CentOS 7.
You will want to make sure that your server is up-to-date. If you are setting up your VPS for the first time, it should already be up-to-date. However, if you are running a Custom ISO, or installing on an existing VPS, then you can run the following command to do a system update:
CentOS is shipped with MongoDB 2.4.9 (this may change in the future). To install it over yum, run the following command:
yum install mongodb
If you wish to use the latest version of MongoDB, then you will need to setup the official repository on your server. To do so, create a file in
/etc/yum.repos.d/mongodb.repo and populate it with the following data:
[mongodb] name=MongoDB Repository baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/x86_64/ gpgcheck=0 enabled=1
Note: This is for the 64-bit version of CentOS 7. If you have installed the 32-bit version of CentOS 7 using a Custom ISO, you need to change
Once you have saved the file, run the following commands:
yum update yum install mongodb-org -y
Proceed after the installation has finished.
Start MongoDB by running
systemctl start mongod. After the service has started, type
mongo into your terminal. If the installation was successful, you will see output similar to the following text.
MongoDB shell version: 2.x.x connecting to: test >
Note: Any start-up warnings related to
Readahead can be safely ignored. To prevent these warnings, verify that the sectors are "as stated" in the warning by running
blockdev –getra /dev/vda1. If the output is greater than 512, run the following commands:
blockdev --setra 512 /dev/vda1 systemctl restart mongod
The warning will now be resolved.
At this point, you are ready to use MongoDB!