啟用shareding認證

2021-08-04 08:40:35 字數 3508 閱讀 8103

啟用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 > chmod 400

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伺服器

修改mongod啟動配置檔案

keyfile=/etc/mongo.key

replset=replset

以配置檔案的方式啟動mongod

mongod --config

在mongodb3.2版本中,不建議config伺服器使用mirror的方式,推薦使用replset的方式啟動config伺服器

enforce access control for each shard in the sharded cluster.

然後啟動每個分片的mongod replset伺服器

修改mongod啟動配置檔案

keyfile=/etc/mongo.key

replset=replset

以配置檔案的方式啟動mongod

mongod --config

create a shard-local user administrator (optional).

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

admin = db.getsiblingdb("admin")

admin.createuser(

]

}

)

enforce access control for the mongos servers.

最後啟動mongos伺服器

修改mongod啟動配置檔案

keyfile=/etc/mongo.key

replset=replset

以配置檔案的方式啟動mongod

mongod --config

如果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 inte***ce.

必須在mongos伺服器所在的物理伺服器上啟動mongo shell 並連線到本地的mongod埠

這個本地埠在第一次建立使用者後就會失效

create the user administrator.

建立集群管理員

admin = db.getsiblingdb("admin")

admin.createuser(

]

}

)

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(

]

}

)

authenticate as cluster admin.

使用新建立的clusteradmin賬號登陸

start the load balancer.

使用新建立的clusteradmin賬號啟動balance

sh.stopbalancer()

sh.getbalancerstate()

create additional users (optional).

建立其它有需要的使用者角色

uwsgi啟用https雙向認證

秘鑰和證書生成 uwsgi 配置http和https,單機訪問可以使用http協議,對外提供https服務協議 此處配置支援https,增加 root ca ca.crt引數,表示需要驗證客戶端證書,表示強制驗證 通過pid停止重啟服務 daemonnize true 守護程序,後台執行訪問方式 p...

mongodb 安裝及其開啟使用者名稱密碼認證

安裝步驟 1.配置 mongodb 的yum 源建立yum 原始檔 vim etc yum.repos.d mongodb org 3.4.repo 新增以下內容 mongodb org 3.4 name mongodb repository baseurl gpgcheck 1 enabled 1...

SSL認證 單向認證與雙向認證

ssl協議即用到了對稱加密也用到了非對稱加密 公鑰加密 在建立傳輸鏈路時,ssl首先對對稱加密的金鑰使用非對稱加密,鏈路建立好之後,ssl對傳輸內容使用對稱加密。對稱加密 速度高,可加密內容較大,用來加密會話過程中的訊息 公鑰加密 加密速度較慢,但能提供更好的身份認證技術,用來加密對稱加密的金鑰 1...