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.
Update System (Optional)
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:
yum update
Install MongoDB
With Yum
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
From MongoDB Repository
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 x86_64
to i686
.
Once you have saved the file, run the following commands:
yum update
yum install mongodb-org -y
Proceed after the installation has finished.
Setup MongoDB
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!
Want to contribute?
You could earn up to $300 by adding new articles
Suggest an update
Request an article