啓用shareding認證

啓用shareding認證必須停止集羣

Enforce Keyfile Internal Authentication on Existing Sharded Cluster Deployment


Create a keyfile.

shareding cluster 成員服務器所有的keyfile的內容必須完成一致
 
可以使用任意方法生成keyfile文件的內容,但是內容的長度必須在6-1024位
 
下面的方法是使用openssl生成1024個隨機字符作爲keyfile
 
openssl rand -base64 755 > <path-to-keyfile>
chmod 400 <path-to-keyfile>

Copy the keyfile to each component in the sharded cluster.

 

拷貝keyfile到shareding cluster 所有成員服務器中的相同位置


Disable the Balancer.

必須停用balance,並且直到balance完全停止爲止
可以通過查看sh.status()查看是否就還有正在running的balance
sh.stopBalancer()
sh.getBalancerState()

Shut down all mongos instances for the sharded cluster.

首先關閉所有的mongos服務器

db.getSiblingDB("admin").shutdownServer()

Shut down config server mongod instances.

然後關閉所有的config服務器

db.getSiblingDB("admin").shutdownServer()

 


Shut down shard replica set mongod instances.

關閉所有的mongoDB replset 分片

確保mongoDB replset 的primary節點是最後關閉的 

db.getSiblingDB("admin").shutdownServer()

Enforce Access Control on the Config Servers.

首先啓動config服務器

啓用keyfile配置文件參數,重新啓動mongod服務器,

修改mongod啓動配置文件

keyFile=/etc/mongo.key
replSet=replset

以配置文件的方式啓動mongod

mongod --config <path-to-config-file>

在MONGODB3.2版本中,不建議CONFIG服務器使用MIRROR的方式,推薦使用REPLSET的方式啓動CONFIG服務器

 


Enforce Access Control for each Shard in the Sharded Cluster.

然後啓動每個分片的mongod replset服務器

啓用keyfile配置文件參數,重新啓動mongod服務器,

修改mongod啓動配置文件

keyFile=/etc/mongo.key
replSet=replset

以配置文件的方式啓動mongod

mongod --config <path-to-config-file>

Create a Shard-Local User Administrator (Optional).

單獨配置每個分片的本地管理賬號,這個賬號只能在這個分片使用

admin = db.getSiblingDB("admin")
admin.createUser(
  {
    user: "fred",
    pwd: "changeme1",
    roles: [ { role: "userAdminAnyDatabase", db: "admin" } ]
  }
)

Enforce Access Control for the mongos servers.

最後啓動mongos服務器

啓用keyfile配置文件參數,重新啓動mongod服務器,

修改mongod啓動配置文件

keyFile=/etc/mongo.key
replSet=replset

以配置文件的方式啓動mongod

mongod --config <path-to-config-file>

如果config DB 服務器是一個replset的話,則

configdb = replset/192.168.1.1:27017,192.168.1.2:27017,192.168.1.3:27017

這個地方最少填寫上replset的一個成員

 

如果config DB 服務器是mirror的話,則

configdb = 192.168.1.1:27017,192.168.1.2:27017,192.168.1.3:27017

必須填寫上所有的mirror成員

mongoDB3.2不推薦使用mirror方式配置config DB服務器


Connect to the mongos instance over the localhost interface.

必須在mongos服務器所在的物理服務器上啓動mongo shell 並連接到本地的mongod端口
這個本地端口在第一次創建用戶後就會失效

Create the user administrator.

創建集羣管理員
admin = db.getSiblingDB("admin")
admin.createUser(
  {
    user: "fred",
    pwd: "changeme1",
    roles: [ { role: "userAdminAnyDatabase", db: "admin" } ]
  }
)

Authenticate as the user administrator.

使用新創建的用戶登錄到admin庫
 
在mongo shell中使用db.auth()來進行認證
db.getSiblingDB("admin").auth("fred", "changeme1" )

另外還可以使用下面的方式登錄到集羣

mongo -u "fred" -p "changeme1" --authenticationDatabase "admin"

Create Administrative User for Cluster Management

創建集羣管理員在admin數據庫中

db.getSiblingDB("admin").createUser(
  {
    "user" : "ravi",
    "pwd" : "changeme2",
    roles: [ { "role" : "clusterAdmin", "db" : "admin" } ]
  }
)

 


Authenticate as cluster admin.

 

使用新創建的clusterAdmin賬號登陸


Start the load balancer.

使用新創建的clusterAdmin賬號啓動balance

 

sh.stopBalancer()
sh.getBalancerState()

Create additional users (Optional).

創建其它有需要的用戶角色

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章