First, install MongoDB
1. Environment configuration:
I. Operating system: CentOS release 6.8 (Final)
Cat /etc/redhat-release
II. Computer Type: x86_64
uname -M
2. Download the corresponding MongoDB version
wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel62-3.6.4.tgz
3. Unzip the MongoDB database
tar -zxvf mongodb-linux-x86_64-rhel62-3.6. 4. tgz
4. Start MongoDB
mkdir -p/data/db # CREATE DATABASE data store directory
[Email protected] opt]# Cd/opt/mongodb/bin
[[email protected] bin]#./mongod # Boot MONGO Server service, default port: 27017, local connection allowed by default
Second, configure the account number and password
1. Turn on authentication
MongoDB default installation After the completion, only allow local connection, and do not need to use any account password to directly connect MongoDB, so it is easy to be black, let pay some bitcoins, so in order to avoid these
Necessary trouble, so we need to set an account password for MONGO;
[[email protected] bin]#./mongod--auth # Enable authentication
2. Create an administrator user
>Use adminswitched to DB admin> Db.createuser ({User:"Admin",pwd:"Password", roles:["Root"]}) Successfully added User: {"User":"Admin","Roles": ["Root"] }
3. Authentication Login
> Db.auth ("admin""password")
4.MongoDB Role Type
- Database user Role (Roles)
READ: Permission to grant user read-only data
ReadWrite: Grant user permission to read and write data
- Database Management Role (DB Administration Roles):
DbAdmin: Performing administrative operations in the current DB
Dbowner: Perform any action in the current DB
Useradmin: Managing user in the current DB
- Backup and restore role (backup and restoration Roles):
Backup
Restore
- Cross-Library roles (All-database Roles):
Readanydatabase: Granting permission to read data on all databases
Readwriteanydatabase: Granting permission to read and write data on all databases
Useradminanydatabase: Granting permissions to administer user on all databases
Dbadminanydatabase: Granting permissions to administer all databases
- Cluster Management Role (Cluster administration Roles):
Clusteradmin: Granting the highest privileges to administer a cluster
Clustermanager: Grant permissions to administer and monitor the cluster, A user with this role can access the config and local databases, which is used in sharding an d replication, respectively.
Clustermonitor: Grant permissions to the monitoring cluster with readonly permissions on the monitoring tool
Hostmanager: Management Server
5. Adding a database user
> use flowppswitched to db flowpp"flowpp"pwd"flopww "" "dbowner" "flowpp" }]}) # Create user FLOWPP, set password flopww, set role Dbowner
6. View System users
>Use adminswitched to DB admin> Db.system.users.Find() # Displays the current system user {"_id":"Admin.admin","User":"Admin","DB":"Admin","Credentials": {"Scram-sha-1": {"IterationCount":10000,"Salt":"9jxmylyrak22tzmzv1thig==","Storedkey":"z76cvrbjx/ctfmn5rujtu+dz7nw=","Serverkey":"jqgonm84idmi1nixw7fdyoe55ig="} },"Roles": [ {"role":"Root","DB":"Admin" } ] }{ "_id":"FLOWPP. FLOWPP","User":"FLOWPP","DB":"FLOWPP","Credentials": {"Scram-sha-1": {"IterationCount":10000,"Salt":"kvocqwza9e2txbhpkpdaeq==","Storedkey":"50kxc3legcsvn1z16s8g4a6jvp8=","Serverkey":"0rsnsxd/7yzmqro/yohf/kfbhck="} },"Roles": [ {"role":"Dbowner","DB":"FLOWPP" } ] }
7. Delete a user
1. Switch admin, delete user flowpp, delete failed
> use adminswitched to DB admin> Db.dropuser ("flowpp")false
2. Switch FLOWPP, delete user flowpp, delete success > use flowppswitched to db flowpp> Db.dropuser ("flowpp " )true
Description
Delete the user when you need to switch to the user-managed database can be deleted;
MongoDB Setup account and password