CentOS 7 Detailed Steps for Installing MongoDB

  centos7, mongodb

Create/etc/yum.repos.d/mongodb-org-4.0.repoFile, edit content is as follows:

[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

Run the following command to install the latest version of mongodb:

sudo yum install -y mongodb-org

Configurationmongod.confAllow remote connections:

$ vim /etc/mongod.conf
 
 # Listen to all ip address
 bind_ip = 0.0.0.0

Start mongodb:

sudo service mongod start

To create an administrator user:

$ mongo
>use admin
db.createUser(
{
user: "myUserAdmin",
pwd: "abc123",
roles: [ { role: "userAdminAnyDatabase", db: "admin" }, "readWriteAnyDatabase" ]
}
)

Enable rights management:

$ vim /etc/mongod.conf

#security
security:
authorization: enabled

Restart mongodb:

sudo service mongod restart

We’re done!