SystemMen - How to install MongoDB in CentOS 7? This article will guide you step by step how to install it successfully.
MongoDB is a well-known database type, many large systems are using it, especially the development of IoT.
Add MongoDB repository to the server
First, just like database types like MariaDB, MongoDB allows you to install it through the repository.
Type the command below to create MongoDB repository file.
yum install nano -y && nano /etc/yum.repos.d/mongodb-org-4.0.repo
Then, copy the text below into the file above and save it.
[mongodb-org-4.0] name=MongoDB Repository baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/4.0/x86_64/ gpgcheck=1 enabled=1 gpgkey=https://www.mongodb.org/static/pgp/server-4.0.asc
Install MongoDB in CentOS 7
You type the following command to proceed with MongoDB installation for CentOS 7 server.
In the demo, I am using CentOS version 7.6.1810 (Core) and the current MongoDB version is 4.0.9.
yum install -y mongodb-org
You can see more information about installation at the MongoDB tutorial page.
After installation is complete, type the following command to start the service.
service mongod start
Type below command to enable MongoDB’s service auto start after reboot.
chkconfig mongod on
And then, you check to see if the service is working.
service mongod status
The result like this.
[root@db01 ~]# service mongod status Redirecting to /bin/systemctl status mongod.service ● mongod.service - MongoDB Database Server Loaded: loaded (/usr/lib/systemd/system/mongod.service; enabled; vendor preset: disabled) Active: active (running) since Tue 2019-04-16 21:23:49 +07; 18h ago Docs: https://docs.mongodb.org/manual Process: 27437 ExecStart=/usr/bin/mongod $OPTIONS (code=exited, status=0/SUCCESS) Process: 27435 ExecStartPre=/usr/bin/chmod 0755 /var/run/mongodb (code=exited, status=0/SUCCESS) Process: 27433 ExecStartPre=/usr/bin/chown mongod:mongod /var/run/mongodb (code=exited, status=0/SUCCESS) Process: 27431 ExecStartPre=/usr/bin/mkdir -p /var/run/mongodb (code=exited, status=0/SUCCESS) Main PID: 27441 (mongod) CGroup: /system.slice/mongod.service └─27441 /usr/bin/mongod -f /etc/mongod.conf Apr 16 21:23:48 db01 systemd[1]: Starting MongoDB Database Server… Apr 16 21:23:48 db01 mongod[27437]: about to fork child process, waiting until server is ready for connections. Apr 16 21:23:48 db01 mongod[27437]: forked process: 27441 Apr 16 21:23:49 db01 systemd[1]: Started MongoDB Database Server.
Like other databases, it also has shell cli for you to work with the database.
Type mongo
to enter shell cli.
![How to install MongoDB in CentOS 7 how-to-install-mongodb-in-centos-7 How to install MongoDB in CentOS 7](/wp-content/uploads/2019/04/how-to-install-mongodb-in-centos-7.jpg)
Conclusion
Installing MongoDB in CentOS 7 is really simple. In fact, it only takes about 2-3 lines of code to complete the installation. Yes, installation is one thing and using it is another.
«« Fix error disk read-only in VestaCP after rebootHow to search for a container image »»