How to install mongoDB on centos 7.

MongoDB is a free and open-source cross-platform document-oriented database program. Classified as a NoSQL database program, MongoDB avoids the traditional table-based relational database structure in favor of JSON-like documents with dynamic schemas, making data integration in some applications easier and faster.

1. Log in to your VPS via SSH

2. Create a MongoDB repository file using an editor as below –

vim /etc/yum.repos.d/mongodb.repo

3. If you are running a 64-bit system, add the below information to the file you have created – 

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

4. Press i(to insert) and paste the content above then press : then wq!(save and quit) then press Enter key as per the screenshot.

5. As a best practice, we should also update our package using this command – 

yum -y update

6. Now, run the below-given command to install MongoDB – 

yum -y install mongodb-org mongodb-org-server

That’s it.
MongoDB is installed. 

Here’s a list of some useful commands –

  • Start-Up MongoDB – systemctl start mongod
  • Check MongoDB Service Status – systemctl status mongod
  • Enter the MongoDB Command Line – mongo
  • Shutdown MongoDB – systemctl stop mongod
  • Summary List of Status Statistics (Continuous) – mongostat
  • Summary List of Status Statistics (5 Rows, Summarized Every 2 Seconds) – mongostat –rowcount 5 2

By default, the MongoDB server listening on port 27017 on the localhost interface. To change MongoDB listening port to 22222: mongo –port 22222.

Leave A Comment?