這期內(nèi)容當(dāng)中小編將會給大家?guī)碛嘘P(guān)如何設(shè)置redis集群密碼,文章內(nèi)容豐富且以專業(yè)的角度為大家分析和敘述,閱讀完這篇文章希望大家可以有所收獲。
成都創(chuàng)新互聯(lián)從2013年開始,先為青白江等服務(wù)建站,青白江等地企業(yè),進(jìn)行企業(yè)商務(wù)咨詢服務(wù)。為青白江企業(yè)網(wǎng)站制作PC+手機(jī)+微官網(wǎng)三網(wǎng)同步一站式服務(wù)解決您的所有建站問題。
注意事項(xiàng):
1.如果是使用redis-trib.rb工具構(gòu)建集群,集群構(gòu)建完成前不要配置密碼,集群構(gòu)建完畢再通過config set + config rewrite命令逐個機(jī)器設(shè)置密碼
2.如果對集群設(shè)置密碼,那么requirepass和masterauth都需要設(shè)置,否則發(fā)生主從切換時,就會遇到授權(quán)問題,可以模擬并觀察日志
3.各個節(jié)點(diǎn)的密碼都必須一致,否則Redirected就會失敗
config set masterauth abc config set requirepass abc config rewrite
測試版本:
redis3.0.7
測試環(huán)境:
centos7
集群規(guī)模:
3主3從
集群構(gòu)建成功前的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
集群構(gòu)建成功后的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的從,現(xiàn)在要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已經(jīng)變成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
上述就是小編為大家分享的如何設(shè)置redis集群密碼了,如果剛好有類似的疑惑,不妨參照上述分析進(jìn)行理解。如果想知道更多相關(guān)知識,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。