Mongodb Account Management

Mongodb Account Management

 

Introduction

Mongodb is a schema free sql class of non-distributed database, you can use it to do a lot of very flexible storage and operation, recently learned about the mechanisms under its accounts, you can do various operations on all land users by setting the startup mode of limited auth .

Authentication landing mongodb

sudo ./bin/mongod --auth -dbpath=/usr/local/mongodb/data/db --port 27017 -logpath=/usr/local/mongodb/log --logappend

dbpath logpath in advance and create a separate directory of your own good.
-auth: landing mongodb expressed by authentication

But starting with auth server mongodb way before , you need to create a user can manage all accounts (usually in the admin database), such as:

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

Created a "root" account, its role (ie competence) is "userAdminAnyDatabase", that is, the user admin privileges can manage any database.

If you do not use the "use admin", that will be created in the current database user, do not specify a default db landing in the test database, createUser the role specified type of permissions, roles in the "db" specifies the scope of the database.

After landing in a set auth mode, client end by mongo landing mongodb, must be coupled with "--authenticationDatabase" option, "authenticationDatabase" specifies the database to check user account name and password, for example:

./bin/mongo mytest -u "test" -p "123" --authenticationDatabase admin
  • Mongo immediately following the command "mytest" specifies the database is located after landing, ie, after the successful landing will jump directly to the database, not written by default test database.
  • --authenticationDatabase specifies the database to verify the user name and password, which means that the database login user created, wrote a database which, in the example above, user = "test" and passwd = "123" is created in the admin db of.
  • If the goal is both landing test database, test the database and the user is created, you can not write parameters --authenticationDatabase behind, as can also visit:
./bin/mongo mytest -u "test" -p "123" 

mongodb Close

Do not kill -9 pid way mongodb shutdown process, so that there will be many service resources not recycle, you should use

kill -2 pid

or

db.shutdownServer()

Reprinted: https: //www.jianshu.com/p/88e0d33a6201

Guess you like

Origin www.cnblogs.com/xibuhaohao/p/10954436.html