1, the security certification mode to start
Copy Code code as follows:
Bin/mongod?–auth?-dbpath/users/mc2/mongo/db-logpath/users/mc2/mongo/log.log &
You can enable authentication mode by starting the Mongod process with the –auth option.
Alternatively, you can modify the/etc/mongodb.conf, set the auth=true, and restart the Mongod process.
2. Add User
Copy Code code as follows:
Db.adduser ("admin", "123456″")
3. Safety Certification
Copy Code code as follows:
Db.auth ("admin", "123456″")
In case of successful certification
Copy Code code as follows:
Db.system.users.find ()
{"_id": ObjectId ("5032e8386a7fc39e31978c50″"), "user": "admin", "readOnly": false, "pwd": "95ec4261124ba5951720b199908 D892b "}
otherwise return null
4. Write Data for database (sync to disk) lock
Copy Code code as follows:
Db.runcommand ({fsync:1,lock:1})
Description
This operation has been locked to the database and does not allow write data operations, which are generally useful when performing database backups. Execute the command, and the result example is as follows:
Copy Code code as follows:
Db.runcommand ({fsync:1,lock:1})
{"ErrMsg": "Access denied; Use admin db "," OK ": 0}
Use admin
> Db.runcommand ({fsync:1,lock:1})
{
"Info": "Now locked against writes, use Db.fsyncunlock () to unlock",
"Seealso": "Http://www.mongodb.org/display/DOCS/fsync+Command",
"OK": 1
}
5. View current lock status
Copy Code code as follows:
Db.currentop ()
> Db.currentop ()
{
"InProg": [],
"Fsynclock": 1,
"Info": "Use Db.fsyncunlock () to terminate the Fsync write/snapshot lock"
}
Where Fsynclock 1 represents the MongoDB Fsync process (responsible for synchronizing write changes to disk) does not allow other processes to perform write data operations
6, Unlock
Copy Code code as follows:
Use admin
>db.fsyncunlock ()
{"OK": 1, "info": "Unlock Completed"}
Db. $cmd. Sys.unlock.findOne () Effect equivalent
> Db.currentop ()
{"InProg": []}
Indicates that there are no locks currently available to perform write data operations.