Redis集群——Redis高可用集群添加密码
线上环境的redis集群肯定要有密码的,今天介绍一下redis-cluster如何配置密码
第一步,修改每个redis-700x.conf配置文件,注意密码必须一致
masterauth 123456
requirepass 123456
第二步,删除每个节点的配置文件
注意,如果你使用redis-trib.rb命令会提示无法连接,如
[root@localhost src]# ./redis-trib.rb check 192.168.1.10:7001
[ERR] Sorry, can’t connect to node 192.168.1.10:7001
通过find / -name ‘client.rb’命令找到文件位置
修改第三个文件
再重试命令就正常了
[root@localhost src]# ./redis-trib.rb check 192.168.1.10:7001
Performing Cluster Check (using node 192.168.1.10:7001)
M: 367899876fc08d3475646b8890fb14f6877c7b95 192.168.1.10:7001
slots: (0 slots) master
0 additional replica(s)
[OK] All nodes agree about slots configuration.
Check for open slots…
Check slots coverage…
[ERR] Not all 16384 slots are covered by nodes.
第三步,重启集群
./redis-trib.rb create --replicas 1 192.168.1.10:7001 192.168.1.11:7002 192.168.1.12:7003 192.168.1.10:7004 192.168.1.11:7005 192.168.1.12:7006
第四步,测试
[root@localhost src]# ./redis-trib.rb check 192.168.1.10:7001
Performing Cluster Check (using node 192.168.1.10:7001)
M: 367899876fc08d3475646b8890fb14f6877c7b95 192.168.1.10:7001
slots:0-5460 (5461 slots) master
1 additional replica(s)
S: eb878ae3b4908e8be97978869b26929166e96fd9 192.168.1.11:7005
slots: (0 slots) slave
replicates 367899876fc08d3475646b8890fb14f6877c7b95
M: bc780887c5cd2fc8e15de32da37e2d407f719bed 192.168.1.12:7003
slots:10923-16383 (5461 slots) master
1 additional replica(s)
S: ea85ffe7a379f1d53c9e9d5c0fa85cb88b0c79f4 192.168.1.10:7004
slots: (0 slots) slave
replicates 49622a7f76d078c8f752362ce765dc274616d77b
M: 49622a7f76d078c8f752362ce765dc274616d77b 192.168.1.11:7002
slots:5461-10922 (5462 slots) master
1 additional replica(s)
S: 8640a636d5c6fa926363602be4b0d081e0fb9396 192.168.1.12:7006
slots: (0 slots) slave
replicates bc780887c5cd2fc8e15de32da37e2d407f719bed
[OK] All nodes agree about slots configuration.
Check for open slots…
Check slots coverage…
[OK] All 16384 slots covered.
[root@localhost src]#
第五步,带密码访问集群
./redis-cli -c -h 192.168.1.10 -p 7001 -a 123456
[root@localhost redis-4.0.1]# redis-cli -c -h 192.168.1.10 -p 7001 -a 123456
192.168.1.10:7001> keys *
(empty list or set)
192.168.1.10:7001>
还没有评论,来说两句吧...