Web development basic and advance tutorial, php basic tutorial, laravel basic tutorial, React Native tutorial

Wednesday, March 22, 2023

Digitalocean How to Install MongoDB on CentOS 7

0 comments
Digitalocean 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.

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      

                         

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)

mongostat

Summary List of Status Statistics (5 Rows, Summarized Every 2 Seconds)

mongostat --rowcount 5 2

Enter the MongoDB Command Line

mongo

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

Shutdown MongoDB

systemctl stop mongod

No comments:

Post a Comment