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 * ')