啓用shareding認證必須停止集羣
Enforce Keyfile Internal Authentication on Existing Sharded Cluster Deployment
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.
啓用keyfile配置文件參數,重新啓動mongod服務器,
修改mongod啓動配置文件
以配置文件的方式啓動mongod
mongod --config <path-to-config-file>
在MONGODB3.2版本中,不建議CONFIG服務器使用MIRROR的方式,推薦使用REPLSET的方式啓動CONFIG服務器
Create a Shard-Local User Administrator (Optional).
單獨配置每個分片的本地管理賬號,這個賬號只能在這個分片使用
Enforce Access Control for the mongos servers.
啓用keyfile配置文件參數,重新啓動mongod服務器,
修改mongod啓動配置文件
以配置文件的方式啓動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.
Create the user administrator.
Authenticate as the user administrator.
db.getSiblingDB("admin").auth("fred", "changeme1" )
另外還可以使用下面的方式登錄到集羣
mongo -u "fred" -p "changeme1" --authenticationDatabase "admin"
Create Administrative User for Cluster Management
創建集羣管理員在admin數據庫中