redis集群设置密码

柔光的暖阳◎ 2022-09-21 01:48 451阅读 0赞

注意事项:

1.如果是使用redis-trib.rb工具构建集群,集群构建完成前不要配置密码,集群构建完毕再通过config set + config rewrite命令逐个机器设置密码

2.如果对集群设置密码,那么requirepass和masterauth都需要设置,否则发生主从切换时,就会遇到授权问题,可以模拟并观察日志

3.各个节点的密码都必须一致,否则Redirected就会失败

  1. config set masterauth abc
  2. config set requirepass abc
  3. config rewrite

测试版本:

redis3.0.7

测试环境:

centos7

集群规模:

3主3从

集群构建成功前的redis配置:

  1. port 8000
  2. cluster-enabled yes
  3. cluster-config-file "nodes-8000.conf"
  4. cluster-node-timeout 15000
  5. dir "/opt/redisdata"
  6. appendonly yes
  7. appendfilename "appendonly-8000.aof"
  8. logfile "/opt/redisdata/8000.log"
  9. daemonize yes
  10. pidfile "/var/run/redis-8000.pid"
  11. dbfilename "dump-8000.rdb"
  12. cluster-require-full-coverage no

集群构建成功后的redis配置:

  1. port 8004
  2. cluster-enabled yes
  3. cluster-config-file "nodes-8004.conf"
  4. cluster-node-timeout 15000
  5. dir "/opt/redisdata"
  6. appendonly yes
  7. appendfilename "appendonly-8004.aof"
  8. logfile "/opt/redisdata/8004.log"
  9. daemonize yes
  10. pidfile "/var/run/redis-8004.pid"
  11. dbfilename "dump-8004.rdb"
  12. cluster-require-full-coverage no
  13. # Generated by CONFIG REWRITE
  14. requirepass "abc"
  15. masterauth "abc"

测试:

1.8002是主,8005是8002的从,现在要kill掉8002模拟主从切换

![Image 1][]

Center

2.查看8005的日志,8005最终被选举成新的master

21227:S 14 Jun 07:28:49.343 # Connection with master lost.

21227:S 14 Jun 07:28:49.343 * Caching the disconnected master state.

21227:S 14 Jun 07:28:49.433 * Connecting to MASTER 127.0.0.1:8002

21227:S 14 Jun 07:28:49.433 * MASTER <-> SLAVE sync started

21227:S 14 Jun 07:28:49.434 # Error condition on socket for SYNC: Connection refused

21227:S 14 Jun 07:28:50.437 * Connecting to MASTER 127.0.0.1:8002

21227:S 14 Jun 07:29:06.205 # Start of election delayed for 564 milliseconds (rank #0, offset 337).

21227:S 14 Jun 07:29:06.507 * Connecting to MASTER 127.0.0.1:8002

21227:S 14 Jun 07:29:06.507 * MASTER <-> SLAVE sync started

21227:S 14 Jun 07:29:06.507 # Error condition on socket for SYNC: Connection refused

21227:S 14 Jun 07:29:06.808 # Starting a failover election for epoch 10.

21227:S 14 Jun 07:29:06.810 # Failover election won: I’m the new master.

21227:S 14 Jun 07:29:06.810 # configEpoch set to 10 after successful failover

21227:M 14 Jun 07:29:06.810 * Discarding previously cached master state.

3.再次启动8002,查看8005的日志,8002已经变成8005的slave

21227:M 14 Jun 07:32:53.511 * Slave 127.0.0.1:8002 asks for synchronization

21227:M 14 Jun 07:32:53.511 * Full resync requested by slave 127.0.0.1:8002

21227:M 14 Jun 07:32:53.511 * Starting BGSAVE for SYNC with target: disk

21227:M 14 Jun 07:32:53.511 * Background saving started by pid 21613

21613:C 14 Jun 07:32:53.513 * DB saved on disk

21613:C 14 Jun 07:32:53.513 * RDB: 0 MB of memory used by copy-on-write

21227:M 14 Jun 07:32:53.612 * Background saving terminated with success

21227:M 14 Jun 07:32:53.612 * Synchronization with slave 127.0.0.1:8002 succeeded

4.简单测试了GET SET命令,正常

原文出自:http://blog.csdn.net/daiyudong2020/article/details/51674169

[Image 1]:

发表评论

表情:
评论列表 (有 0 条评论,451人围观)

还没有评论,来说两句吧...

相关阅读