MongoDB Learning to organize the access control
1, restricting access to specific IP addresses, only need to add the--BIND_IP parameter when starting up, the client connection should also be added--host
/app/mongo/mongodb/bin/mongod--dbpath=/app/mongo/mongodb/data/test-- Logpath=/app/mongo/mongodb/data/test/server.log--fork--bind_ip 132.42.33.190
/app/mongo/mongodb/bin/mongo--host 132.42.33.190
2, set the port, only need to add the--port parameter at start-up, the client connection also needs to be added--port
/app/mongo/mongodb/bin/mongod--dbpath=/app/mongo/mongodb/data/test--logpath=/app/mongo /mongodb/data/test/server.log--fork--port 28018
/app/mongo/mongodb/bin/mongo--port 28012
3, user authentication management
MongoDB has an admin database by default, and the user on the admin library is larger than other libraries, that is, users of the admin library can manipulate any of the other libraries.
Enabled: Login verification
/app/mongo/mongodb/bin/mongod--dbpath=/app/mongo/mongodb /data/test--logpath=/app/mongo/mongodb/data/test/server.log--fork--auth
Note: MongoDB default has an admin database, if there is no data in Admin.system.users, login verification will not take effect
1) Create user
> Db.adduser ("Root", "111111")--New user
> Db.auth ("Root", "111111")--set user to have database connection verification
2) Set up the designated rights user,
Command format: Db.adduser (Username,password[,readonly=false])
For example: Add a read-only user User_reader to the test library, as shown in the code:
> Db.adduser ("User_reader", "Passw0rd", true)--Create a read-only user
> Show Collections--can view
System.indexes
System.users
> Db.t1.insert ({name: "Liangzhangping", age:29})--but cannot be added, deleted, and updated
Unauthorized
3) Delete the specified user, call the Db.removeuser (username) command, just pass in the user name, you can delete it, call Db.system.users.find () to see if the deletion
> Db.removeuser ("User_reader")
> Db.system.users.find ()
{"_id": ObjectId ("4fd9c4bc869208ca70bcf180"), "User": "Test", "readOnly": false, "pwd": "Ab29e5e0e27099729856ff91da2b 9112 "}
This article is from "Smile_ Youth" blog, please be sure to keep this source http://smileyouth.blog.51cto.com/7273768/1616370
MongoDB Learning to organize the access control