MongoDB installation and configuration under CENTOS7

Source: Internet
Author: User
Tags auth mongodb create database

1. Download installation package
Https://www.mongodb.com/download-center#atlas
Go straight to the official website and find your own version.

[Root@liugepython3 mongodb]# wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-3.6.4.tgz

2. Extract and rename move to specified location

3. File path under/usr/local/mongodb

New Database File Store path

Mkdir-p data/db

New Database log Store path

mkdir logs

4. Create a new configuration under/usr/local/mongodb/bin

Vim mongodb.conf

DBPath =/usr/local/mongodb/data/db #数据库文件存放目录
logpath =/usr/local/mongodb/logs/mongodb.log #日志文件存放目录
port = 27017  #端口
fork = True  #以守护程序的方式启用, that is, running
Nohttpinterface = True
auth=true
bind_ip=0.0.0.0 # in the background Turn on remote connections

5 Configuration to System environment variables
Vim/etc/profile

#添加
export mongodb_home=/usr/local/mongodb

export path= $PATH: $MONGODB _home/bin
#wq保存退出

Refreshing the configuration file to take effect
Source/etc/profile

6. Startup and shutdown
Under the/usr/local/mongodb/bin

Mongod-f mongodb.conf or./mongod-f mongodb.conf

Shut down
Mongod-f./mongodb.conf–shutdown or./mongod-f/mongodb.conf–shutdown

7, open the port

Firewall-cmd–zone=public–add-port=27017/tcp–permanent
View ports
Firewall-cmd–permanent–query-port=27017/tcp
Reboot firewall

Firewall-cmd–reload

8. Create user

Create user admin:
Use admin
Db.createuser ({User: "root", pwd: "root123456", roles:["Useradminanydatabase"})
Db.auth (' root ', ' root123456 ')
Log on as User Administrator and switch database, create DATABASE User:
Switch to test database
Use test
to create user name, password, role
Db.creat Euser ({User: "username", pwd: "@user123456 *", Roles:[{role: "ReadWrite", DB: "Securitydata"}])
Set Auth to True in the MongoDB configuration (/etc/mongod.conf):
Security:
authorization:enabled
Validate MongoDB database permissions.
Db.auth (' user ', ' @user123456 * ')

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.