How to Install MongoDB on CentOS 7
MongoDB is a NoSQL database intended for storing large amounts of data in document-oriented storage with dynamic schemas. NoSQL refers to a database with a data model other than the tabular format used in relational databases such as MySQL, PostgreSQL, and Microsoft SQL. MongoDB features include: full index support, replication, high availability, and auto-sharding.
- A Liquid Web Core Managed CentOS 7 node.
- We are logged in as the root user.
Step #1: Add the MongoDB Repository
First, we will use the vim text editor to create a new repo file for MongoDB. For a refresher on editing files with vim see: New User Tutorial: Overview of the Vim Text Editor
root@host:~# vim /etc/yum.repos.d/mongodb.repo
Next, add the following information to the file you've created, using i to insert:
[mongodb-org-4.4] name=MongoDB Repository baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/4.4/x86_64/ gpgcheck=1 enabled=1 gpgkey=https://www.mongodb.org/static/pgp/server-4.4.asc
Then save and exit vim using the command :wq.
Step #2: Install MongoDB
As a matter of best practice we will update our packages.
root@host:~# yum -y update
At this point, installing MongoDB is as simple as running this command.
root@host:~# yum install -y mongodb-org
Step #3: Configure MongoDB
Many Linux OSes confine the amount of system resources which a process can use. These limits sometimes can negatively effect the operation of MongoDB, and should be adjusted accordingly. The ulimit setting for CentOS 7 can be modified using the following command.
root@host:~# ulimit -n <value>
Additionally, CentOS 7 enforces a distinct max process limitation using, nproc, which overrides the ulimit settings. This nproc value is defined in this configuration file
To configure a nproc value, use vim to create a file called 99-mongodb-nproc.conf.
root@host:~# touch /etc/security/limits.d/99-mongodb-nproc.conf
Now, add the new soft nproc and hard nprocvalues to increase the process limit.
-f (file size): unlimited -t (cpu time): unlimited -v (virtual memory): unlimited  -l (locked-in-memory size): unlimited -n (open files): 64000 -m (memory size): unlimited   -u (processes/threads): 64000
Step #4: Start MongoDB
To run and manage the mongod process, we will use our OSes default init system. Newer versions of Linux typically use systemd (systemctl), and older versions use System V init (service). To determine which init system the platform uses, run the following command.
root@host:~# ps --no-headers -o comm 1
- Start Mongodb Using Systemd (Systemctl)
- Start Mongodb Using System V Init (service)
1. Start the mongod process.
root@host:~# systemctl start mongod
If you receive an error like:
Failed to start mongod.service: Unit mongod.service not found.
Run the following command.
root@host:~# systemctl daemon-reload
Then, run the start command above again.
2. Verify MongoDB has started.
To verify the mongod process has started successfully, issue the following command.
root@host:~# systemctl status mongod
To ensure MongoDB starts after a system reboot, issuing the following command.
root@host:~# systemctl enable mongod
Step #5: Check MongoDB Status & Info
Check MongoDB Service Status
systemctl status mongod
Summary List of Status Statistics (Continuous)
Summary List of Status Statistics (5 Rows, Summarized Every 2 Seconds)
mongostat --rowcount 5 2
Enter the MongoDB Command Line
By default, running this command will look for a MongoDB server listening on port 27017 on the localhost interface.
If you’d like to connect to a MongoDB server running on a different port, then use the --port option. For example, if you wanted to connect to a local MongoDB server listening on port 22222, then you’d issue the following command:
mongo --port 22222
systemctl stop mongod
MongoDB is an excellent NoSQL solution for many types of projects. It is resilient, robust, and durable document database that is designed for ease of development and scaling.
Our talented Support Teams are full of experienced technicians and administrators who have intimate knowledge of multiple web hosting technologies, especially those discussed in this article. We are always available to assist with any issues related to this article, 24 hours a day, 7 days a week 365 days a year.
If you are a Fully Managed VPS server, Cloud Dedicated, VMWare Private Cloud, Private Parent server or a Dedicated server owner and you are uncomfortable with performing any of the steps outlined, we can be reached via phone @800.580.4985, a chator support ticket to assisting you with this process.
- How to Edit the PHP Memory for Your WordPress Site via WP Toolkit
- 4 Methods for How to Install Yarn on Windows Server
- How to Install Bpytop Resource Monitoring Tool on AlmaLinux
- How to Fix “This Site Can’t Provide a Secure Connection” Error
- How to Install MongoDB on AlmaLinux
- How to Install PostgreSQL on AlmaLinux
About the Author: David Singer
I am a g33k, Linux blogger, developer, student, and former Tech Writer for Liquidweb.com. My passion for all things tech drives my hunt for all the coolz. I often need a vacation after I get back from vacation....
Our Sales and Support teams are available 24 hours by phone or e-mail to assist.
How to Edit the PHP Memory for Your WordPress Site via WP ToolkitRead Article
What is CGI-Bin and What Does it Do?Read Article
Top 10 Password Security StandardsRead Article
Top 10 Password Security StandardsRead Article
How to Use the WP Toolkit to Secure and Update WordPressRead Article