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> 
 

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值