Introduction
MongoDB is a scalable, high-performance, open source NoSQL database. The database is document-oriented so it manages collections of JSON-like documents. Many applications can thus model data in a more natural way, as data can be nested in complex hierarchies and still be queryable and indexable.
We are assuming that you have root permission, otherwise, you may start commands with “sudo”.
Install MongoDB
For installing the latest stable version of MongoDB you should add MongoDB repository first.
Adding MongoDB Repository
Move to the following directory:
cd /etc/yum.repos.d/
Create the following file with your favorite text editor:
nano mongodb-org-3.4.repo
For the latest stable version of MongoDB paste the following line in the file then save and exit:
[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
Installing MongoDB
Update your repositories list executing the following command:
yum repolist
Now you can install the latest stable version of MongoDB using “Yum”:
yum install mongodb-org -y
Configuring SELINUX
If you are using SELinux, you must configure SELinux to allow MongoDB to start on Red Hat Linux-based systems
If SELinux is in enforcing mode, enable access to the relevant ports that the MongoDB deployment will use (e.g. 27017).
semanage port -a -t mongod_port_t -p tcp 27017
Manage your MongoDB Service
You can manage your MongoDB service with “systemctl”:
For making MongoDB run at startup:
systemctl enable mongod
orchkconfig mongod on
For Start/Stop MongoDB service:
systemctl start mongod
systemctl stop mongod
orservice mongod start
service mongod stop
See your MongoDB status:
systemctl status mongod
orservice mongod status
Check out MongoDB official website for more information and news!