共计 2821 个字符,预计需要花费 8 分钟才能阅读完成。
自动写代码机器人,免费开通
这期内容当中丸趣 TV 小编将会给大家带来有关如何设置 redis 集群密码,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。
注意事项:
1. 如果是使用 redis-trib.rb 工具构建集群,集群构建完成前不要配置密码,集群构建完毕再通过 config set + config rewrite 命令逐个机器设置密码
2. 如果对集群设置密码,那么 requirepass 和 masterauth 都需要设置,否则发生主从切换时,就会遇到授权问题,可以模拟并观察日志
3. 各个节点的密码都必须一致,否则 Redirected 就会失败
config set masterauth abc
config set requirepass abc
config rewrite
测试版本:
redis3.0.7
测试环境:
centos7
集群规模:
3 主 3 从
集群构建成功前的 redis 配置:
port 8000
cluster-enabled yes
cluster-config-file nodes-8000.conf
cluster-node-timeout 15000
dir /opt/redisdata
appendonly yes
appendfilename appendonly-8000.aof
logfile /opt/redisdata/8000.log
daemonize yes
pidfile /var/run/redis-8000.pid
dbfilename dump-8000.rdb
cluster-require-full-coverage no
集群构建成功后的 redis 配置:
port 8004
cluster-enabled yes
cluster-config-file nodes-8004.conf
cluster-node-timeout 15000
dir /opt/redisdata
appendonly yes
appendfilename appendonly-8004.aof
logfile /opt/redisdata/8004.log
daemonize yes
pidfile /var/run/redis-8004.pid
dbfilename dump-8004.rdb
cluster-require-full-coverage no
# Generated by CONFIG REWRITE
requirepass abc
masterauth abc
测试:
1.8002 是主,8005 是 8002 的从,现在要 kill 掉 8002 模拟主从切换
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
上述就是丸趣 TV 小编为大家分享的如何设置 redis 集群密码了,如果刚好有类似的疑惑,不妨参照上述分析进行理解。如果想知道更多相关知识,欢迎关注丸趣 TV 行业资讯频道。
向 AI 问一下细节