Practical work: Install mongodb and set the login account password

For the convenience of reading, I try to include pictures and minimize nonsense
. 1. Update the repo source

vim /etc/yum.repos.d/mongodb.repo
[mongodb-org]
name=MongoDB Repository
baseurl=https://mirrors.tuna.tsinghua.edu.cn/mongodb/yum/el$releasever/
gpgcheck=0
enabled=1
yum makecache  #更新

Insert image description here
2. Install mongo

yum install mongodb-org -y                #执行安装
systemctl enable  mongod.service          #设置开机启动
systemctl start mongod.service            #开启mongodb
vim /etc/mongod.conf                      #设置bindIP 0.0.0.0 
systemctl restart mongod.service          #重启 

Insert image description here
3. Set the account password mongo 123456

Insert image description here

show dbs

Insert image description here
Execute the following command (if you don’t understand, just copy and paste, where user and pwd are the user and password. Just change it to what you want to set)

use admin 
db.createUser(
{
    
    
user: "mongo",
pwd: "123456",
roles: [ {
    
     role: "userAdminAnyDatabase", db: "admin" } ]
 }
)

After the change, exit to exit mongo.
Then set security: authorization: enabled
in vim /etc/mongo.conf.   There must be a space after #:   (set as shown in the picture). After the setting is completed, systemctl restart mongod.service restarts



Insert image description here

4. Login verification

Execute the command to view and use mongo --port 27017 -u "mongo" -p "123456" --authenticationDatabase "admin" to view, add, delete, and modify the data. However,
you cannot view the data after logging in with mongo.
Insert image description here

Insert image description here
Setup is complete. Thank you for watching.
Give me a like? ? ?

Guess you like

Origin blog.csdn.net/Lcongming/article/details/120553583