Home | 简体中文 | 繁体中文 | 杂文 | Search | ITEYE 博客 | OSChina 博客 | Facebook | Linkedin | 知乎专栏 | Email

第 3 章 MongoDB 管理

目录

3.1. Security and Authentication
3.1.1. 超级管理员
3.1.2. 数据库用户
3.1.3. 删除用户
3.1.4. 更新角色
3.2. Unique Indexes
3.2.1. 索引管理
3.2.1.1. 唯一索引

3.1. Security and Authentication

开启认证

# vim /etc/mongodb.conf
auth = true
		

重载配置文件

# /etc/init.d/mongod reload
Stopping mongod:                                           [  OK  ]
Starting mongod:                                           [  OK  ]
		

3.1.1. 超级管理员

			
use admin;
db.createUser(
   {
     user: "admin",
     pwd: "WkAFdmfVQpP1oAEkz4YVlMCDxkG36TAi",
     roles: [ "readWrite", "dbAdmin" ]
   }
);
			
			

3.1.2. 数据库用户

注意,只有创建了超级管理后,下面的操作才会生效

MongoDB

			
use products
db.createUser(
   {
     user: "accountUser",
     pwd: "password",
     roles: [ "readWrite", "dbAdmin" ]
   }
)

db.createUser(
   {
     user: "monitor",
     pwd: "netkiller",
     roles: [ "clusterMonitor"]
   }
)
			
			

早期版本

			
> use neo
switched to db neo
> db.addUser('neo','chen')
{
        "user" : "neo",
        "readOnly" : false,
        "pwd" : "68ace374737253d87e0ec91d4fcb673d"
}

> db.system.users.find()
{ "_id" : ObjectId("4c481404b9db6474d2fcb76f"), "user" : "neo", "readOnly" : false, "pwd" : "68ace374737253d87e0ec91d4fcb673d" }

> db.auth('neo','chen')
1
			
			

3.1.3. 删除用户

Deleting Users 删除用户

To delete a user:

			
> db.getUsers();
[
	{
		"_id" : "test.monitor",
		"user" : "monitor",
		"db" : "test",
		"roles" : [
			{
				"role" : "dbOwner",
				"db" : "test"
			}
		]
	}
]
			
> db.dropUser('monitor')
ture

> db.getUsers();
[ ]
						
			

早期版本

			
db.system.users.remove( { user: username } )
			
			

3.1.4. 更新角色

			

db.updateUser( "monitor",
   {
     roles: [ "read", "clusterMonitor" ]
   }
)
			
			
comments powered by Disqus