Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
How To Install and Configure MongoDB on CentOS 7
In this article, we will learn how to install and configure MongoDB on CentOS 7. MongoDB is an open-source NoSQL database that stores documents in a JSON-like format called BSON. Unlike traditional relational databases, MongoDB doesn't require a predefined schema and offers high availability, performance, and automatic scaling capabilities.
Prerequisites
- CentOS 7 installed on the Linux machine
- A user with root privileges
Adding the MongoDB Repository
By default, the MongoDB repository is not available in CentOS 7. We need to add the MongoDB repository to the local machine first.
vi /etc/yum.repos.d/mongodb-org.repo
Add the following content to the repository file ?
[mongodb-org-3.2] name=MongoDB Repository baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/3.2/x86_64/ gpgcheck=1 enabled=1 gpgkey=https://www.mongodb.org/static/pgp/server-3.2.asc
Update the system to refresh the repository information ?
yum update
Loaded plugins: fastestmirror base | 3.6 kB 00:00 extras | 3.4 kB 00:00 mongodb-org-3.2 | 2.5 kB 00:00 updates | 3.4 kB 00:00 mongodb-org-3.2/7/primary_db | 54 kB 00:01 Determining fastest mirrors * base: mirror.dhakacom.com * extras: mirror.dhakacom.com * updates: mirror.dhakacom.com No packages marked for update
Installing MongoDB
Once the repository is configured, install MongoDB using the yum command ?
yum install mongodb-org
Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile ... Installing: mongodb-org x86_64 3.2.11-1.el7 mongodb-org-3.2 5.8 k Installing for dependencies: mongodb-org-mongos x86_64 3.2.11-1.el7 mongodb-org-3.2 5.6 M mongodb-org-server x86_64 3.2.11-1.el7 mongodb-org-3.2 12 M mongodb-org-shell x86_64 3.2.11-1.el7 mongodb-org-3.2 6.7 M mongodb-org-tools x86_64 3.2.11-1.el7 mongodb-org-3.2 41 M ... Complete!
Starting MongoDB Service
Start the MongoDB service ?
systemctl start mongod
Check the status of the MongoDB service ?
systemctl status mongod
mongod.service - SYSV: Mongo is a scalable, document-oriented database.
Loaded: loaded (/etc/rc.d/init.d/mongod)
Active: active (running) since Fri 2016-11-25 14:09:25 IST; 12s ago
Docs: man:systemd-sysv-generator(8)
Process: 9901 ExecStart=/etc/rc.d/init.d/mongod start (code=exited, status=0/SUCCESS)
CGroup: /system.slice/mongod.service
??9912 /usr/bin/mongod -f /etc/mongod.conf
Configuring Process Limits
By default, MongoDB may show warnings about low process limits. To fix this, edit the process limits configuration ?
vi /etc/security/limits.d/20-nproc.conf
Change the soft process limit from 4096 to 32000 ?
* soft nproc 32000 root soft nproc unlimited
Restart MongoDB to apply the changes ?
systemctl restart mongod
Creating an Administrator User
Connect to MongoDB and create an administrator user ?
mongo
use admin
db.createUser(
{
user: "admin",
pwd: "password123",
roles: [ { role: "userAdminAnyDatabase", db: "admin" } ]
}
)
Successfully added user: {
"user" : "admin",
"roles" : [
{
"role" : "userAdminAnyDatabase",
"db" : "admin"
}
]
}
Verify the user creation ?
show users
{
"_id" : "admin.admin",
"user" : "admin",
"db" : "admin",
"roles" : [
{
"role" : "userAdminAnyDatabase",
"db" : "admin"
}
]
}
Conclusion
We have successfully installed and configured MongoDB on CentOS 7, including setting up the repository, adjusting process limits, and creating an administrator user. MongoDB is now ready for use with proper configuration and security settings.
