mongodb 分片集群和redis設(shè)置加密
設(shè)置Mongodb密碼
- 首先登錄三臺(tái)mongodb服務(wù)器備份config配置文件
- 然后登錄Mongos 3000端口 和Shrad分片主節(jié)點(diǎn)設(shè)置Mongodb管理員用戶名和密碼
./mongo 192.168.127.3/admin #使用admin庫進(jìn)行登錄
db.createUser({
user:"admin",
pwd:"Admin@123",
roles: [ { role: "root",db:"admin"}]
})
db.auth("admin","Admin@123")//認(rèn)證該用戶
- 然后生成一個(gè)添加keyFile文件用于認(rèn)證使用,賦予600權(quán)限瞎抛,遠(yuǎn)程拷貝到三臺(tái)集群上面的config下面即可
openssl rand -base64 751 > ./keyFile.key
chmod 600 ./keyFile.key #權(quán)限必須是600
scp ./keyFile.key #到對(duì)應(yīng)的在分片和Configserver的config配置文件路徑下
- 在修改增加Shard和Configserver配置文件增加相關(guān)認(rèn)證參數(shù)占锯,添加到配置文件最后即可暇番。
#開啟權(quán)限驗(yàn)證
auth=true
keyFile=/home/mongodb/config/keyFile.key
- 然后在三臺(tái)Mongos文件中增加如下操作
#指向keyFile
keyFile=/usr/local/mongodb/key/keyFile.key
- 然后重啟全部mongodb服務(wù),并驗(yàn)證登錄是否正常
$ ./mongo 192.168.127.3:30000 -uadmin -pAdmin@123 --authenticationDatabase admin
MongoDB shell version: 3.2.12
connecting to: 192.168.127.3:30000/test
Server has startup warnings:
2022-09-16T23:43:38.292+0800 I CONTROL [main]
2022-09-16T23:43:38.292+0800 I CONTROL [main] ** WARNING: The server is started with the web server interface and access control.
2022-09-16T23:43:38.292+0800 I CONTROL [main] ** The web interfaces (rest, httpinterface and/or jsonp) are insecure
2022-09-16T23:43:38.292+0800 I CONTROL [main] ** and should be disabled unless required for backward compatibility.
2022-09-16T23:43:38.292+0800 I CONTROL [main]
mongos> show dbs
admin 0.000GB
config 0.033GB
設(shè)置redis密碼
首先登錄redis服務(wù)器備份redis.conf和sentinel.conf配置文件
-
在分別6379垂攘、6380针炉、6381的redis.conf最后增加如下參數(shù)
masterauth Redis@passwd123 #在slava節(jié)點(diǎn)上面添加此配置項(xiàng)
- requirepass Redis@passwd123 #Master/Salve節(jié)點(diǎn)上添加此配置項(xiàng),如主節(jié)點(diǎn)發(fā)生切換時(shí)锡移,對(duì)應(yīng)也要添加上該配置項(xiàng)
-
在分別哨兵的sentinel.conf最后增加如下參數(shù)
sentinel auth-pass server-1M Redis@passwd123 #server-1M 為服務(wù)名稱
-
重新啟動(dòng)redis、sentinel服務(wù)
./start.sh -r redis sentinel
-
驗(yàn)證是否可以登錄
- ./redis-cli -h 1921.68.127.3 -p6379 -a Redis@passwd123 info