MongoDB learns to sort out the access control to restrict access from specific IP addresses. You only need to add the -- bind_ip parameter when starting, and add the -- host parameter when connecting to the client.
MongoDB learns to sort out the access control to restrict access from specific IP addresses. You only need to add the -- bind_ip parameter when starting, and add the -- host parameter when connecting to the client.
1. Restrict access from specific IP addresses. You only need to add the -- bind_ip parameter at startup, and add the -- host parameter at client connection.
/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. You only need to add the -- port parameter at startup and add the -- port parameter at client connection.
/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 verification management
By default, mongodb has an admin database. users in the admin database have higher permissions than those in other databases, that is, users in the admin database can perform any operation on other databases.
Enable: 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 has an admin database by default. If there is no data in admin. system. users, login verification will not take effect.
1) create a user
> Db. addUser ("root", "111111") -- create a user
> Db. auth ("root", "111111") -- set the user to have database connection Verification
2) create a user with the specified permission,
Command Format: db. addUser (username, password [, readOnly = false])
For example, add a read-only user user_reader to the test database. The Code is as follows:
> Db. addUser ("user_reader", "passw0rd", true) -- creates a read-only user.
> Show collections -- View
System. indexes
System. users
> Db. t1.insert ({name: "liangzhangping", age: 29}) -- but cannot be added, deleted, or updated.
Unauthorized
3) delete a specified user. Call the db. removeUser (username) command to delete the user. You can call db. system. users. find () to check whether the user is deleted.
> Db. removeUser ("user_reader ")
> Db. system. users. find ()
{"_ Id": ObjectId ("4fd9c4bc869208ca70bcf180"), "user": "test", "readOnly": false, "pwd": "success "}