Cài đặt MongoDB trên CentOS

Configure the package management system (yum).

Create a /etc/yum.repos.d/mongodb-org-4.0.repo file so that you can install MongoDB directly using yum:

[mongodb-org-4.0]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/amazon/2013.03/mongodb-org/4.0/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-4.0.asc

Install the MongoDB packages

sudo yum install -y mongodb-org

Start MongoDB

sudo service mongod start

Verify that MongoDB has started successfully

[initandlisten] waiting for connections on port

where <port> is the port configured in /etc/mongod.conf27017 by default.

You can optionally ensure that MongoDB will start following a system reboot by issuing the following command:copycopied

sudo chkconfig mongod on

Stop MongoDB.

As needed, you can stop the mongod process by issuing the following command:copycopied

sudo service mongod stop

Restart MongoDB.

You can restart the mongod process by issuing the following command:copycopied

sudo service mongod restart

You can follow the state of the process for errors or important messages by watching the output in the /var/log/mongodb/mongod.log file.

spacer