主頁 > 知識庫 > 基于redis集群設(shè)置密碼的實例

基于redis集群設(shè)置密碼的實例

熱門標(biāo)簽:地圖標(biāo)注費用 小紅書怎么地圖標(biāo)注店 百度商家地圖標(biāo)注怎么做 西藏教育智能外呼系統(tǒng)價格 竹間科技AI電銷機器人 太原營銷外呼系統(tǒng) 地圖標(biāo)注如何即時生效 最簡單的百度地圖標(biāo)注 玄武湖地圖標(biāo)注

注意事項:

1.如果是使用redis-trib.rb工具構(gòu)建集群,集群構(gòu)建完成前不要配置密碼,集群構(gòu)建完畢再通過config set + config rewrite命令逐個機器設(shè)置密碼

2.如果對集群設(shè)置密碼,那么requirepass和masterauth都需要設(shè)置,否則發(fā)生主從切換時,就會遇到授權(quán)問題,可以模擬并觀察日志

3.各個節(jié)點的密碼都必須一致,否則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

4.簡單測試了GET SET命令,正常

以上這篇基于redis集群設(shè)置密碼的實例就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。

您可能感興趣的文章:
  • 解決Redis設(shè)置密碼重啟后失效的問題
  • Redis設(shè)置密碼保護的實例講解
  • Redis 密碼設(shè)置和查看密碼的方法
  • Linux下Redis設(shè)置密碼及開機自啟動
  • redis密碼設(shè)置、訪問權(quán)限控制等安全設(shè)置
  • Redis密碼設(shè)置與訪問限制實現(xiàn)方法

標(biāo)簽:唐山 廣東 林芝 澳門 香港 景德鎮(zhèn) 揚州 贛州

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《基于redis集群設(shè)置密碼的實例》,本文關(guān)鍵詞  基于,redis,集群,設(shè)置,密碼,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《基于redis集群設(shè)置密碼的實例》相關(guān)的同類信息!
  • 本頁收集關(guān)于基于redis集群設(shè)置密碼的實例的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章