CentOS7 MongoDB installation and basic configuration

Source: Internet
Author: User
Tags install mongodb mongo shell

I. Acquisition of installation packages

1. Create a file:

vi /etc/yumrepos.d/mongodb-org-4.0. Repo

2. In the file created in the previous step, write the following:

[mongodb-org-4.0]name=MongoDB repositorybaseurl=https://  repo.mongodb.org/yum/redhat/$releasever/mongodb-org/4.0/x86_64/gpgcheck=1enabled=1  gpgkey=https://WWW.MONGODB.ORG/STATIC/PGP/SERVER-4.0.ASC

3. Download the package, the downloaded file storage location has Downloaddir specified:

Yum Install --downloaddir=/home/mongodb-rpm/--downloadonly mongodb-org

When completed, the following files will be downloaded to the specified directory:

These files are the installation packages and their dependent packages that are required to install MongoDB and can be copied to other CentOS7 systems for the installation of MongoDB.

Second, installation

1. Copy the installation package and its dependent packages to the machine to be installed, any location.
2. Go to the installation package directory.
3. Execute the following command to install:

RPM-IVH *

Such as:

Third, modify the configuration: Modify the data, log storage path

The goal is to store the data and logs in a larger disk partition to avoid the disk partition being filled up after data growth.
Here is an example of storing data and logs under/home.
1. Create two folders, respectively, to store data and logs. Note that you want to change the owner of the two folders to Mongod:mongod:

CD/homemkdir mongo-dbmkdir mongo-logchown -R mongod:mongod./ mongo-dbchown -R mongod:mongod./mongo-log

2. Open the configuration file:

Vim/etc/mongod.conf

3. Modify the configuration file, for example, the Red box section of the figure is the content to be modified:

Iv. Modify configuration: Enable authentication

1. Open the configuration file:

Vim/etc/mongod.conf

2. Modify the configuration file, for example, the Red box section of the figure is the content to be modified:

V. Modify configuration: Turn on remote access

Remote access is not allowed by default. This modification is optional, and if you are only accessing MongoDB natively, you do not need to turn on remote access.
1. Open the configuration file:

Vim/etc/mongod.conf

2. Modify the configuration file, for example, the Red box section of the figure is the content to be modified:

Vi. service start, stop, view

After the MongoDB installation is complete, it is automatically configured as a system service that enables and systemctl the command to be managed by the service.
Start the service:

Systemctl Start Mongod

View service Status:

Systemctl Status Mongod

Stop service:

Systemctl Stop Mongod

Restart Service:

Systemctl Restart Mongod
Vii. Creating users

When you do not create a user, you can log in to the MONGO shell without using authentication, but after you create the user, you must log on as a user.

1. Enter MONGO Shell

Mongo

Such as:

2. Create a superuser root, and after success, exit the MONGO Shell:

Use Admindb.createuser (    {        "root",        pwd"  abc123",        "root""   Admin"  }]    })

Such as:

3. Log in to the MONGO shell using the root user:

" Root " " abc123 " " Admin "

Such as:

CentOS7 MongoDB installation and basic configuration

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.