Redis cluster 叢集
##配置redis叢集需要至少6個redis節點
叢集至少3主3從才可以搭建,防止錯亂我們在redis 下建立一個資料夾cluster,裡面複製6份配置檔案,改名為redis1-redis6.conf
把每個配置檔案都修改以下共同點:
bind 10.233.19.36 (根據實際情況配置)
port 7001 (7001-7006)
daemonize yes(以守護程式執行)
pidfile /var/run/redis.pid (守護程式生成的檔案,以實際情況配置)
appendonly yes (開啟AOF日誌記錄Redis操作的持久化)
appendfilename "appendonly-7001.aof" (AOF檔名,配置埠為檔名便於檢視)
cluster-enabled yes (開啟叢集)
cluster-config-file nodes-7001.conf (節點資訊,已節點命名便於檢視)
cluster-node-timeout 15000 (節點響應超時時間)
以上為共同點每個節點不論主從都需要配置。
此外還需要注意,不要再為各個節點主動配置主從關係,否則啟動時會報錯。
因為主從關係要給redis叢集自己調節。
##啟動redis叢集
上面的配置完成之後,分別啟動6個redis例項。配置正確的情況下,都可以啟動成功。然後執行如下命令建立叢集:
注意,這裡使用的是ip:port
replicas
1 表示我們希望為叢集中的每個主節點建立一個從節點
因為配置檔案中設定了密碼所以建立叢集也需要加密碼引數 -a
[ERR] Node 10.233.19.36:6380 NOAUTH Authentication required.
[redis@weblogic-test bin]$ ./redis-cli --cluster create 10.233.19.36:6380 10.233.19.36:6381 10.233.19.36:6382 10.233.19.36:6383 10.233.19.36:6384 10.233.19.36:6385 --cluster-replicas 1 -a beijing
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
>>> Performing hash slots allocation on 6 nodes...
Master[0] -> Slots 0 - 5460
Master[1] -> Slots 5461 - 10922
Master[2] -> Slots 10923 - 16383
Adding replica 10.233.19.36:6383 to 10.233.19.36:6380
Adding replica 10.233.19.36:6384 to 10.233.19.36:6381
Adding replica 10.233.19.36:6385 to 10.233.19.36:6382
>>> Trying to optimize slaves allocation for anti-affinity
[WARNING] Some slaves are in the same host as their master
M: 369151e4f1bed1e3fcaf474025853bc72056542e 10.233.19.36:6380
slots:[0-5460] (5461 slots) master
M: 1f9314f13a22c2c68c609e98247bfe6d0714c75b 10.233.19.36:6381
slots:[5461-10922] (5462 slots) master
M: 41840a493fceef875b1a521d951090f9c99c7040 10.233.19.36:6382
slots:[10923-16383] (5461 slots) master
S: 438c5ecaf7501da25bfc0d2055445c036907ba61 10.233.19.36:6383
replicates 1f9314f13a22c2c68c609e98247bfe6d0714c75b
S: 9598769e90155aeb130a33980ac1a1c27b1609cc 10.233.19.36:6384
replicates 41840a493fceef875b1a521d951090f9c99c7040
S: b0d325e936ee5055648561302560d055d0bdb365 10.233.19.36:6385
replicates 369151e4f1bed1e3fcaf474025853bc72056542e
Can I set the above configuration? (type 'yes' to accept): yes
>>> Nodes configuration updated
>>> Assign a different config epoch to each node
>>> Sending CLUSTER MEET messages to join the cluster
Waiting for the cluster to join
..
>>> Performing Cluster Check (using node 10.233.19.36:6380)
M: 369151e4f1bed1e3fcaf474025853bc72056542e 10.233.19.36:6380
slots:[0-5460] (5461 slots) master
1 additional replica(s)
M: 1f9314f13a22c2c68c609e98247bfe6d0714c75b 10.233.19.36:6381
slots:[5461-10922] (5462 slots) master
1 additional replica(s)
S: 9598769e90155aeb130a33980ac1a1c27b1609cc 10.233.19.36:6384
slots: (0 slots) slave
replicates 41840a493fceef875b1a521d951090f9c99c7040
M: 41840a493fceef875b1a521d951090f9c99c7040 10.233.19.36:6382
slots:[10923-16383] (5461 slots) master
1 additional replica(s)
S: b0d325e936ee5055648561302560d055d0bdb365 10.233.19.36:6385
slots: (0 slots) slave
replicates 369151e4f1bed1e3fcaf474025853bc72056542e
S: 438c5ecaf7501da25bfc0d2055445c036907ba61 10.233.19.36:6383
slots: (0 slots) slave
replicates 1f9314f13a22c2c68c609e98247bfe6d0714c75b
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
執行成功之後,連線一臺redis,執行 cluster info 會看到類似如下資訊:
127.0.0.1:6380> cluster info
cluster_state:ok
cluster_slots_assigned:16384
cluster_slots_ok:16384
cluster_slots_pfail:0
cluster_slots_fail:0
cluster_known_nodes:6
cluster_size:3
cluster_current_epoch:6
cluster_my_epoch:1
cluster_stats_messages_ping_sent:190
cluster_stats_messages_pong_sent:181
cluster_stats_messages_sent:371
cluster_stats_messages_ping_received:176
cluster_stats_messages_pong_received:190
cluster_stats_messages_meet_received:5
cluster_stats_messages_received:371
我們可以看到cluster_state:ok,cluster_slots_ok:16384,cluster_size:3。
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/30327022/viewspace-2641161/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Redis Cluster(叢集)Redis
- 搭建redis cluster叢集Redis
- 認識Redis叢集——Redis ClusterRedis
- redis偽叢集配置Cluster叢集模式Redis模式
- Redis叢集 - cluster叢集、資料分片Redis
- Redis Cluster叢集模式部署Redis模式
- Docker Redis 5.0 叢集(cluster)搭建DockerRedis
- 玩轉Redis叢集之ClusterRedis
- 【Redis】Redis Cluster-叢集故障轉移Redis
- Redis-cluster叢集搭建部署Redis
- 搭建分散式 Redis Cluster 叢集與 Redis 入門分散式Redis
- Spring Boot整合Redis叢集(Cluster模式)Spring BootRedis模式
- redis cluster 叢集故障恢復操作思路Redis
- 在滴滴雲上搭建 Redis-Cluster 叢集Redis
- Redis Cluster 叢集搭建與擴容、縮容Redis
- Redis Cluster叢集知識學習總結Redis
- redis Cluster模式叢集 多機器 docker 部署Redis模式Docker
- Redis Cluster 叢集部署Redis
- 老司機帶你玩轉面試(5):Redis 叢集模式 Redis Cluster面試Redis模式
- 比Redis-cluster還好的redis分散式叢集(twemproxy代理)Redis分散式
- Node js 叢集(cluster)JS
- MySQL CLUSTER(叢集)系列MySql
- Redis Cluster高可用叢集線上遷移操作記錄Redis
- 部署Redis Cluster 6.0 叢集並開啟密碼認證 和 Redis-cluster-proxy負載Redis密碼負載
- Redis系列:搭建Redis叢集(叢集模式)Redis模式
- Redis Cluster 叢集解決方案Redis
- Redis 超詳細的手動搭建Cluster叢集步驟Redis
- Kubernetes(k8s)部署redis-cluster叢集K8SRedis
- redis 叢集Redis
- redis叢集Redis
- redis cluster 4.0.9 叢集安裝搭建Redis
- redis叢集搭建Redis
- redis系列:叢集Redis
- 搭建 Redis 叢集Redis
- Redis 叢集方法Redis
- Redis叢集方案Redis
- Redis 叢集方案Redis
- Redis-叢集Redis