注意事项:
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
4.简单测试了GET SET命令,正常
以上这篇基于redis集群设置密码的实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
暂无评论...
更新日志
2024年11月22日
2024年11月22日
- 【古典音乐】图蕾克《巴赫-哥德堡变奏曲》(羽管键琴版)2CD.2004[FLAC+CUE整轨]
- 童丽《季候风》双层SACD头版限量珍藏[WAV+CUE][1.1G]
- 谭咏麟《倾·听》2022改编歌曲[WAV+CUE][1.2G]
- 证声音乐图书馆《毕业季·青春爵士》[320K/MP3][49.17MB]
- 张国荣《劲歌集》欧盟压碟[原抓WAV+CUE]
- 黄安《明明知道相思苦》[WAV+CUE]
- 李俊广VS许岚岚《秋蝉》[低速原抓WAV+CUE]
- 证声音乐图书馆《毕业季·青春爵士》[FLAC/分轨][265.35MB]
- 证声音乐图书馆《爵士嘉年华 Big Band Swing》[320K/MP3][62.44MB]
- 证声音乐图书馆《爵士嘉年华 Big Band Swing》[FLAC/分轨][239.3MB]
- 中国民歌宝典《民歌精粹经典珍藏》12CD[WAV]
- 阿姆斯特丹小交响乐团演奏《室内交响曲》SACD-WAV
- Parijat-BuddhaGarden《佛陀花园》[WAV+CUE]
- 证声音乐图书馆《巴莎诺瓦 惬意咖啡馆》[320K/MP3][220.56MB]
- 证声音乐图书馆《巴莎诺瓦 惬意咖啡馆》[FLAC/分轨][220.56MB]