Install MongoDB on CentOS

Install MongoDB on CentOS

To install MongoDB on CentOS, you can follow these steps. MongoDB is a popular NoSQL database management system.

1. Add MongoDB Repository:

MongoDB provides an official repository for CentOS. Create a repo file for MongoDB:

sudo nano /etc/yum.repos.d/mongodb-org-4.4.repo

Add the following content:

[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

Save and close the file.

2. Install MongoDB:

Now, install the MongoDB packages:

sudo yum install -y mongodb-org

3. Start MongoDB:

Start the MongoDB service:

sudo systemctl start mongod

4. Enable MongoDB to Start on Boot:

Enable MongoDB to start on boot:

sudo systemctl enable mongod

5. Check MongoDB Status:

Verify that MongoDB is running without errors:

sudo systemctl status mongod

6. Access MongoDB Shell:

Access the MongoDB shell to interact with the database:

mongo

7. Secure MongoDB (Optional):

It’s recommended to secure your MongoDB installation. Create an administrative user and enable authentication.

Access the MongoDB shell:

mongo

Switch to the admin database:

use admin

Create an administrative user. Replace <username> and <password> with your desired username and password:

db.createUser({user: "<username>", pwd: "<password>", roles: ["userAdminAnyDatabase", "dbAdminAnyDatabase", "readWriteAnyDatabase", "clusterAdmin"]})

Exit the MongoDB shell:

exit

Edit the MongoDB configuration file:

sudo nano /etc/mongod.conf

Add the following lines to enable authentication:

security: authorization: enabled

Save and close the file.

Restart MongoDB:

sudo systemctl restart mongod

Now, you’ll need to provide the created username and password when connecting to MongoDB.

That’s it! You have successfully installed MongoDB on CentOS. Adjust the configuration based on your specific requirements and security considerations.

You May Also Like
Proxmox commands cheat sheet terminal output
Read More

Proxmox Commands – cheat sheet

Managing Proxmox Virtual Environment (PVE) through the command line can significantly speed up administration tasks, especially when working…
secure ssh configuration changing default ssh port for linux and windows servers
Read More

How to Change the SSH Port

Why Change the Default SSH Port? Changing the default SSH port is a common security practice that helps…