【Redis】Cluster集群

来源:https://www.cnblogs.com/Janzen-q/archive/2023/04/21/17334253.html
-Advertisement-
Play Games

一、Redis Cluster 工作原理 在引入哨兵機制後,解決了Redis主從架構Master故障時的主從切換問題,保證了Redis服務可用性。但依舊無法解決單機節點出現的寫入性能瓶頸(網卡速率、單機記憶體容量、併發數量) 1、早期為解決單機性能瓶頸問題採用的解決方案: 1、客戶端分片:由客戶端程式 ...


一、Redis Cluster 工作原理

在引入哨兵機制後,解決了Redis主從架構Master故障時的主從切換問題,保證了Redis服務可用性。但依舊無法解決單機節點出現的寫入性能瓶頸(網卡速率、單機記憶體容量、併發數量)

1、早期為解決單機性能瓶頸問題採用的解決方案:

1、客戶端分片:由客戶端程式進行讀寫key的redis節點判斷和分配,並且由客戶端自行處理讀寫請求分配、高可用管理及故障轉移操作

2、proxy代理模式:引入第三方代理程式,客戶端通過連接proxy代理伺服器對數據進行讀寫,由proxy程式進行讀寫判斷分配,並對集群節點進行管理。但導致proxy又出現單點故障風險,並增加了一層數據處理環節

redis3.0 之後官方推出了無中心化的Cluster集群機制,集群中的每個節點單獨保持當前節點數據和集群狀態信息,每個節點需要和其餘全部節點保持連接。

2、Redis Cluster工作特點

1、Redis cluster集群中的各個節點之間(採用ping機制)進行互聯

2、集群中的某個節點失效,是有整個集群中超過半數的節點監測失效(sdown),才會真正判定為節點不可用(odown)

3、客戶端無需配置連接proxy即可直連redis,應用程式需配置集群的所有redis節點IP

4、redis cluster將集群中所有的節點平均映射到0-16383(16384個)slot槽位上,將資料庫的讀寫全部映射到對應的節點上操作,因此每增加n個集群主節點就能對redis進行n倍擴展,每個主節點將分擔16384/n個slot

5、redis cluster預先將16384個槽位分配至集群中的主節點,當接收到對redis的寫入請求時,會通過 CRC16(key)%16384 計算出當前key的所屬slot編號,從而將數據寫入到對應的主節點上,從而解決單機產生的性能瓶頸

3、Redis Cluster 架構設計

Redis Cluster 基本架構

 Redis Cluster 主從架構

為解決Cluster集群中各Master節點的高可用性,可採用Cluster主從架構部署,將部分加入集群的節點設置為Slave角色,從而解決Master節點的高可用性

Cluster可自行實現類似哨兵機制的每組Master-Slave的主從切換,無需額外配置哨兵機制。並且支持每組節點的 1-n 模式(不支持1-n-n)

 Redis Cluster 部署架構設計

  

3、Redis Cluster局限性

1、大多數時候客戶端連接性能會“降低”,由於cluster在讀寫數據時需要先進行solt計算並重定向訪問到對應節點上,造成了數據處理“延遲性”。

2、部分命令無法跨節點使用:mget、keys、scan、flush、sinter 等

3、客戶端維護複雜:SDK 和 應用自身消耗增加(更多的數據連接池)

4、不支持多資料庫:cluster 模式下僅支持使用db0

5、複製僅支持一層:不支持級聯複製

6、key事務、Lua 的支持有限:key操作必須在同一個節點上,事務和Lua無法跨節點使用

 

二、Redis Cluster 相關配置詳解

################################ REDIS CLUSTER  ###############################

# Normal Redis instances can't be part of a Redis Cluster; only nodes that are
# started as cluster nodes can. In order to start a Redis instance as a
# cluster node enable the cluster support uncommenting the following:
#
# cluster-enabled yes #啟用Cluster模式

# Every cluster node has a cluster configuration file. This file is not
# intended to be edited by hand. It is created and updated by Redis nodes.
# Every Redis Cluster node requires a different cluster configuration file.
# Make sure that instances running in the same system do not have
# overlapping cluster configuration file names.
#
# cluster-config-file nodes-6379.conf #Cluster節點配置文件名稱

# Cluster node timeout is the amount of milliseconds a node must be unreachable
# for it to be considered in failure state.
# Most other internal time limits are multiple of the node timeout.
#
# cluster-node-timeout 15000 #Cluster節點超時時間,單位:毫秒

# A replica of a failing master will avoid to start a failover if its data
# looks too old.
#
# There is no simple way for a replica to actually have an exact measure of
# its "data age", so the following two checks are performed:
#
# 1) If there are multiple replicas able to failover, they exchange messages
#    in order to try to give an advantage to the replica with the best
#    replication offset (more data from the master processed).
#    Replicas will try to get their rank by offset, and apply to the start
#    of the failover a delay proportional to their rank.
#
# 2) Every single replica computes the time of the last interaction with
#    its master. This can be the last ping or command received (if the master
#    is still in the "connected" state), or the time that elapsed since the
#    disconnection with the master (if the replication link is currently down).
#    If the last interaction is too old, the replica will not try to failover
#    at all.
#
# The point "2" can be tuned by user. Specifically a replica will not perform
# the failover if, since the last interaction with the master, the time
# elapsed is greater than:
#
#   (node-timeout * replica-validity-factor) + repl-ping-replica-period
#
# So for example if node-timeout is 30 seconds, and the replica-validity-factor
# is 10, and assuming a default repl-ping-replica-period of 10 seconds, the
# replica will not try to failover if it was not able to talk with the master
# for longer than 310 seconds.
#
# A large replica-validity-factor may allow replicas with too old data to failover
# a master, while a too small value may prevent the cluster from being able to
# elect a replica at all.
#
# For maximum availability, it is possible to set the replica-validity-factor
# to a value of 0, which means, that replicas will always try to failover the
# master regardless of the last time they interacted with the master.
# (However they'll always try to apply a delay proportional to their
# offset rank).
#
# Zero is the only value able to guarantee that when all the partitions heal
# the cluster will always be able to continue.
#
# cluster-replica-validity-factor 10
# 集群副本有效性因數(0表示slave將始終嘗試故障轉移為master,預設被註釋掉) # (node-timeout * replica-validity-factor) + repl-ping-replica-period # 計算時間(秒),如果slave無法與master通信的時間超過了該時間,則slave將不會嘗試故障轉移 # Cluster replicas are able to migrate to orphaned masters, that are masters # that are left without working replicas. This improves the cluster ability # to resist to failures as otherwise an orphaned master can't be failed over # in case of failure if it has no working replicas. # # Replicas migrate to orphaned masters only if there are still at least a # given number of other working replicas for their old master. This number # is the "migration barrier". A migration barrier of 1 means that a replica # will migrate only if there is at least 1 other working replica for its master # and so forth. It usually reflects the number of replicas you want for every # master in your cluster. # # Default is 1 (replicas migrate only if their masters remain with at least # one replica). To disable migration just set it to a very large value. # A value of 0 can be set but is useful only for debugging and dangerous # in production. # # cluster-migration-barrier 1 #集群遷移屏障,僅當master至少有1個其他工作副本時,副本才會遷移 # By default Redis Cluster nodes stop accepting queries if they detect there # is at least an hash slot uncovered (no available node is serving it). # This way if the cluster is partially down (for example a range of hash slots # are no longer covered) all the cluster becomes, eventually, unavailable. # It automatically returns available as soon as all the slots are covered again. # # However sometimes you want the subset of the cluster which is working, # to continue to accept queries for the part of the key space that is still # covered. In order to do so, just set the cluster-require-full-coverage # option to no. # # cluster-require-full-coverage yes # 集群需要全覆蓋(預設為 yes,被註釋掉) # 如果redis集群節點檢測到至少有一個未覆蓋的哈希槽(沒有可用的節點提供服務),則會停止接受查詢 # 如果集群部分關閉(例如不再覆蓋一系列哈希槽),整個集群將不可用 # 當所有插槽再次被覆蓋,集群將自動返回可用狀態 # This option, when set to yes, prevents replicas from trying to failover its # master during master failures. However the master can still perform a # manual failover, if forced to do so. # # This is useful in different scenarios, especially in the case of multiple # data center operations, where we want one side to never be promoted if not # in the case of a total DC failure. # # cluster-replica-no-failover no #主節點故障期間不啟用故障轉移 # In order to setup your cluster make sure to read the documentation # available at http://redis.io web site. ########################## CLUSTER DOCKER/NAT support ######################## # In certain deployments, Redis Cluster nodes address discovery fails, because # addresses are NAT-ted or because ports are forwarded (the typical case is # Docker and other containers). # # In order to make Redis Cluster working in such environments, a static # configuration where each node knows its public address is needed. The # following two options are used for this scope, and are: # # * cluster-announce-ip # * cluster-announce-port # * cluster-announce-bus-port # # Each instruct the node about its address, client port, and cluster message # bus port. The information is then published in the header of the bus packets # so that other nodes will be able to correctly map the address of the node # publishing the information. # # If the above options are not used, the normal Redis Cluster auto-detection # will be used instead. # # Note that when remapped, the bus port may not be at the fixed offset of # clients port + 10000, so you can specify any port and bus-port depending # on how they get remapped. If the bus-port is not set, a fixed offset of # 10000 will be used as usually. # # Example: # # cluster-announce-ip 10.1.1.5 # cluster-announce-port 6379 # cluster-announce-bus-port 6380
# 配置集群節點的公共地址(預設被註釋掉,使用redis群集自動檢測) # 節點的ip地址,客戶端埠,集群消息匯流排埠

 

三、Redis Cluster部署

0、基礎環境準備

所有redis節點採用相同硬體配置,相同密碼,清空所有數據

  IP 角色 slot
node1 10.0.0.20 M1 0-5460
node2 10.0.0.21 M2 5461-10922
node3 10.0.0.22 M3 10923-16383
node4 10.0.0.23 集群擴容縮容備用(M4)  
node5 10.0.0.30 S1  
node6 10.0.0.31 S2  
node7 10.0.0.32 S3  
node8 10.0.0.33 集群擴容縮容備用(S4)  

 

 

 

 

 

 

 

初始化安裝6台 redis服務,並啟用Cluster模式

[root@Redis-Ubuntu1804-node1:~]# apt install redis -y
[root@Redis-Ubuntu1804-node1:~]# sed -i.bak -e 's/bind 127.0.0.1/bind 0.0.0.0/' -e '/masterauth/a masterauth redis' -e '/# requirepass/a requirepass redis' -e '/# cluster-enabled yes/a cluster-enabled yes' -e '/# cluster-config-file/a cluster-config-file nodes-6379.conf' -e '/# cluster-require-full-coverage yes/a cluster-require-full-coverage yes' /etc/redis/redis.conf
[root@Redis-Ubuntu1804-node1:~]# systemctl restart redis
[root@Redis-Ubuntu1804-node1:~]# ss -ntl
State             Recv-Q             Send-Q                          Local Address:Port                           Peer Address:Port             
LISTEN            0                  128                             127.0.0.53%lo:53                                  0.0.0.0:*                
LISTEN            0                  128                                   0.0.0.0:22                                  0.0.0.0:*                
LISTEN            0                  128                                 127.0.0.1:6010                                0.0.0.0:*                
LISTEN            0                  128                                   0.0.0.0:16379                               0.0.0.0:*                
LISTEN            0                  128                                   0.0.0.0:6379                                0.0.0.0:*                
LISTEN            0                  128                                      [::]:22                                     [::]:*                
LISTEN            0                  128                                     [::1]:6010                                   [::]:*                
[root@Redis-Ubuntu1804-node1:~]# ps -ef | grep redis
redis      2098      1  0 01:38 ?        00:00:00 /usr/bin/redis-server 0.0.0.0:6379 [cluster]
root       2112   1236  0 01:39 pts/0    00:00:00 grep --color=auto redis
[root@Redis-Ubuntu1804-node1:~]# 

1、基本模式手動部署

基本步驟

1、各節點伺服器上安裝redis服務,啟用Cluster配置

2、通過meet 將節點添加至集群中

3、為各Master節點分配槽位 0~16383 ,必須全部分配完成,集群才可用

4、指定各節點主從關係

1.1、查看當前節點狀態信息

[root@Redis-Ubuntu1804-node1:~]# redis-cli -a redis -h 10.0.0.20 cluster nodes
98bb2740b622645ff51fd07bc994bb22e94feaaa :6379@16379 myself,master - 0 0 0 connected
[root@Redis-Ubuntu1804-node1:~]# 

 

1.2、將所有節點加入到當前集群中 

Cluster節點操作相關命令

1、加入節點:將 ip 和 port 所指定的節點添加到集群當中,讓它成為集群的一份子。

1)CLUSTER MEET <ip:port>

2、移除節點:

1)CLUSTER FORGET <node_id>

2)、redis-trib.rb del-node <ip> <port> <node_id>

3、設置主從節點:

CLUSTER REPLICATE <node_id> 將當前節點設置為 node_id 指定的節點的從節點。  

4、節點數據備份到硬碟:

CLUSTER SAVECONFIG 將節點的配置文件保存到硬碟裡面。 

[root@Redis-Ubuntu1804-node1:~]# redis-cli -a redis -h 10.0.0.20 cluster meet 10.0.0.20 6379
[root@Redis-Ubuntu1804-node1:~]# redis-cli -a redis -h 10.0.0.20 cluster meet 10.0.0.20 6379
OK
[root@Redis-Ubuntu1804-node1:~]# redis-cli -a redis -h 10.0.0.20 cluster meet 10.0.0.21 6379
OK
[root@Redis-Ubuntu1804-node1:~]# redis-cli -a redis -h 10.0.0.20 cluster meet 10.0.0.22 6379
OK
[root@Redis-Ubuntu1804-node1:~]# redis-cli -a redis -h 10.0.0.20 cluster meet 10.0.0.30 6379
OK
[root@Redis-Ubuntu1804-node1:~]# redis-cli -a redis -h 10.0.0.20 cluster meet 10.0.0.31 6379
OK
[root@Redis-Ubuntu1804-node1:~]# redis-cli -a redis -h 10.0.0.20 cluster meet 10.0.0.32 6379
OK
[root@Redis-Ubuntu1804-node1:~]# redis-cli -a redis -h 10.0.0.20 cluster nodes
98bb2740b622645ff51fd07bc994bb22e94feaaa 10.0.0.20:6379@16379 myself,master - 0 1681926433000 1 connected
9fe09d53d884c6c99c926a0e7213cf5386987ebf 10.0.0.32:6379@16379 master - 0 1681926434205 5 connected
55fd3a5d21e026b6503a89f1d88996b2a67c314a 10.0.0.31:6379@16379 master - 0 1681926435212 4 connected
6717c6b5a6170963ac251a1f14b0c600e917aa26 10.0.0.30:6379@16379 master - 0 1681926433000 3 connected
d9c17ded7fb139f9eb7fd41e476bb8e17c8b9bed 10.0.0.21:6379@16379 master - 0 1681926434000 0 connected
bdec3c92bcaa00c8ad1850cd477eb0a8f8a28aa2 10.0.0.22:6379@16379 master - 0 1681926433199 2 connected
[root@Redis-Ubuntu1804-node1:~]# 

 

1.3、查看當前集群信息

[root@Redis-Ubuntu1804-node1:~]# redis-cli -a redis -h 10.0.0.20 cluster info
cluster_state:fail
cluster_slots_assigned:0
cluster_slots_ok:0
cluster_slots_pfail:0
cluster_slots_fail:0
cluster_known_nodes:6
cluster_size:0
cluster_current_epoch:5
cluster_my_epoch:1
cluster_stats_messages_ping_sent:70
cluster_stats_messages_pong_sent:89
cluster_stats_messages_meet_sent:6
cluster_stats_messages_sent:165
cluster_stats_messages_ping_received:88
cluster_stats_messages_pong_received:76
cluster_stats_messages_meet_received:1
cluster_stats_messages_received:165
[root@Redis-Ubuntu1804-node1:~]# 

 

1.4、為集群節點分配槽位

Cluster 槽位相關命令
CLUSTER ADDSLOTS <slot> [slot ...] 將一個或多個槽(slot)指派(assign)給當前節點。

CLUSTER DELSLOTS <slot> [slot ...] 移除一個或多個槽對當前節點的指派。

CLUSTER FLUSHSLOTS 移除指派給當前節點的所有槽,讓當前節點變成一個沒有指派任何槽的節點。

CLUSTER SETSLOT <slot> NODE <node_id> 將槽 slot 指派給 node_id 指定的節點,如果槽已經指派給另一個節點,那麼先讓另一個節點刪除該槽>,然後再進行指派。

CLUSTER SETSLOT <slot> MIGRATING <node_id> 將本節點的槽 slot 遷移到 node_id 指定的節點中。

CLUSTER SETSLOT <slot> IMPORTING <node_id> 從 node_id 指定的節點中導入槽 slot 到本節點。

CLUSTER SETSLOT <slot> STABLE 取消對槽 slot 的導入(import)或者遷移(migrate)。 

使用命令 redis-cli -h <目標節點IP> -p <目標節點埠> -a <目標節點密碼> --no-auth-warning cluster addslots <要分配的槽位號> 進行槽位分配

[root@Client-Ubuntu-1804-250:~/script/redis]# cat add_slots.sh 
#!/bin/bash
#
#********************************************************************
#Author:                janzen
#Date:                  2023-04-20
#FileName:             add_slots.sh
#Description:          The test script
#Copyright (C):        2023 All rights reserved
#********************************************************************
host=$1
port=$2
start=$3
end=$4
passwd=redis

for slot in `seq $start $end`; do
    redis-cli -h $host -p $port -a $passwd --no-auth-warning cluster addslots $slot &&
    echo $slot add to node $host:$port
done
[root@Client-Ubuntu-1804-250:~/script/redis]# 
[root@Client-Ubuntu-1804-250:~/script/redis]# ./add_slots.sh 10.0.0.20 6379 0 5460 >> addslot.log
[root@Client-Ubuntu-1804-250:~/script/redis]# ./add_slots.sh 10.0.0.21 6379 5461 10922 >> addslot.log
[root@Client-Ubuntu-1804-250:~/script/redis]# ./add_slots.sh 10.0.0.22 6379 10923 16383 >> addslot.log

 

##查看當前集群信息,槽位已完成分配
[root@Redis-Ubuntu1804-node1:~]# redis-cli -a redis -h 10.0.0.20 cluster nodes 98bb2740b622645ff51fd07bc994bb22e94feaaa 10.0.0.20:6379@16379 myself,master - 0 1681929286000 1 connected 0-5460 55fd3a5d21e026b6503a89f1d88996b2a67c314a 10.0.0.31:6379@16379 master - 0 1681929287000 4 connected 9fe09d53d884c6c99c926a0e7213cf5386987ebf 10.0.0.32:6379@16379 master - 0 1681929287000 5 connected 6717c6b5a6170963ac251a1f14b0c600e917aa26 10.0.0.30:6379@16379 master - 0 1681929288247 3 connected d9c17ded7fb139f9eb7fd41e476bb8e17c8b9bed 10.0.0.21:6379@16379 master - 0 1681929286000 0 connected 5461-10922 bdec3c92bcaa00c8ad1850cd477eb0a8f8a28aa2 10.0.0.22:6379@16379 master - 0 1681929289256 2 connected 10923-16383 [root@Redis-Ubuntu1804-node1:~]#

1.5、創建 Master-Slave 主從關係

使用命令 redis-cli -h <從節點IP> -p <從節點埠> -a <從節點密碼> --no-auth-warning cluster replicate <主節點node id> 

[root@Redis-Ubuntu1804-node1:~]# redis-cli -a redis -h 10.0.0.30 cluster replicate 98bb2740b622645ff51fd07bc994bb22e94feaaa
OK

##觀察主節點上的replication信息
[root@Redis-Ubuntu1804-node1:~]# redis-cli -a redis -h 10.0.0.20 info Replication
# Replication
role:master
connected_slaves:1
slave0:ip=10.0.0.30,port=6379,state=online,offset=350,lag=1
master_replid:6a823070fcbc13b4f4eb7b5d13bf1d2f4625a1a2
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:350
second_repl_offset:-1
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:1
repl_backlog_histlen:350
[root@Redis-Ubuntu1804-node1:~]# redis-cli -a redis -h 10.0.0.20 cluster nodes
98bb2740b622645ff51fd07bc994bb22e94feaaa 10.0.0.20:6379@16379 myself,master - 0 1681929989000 1 connected 0-5460
55fd3a5d21e026b6503a89f1d88996b2a67c314a 10.0.0.31:6379@16379 master - 0 1681929992372 4 connected
9fe09d53d884c6c99c926a0e7213cf5386987ebf 10.0.0.32:6379@16379 master - 0 1681929991000 5 connected
6717c6b5a6170963ac251a1f14b0c600e917aa26 10.0.0.30:6379@16379 slave 98bb2740b622645ff51fd07bc994bb22e94feaaa 0 1681929992000 3 connected
d9c17ded7fb139f9eb7fd41e476bb8e17c8b9bed 10.0.0.21:6379@16379 master - 0 1681929989351 0 connected 5461-10922
bdec3c92bcaa00c8ad1850cd477eb0a8f8a28aa2 10.0.0.22:6379@16379 master - 0 1681929991364 2 connected 10923-16383

##觀察從節點上的replication信息
[root@Redis-Ubuntu1804-node1:~]# redis-cli -a redis -h 10.0.0.30 info Replication
# Replication
role:slave
master_host:10.0.0.20
master_port:6379
master_link_status:up
master_last_io_seconds_ago:0
master_sync_in_progress:0
slave_repl_offset:462
slave_priority:100
slave_read_only:1
connected_slaves:0
master_replid:6a823070fcbc13b4f4eb7b5d13bf1d2f4625a1a2
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:462
second_repl_offset:-1
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:1
repl_backlog_histlen:462
[root@Redis-Ubuntu1804-node1:~]# 

 

 繼續完成主從組配置

[root@Redis-Ubuntu1804-node1:~]# redis-cli -a redis -h 10.0.0.31 cluster replicate d9c17ded7fb139f9eb7fd41e476bb8e17c8b9bed
OK
[root@Redis-Ubuntu1804-node1:~]# redis-cli -a redis -h 10.0.0.32 cluster replicate bdec3c92bcaa00c8ad1850cd477eb0a8f8a28aa2
OK

##觀察集群節點狀態 [root@Redis
-Ubuntu1804-node1:~]# redis-cli -a redis -h 10.0.0.30 cluster nodes 9fe09d53d884c6c99c926a0e7213cf5386987ebf 10.0.0.32:6379@16379 slave bdec3c92bcaa00c8ad1850cd477eb0a8f8a28aa2 0 1681930655876 5 connected 98bb2740b622645ff51fd07bc994bb22e94feaaa 10.0.0.20:6379@16379 master - 0 1681930654870 1 connected 0-5460 55fd3a5d21e026b6503a89f1d88996b2a67c314a 10.0.0.31:6379@16379 slave d9c17ded7fb139f9eb7fd41e476bb8e17c8b9bed 0 1681930656886 4 connected bdec3c92bcaa00c8ad1850cd477eb0a8f8a28aa2 10.0.0.22:6379@16379 master - 0 1681930655000 2 connected 10923-16383 6717c6b5a6170963ac251a1f14b0c600e917aa26 10.0.0.30:6379@16379 myself,slave 98bb2740b622645ff51fd07bc994bb22e94feaaa 0 1681930654000 3 connected d9c17ded7fb139f9eb7fd41e476bb8e17c8b9bed 10.0.0.21:6379@16379 master - 0 1681930653863 0 connected 5461-10922

  

1.6、驗證Cluster集群訪問

[root@Redis-Ubuntu1804-node1:~]# redis-cli -c -a redis -h 10.0.0.20 set node1 10.0.0.20
OK
[root@Redis-Ubuntu1804-node1:~]# redis-cli -c -a redis -h 10.0.0.21 set node2 10.0.0.21
OK
[root@Redis-Ubuntu1804-node1:~]# redis-cli -c -a redis -h 10.0.0.22 set node3 10.0.0.22
OK
[root@Redis-Ubuntu1804-node1:~]# redis-cli -c -a redis -h 10.0.0.30 set node5 10.0.0.24
OK
[root@Redis-Ubuntu1804-node1:~]# 
[root@Redis-Ubuntu1804-node1:~]# redis-cli -c -a redis -h 10.0.0.31 get node1
"10.0.0.20"
[root@Redis-Ubuntu1804-node1:~]# redis-cli -c -a redis -h 10.0.0.31 get node2
"10.0.0.21"
[root@Redis-Ubuntu1804-node1:~]# redis-cli -c -a redis -h 10.0.0.21 get node6
"10.0.0.31"
[root@Redis-Ubuntu1804-node1:~]# 

 

 

2、基於 Redis 5 Cluster集群部署

--cluster 常用命令

[root@Redis-Ubuntu1804-node3:~]# redis-cli -a redis --cluster help
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
Cluster Manager Commands:
  create         host1:port1 ... hostN:portN    ##創建集群
                 --cluster-replicas <arg>    ##指定每個集群的slave節點數,通常為1
  check          host:port    ##檢查集群信息
                 --cluster-search-multiple-owners
  info           host:port    ##查看集群節點基本信息
  fix            host:port    ##修複集群
                 --cluster-search-multiple-owners
  reshard        host:port    ##線上熱機遷移指定的slots數據
                 --cluster-from <arg>
                 --cluster-to <arg>
                 --cluster-slots <arg>
                 --cluster-yes
                 --cluster-timeout <arg>
                 --cluster-pipeline <arg>
                 --cluster-replace
  rebalance      host:port    ##平衡集群線上節點的slots數量
                 --cluster-weight <node1=w1...nodeN=wN>
                 --cluster-use-empty-masters
                 --cluster-timeout <arg>
                 --cluster-simulate
                 --cluster-pipeline <arg>
                 --cluster-threshold <arg>
                 --cluster-replace
  add-node       new_host:new_port existing_host:existing_port    ##添加新的節點到集群中
                 --cluster-slave
                 --cluster-master-id <arg>
  del-node       host:port node_id    ##刪除集群中的節點
  call           host:port command arg arg .. arg    ##在集群上的所有節點執行命令
  set-timeout    host:port milliseconds    ##設置節點超時時間
  import         host:port    ##導入外部redis數據到當前集群
                 --cluster-from <arg>
                 --cluster-copy
                 --cluster-replace
  help           

For check, fix, reshard, del-node, set-timeout you can specify the host and port of any working node in the cluster.

 

2.0、基本環境準備

[root@Redis-Ubuntu1804-node4:~]# redis-cli -a redis --version
redis-cli 5.0.14
[root@Redis-Ubuntu1804-node4:~]# redis-cli -a redis --no-auth-warning cluster nodes
e603091426e2ce29629ca51fb5e7dafb2f0c9524 :6379@16379 myself,master - 0 0 0 connected
[root@Redis-Ubuntu1804-node4:~]# 

 

2.1、創建Cluster集群

[root@Redis-Ubuntu1804-node1:~]# redis-cli -a redis --cluster create 10.0.0.20:6379 10.0.0.21:6379 10.0.0.22:6379 10.0.0.30:6379 10.0.0.31:6379 10.0.0.32:6379 --cluster-replicas 1
Warning: Using a password with '	   

您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • 《Redis設計與實現》讀書筆記 簡單動態字元串 SDS的定義 結構: buf數組:用於保存字元串 len屬性:記錄SDS中保存字元串的長度 free屬性:記錄buf中未使用位元組數量 遵循C字元串以空字元串結尾的慣例,保存空字元串的位元組不計入長度 SDS與C字元串的區別 常數複雜度獲取字元串長度 因 ...
  • 4月20日,以“數實融合,韌性生長”為主題的袋鼠雲春季生長大會圓滿落幕。 在春季生長大會中,袋鼠雲帶來了數實融合趨勢下的最新行業沉澱、最佳實踐經驗和行業前瞻性的產品發佈。從大數據基礎軟體“數棧”、到低代碼數字孿生世界“易知微”,再到可觀測運維專家“雲掣”,為廣大用戶帶來了一場場精彩內容,共話數字未來 ...
  • 摘要:推送服務(Push Kit)是華為提供的消息推送平臺,建立了從雲端到終端的消息推送通道。通過集成推送服務,您可以向客戶端應用實時推送消息,讓應用更精準觸達用戶,是開發者提升用戶感知度和活躍度的一件利器。 本文分享自華為雲社區《無懼百萬級併發,GaussDB(for Cassandra)讓華為P ...
  • 環境: AlmaLinux release 9.1 MySQL Community Server Ver 8.0.33 Replication Manager v2.2.40 for MariaDB 10.x and MySQL 5.7 Series ProxySQL version 2.5.1-9 ...
  • 摘要:目前MetaERP已經覆蓋了華為公司100%的業務場景和80%的業務量。 本文分享自華為雲社區《強渡大渡河!華為雲GaussDB支撐華為MetaERP系統全面替換》,作者: 華為雲頭條。 近日,在“英雄強渡大渡河”MetaERP表彰會上,華為宣佈實現自主可控的MetaERP研發,並完成對舊ER ...
  • Redis集群是一種通過將多個Redis節點連接在一起以實現高可用性、數據分片和負載均衡的技術。它允許Redis在不同節點上同時提供服務,提高整體性能和可靠性。根據搭建的方式和集群的特性,Redis集群主要有三種模式:主從複製模式(Master-Slave)、哨兵模式(Sentinel)和Clust... ...
  • GreatSQL社區原創內容未經授權不得隨意使用,轉載請聯繫小編並註明來源。 GreatSQL是MySQL的國產分支版本,使用上與MySQL一致。 作者: 王權富貴 文章來源:GreatSQL社區投稿 背景概述 由於安裝資料庫時將MySQL的數據目錄放在了根目錄下,現在存儲空間不足,想通過mv將數據 ...
  • 一、主從Redis部署(docker) 首先,我準備了兩台linux,一臺準備當作master,ip是192.168.241.128,另一臺是當作slave,ip是192.168.241.129。 1. 安裝redis docker pull redis 2. 下載對應版本的redis.conf 可 ...
一周排行
    -Advertisement-
    Play Games
  • 移動開發(一):使用.NET MAUI開發第一個安卓APP 對於工作多年的C#程式員來說,近來想嘗試開發一款安卓APP,考慮了很久最終選擇使用.NET MAUI這個微軟官方的框架來嘗試體驗開發安卓APP,畢竟是使用Visual Studio開發工具,使用起來也比較的順手,結合微軟官方的教程進行了安卓 ...
  • 前言 QuestPDF 是一個開源 .NET 庫,用於生成 PDF 文檔。使用了C# Fluent API方式可簡化開發、減少錯誤並提高工作效率。利用它可以輕鬆生成 PDF 報告、發票、導出文件等。 項目介紹 QuestPDF 是一個革命性的開源 .NET 庫,它徹底改變了我們生成 PDF 文檔的方 ...
  • 項目地址 項目後端地址: https://github.com/ZyPLJ/ZYTteeHole 項目前端頁面地址: ZyPLJ/TreeHoleVue (github.com) https://github.com/ZyPLJ/TreeHoleVue 目前項目測試訪問地址: http://tree ...
  • 話不多說,直接開乾 一.下載 1.官方鏈接下載: https://www.microsoft.com/zh-cn/sql-server/sql-server-downloads 2.在下載目錄中找到下麵這個小的安裝包 SQL2022-SSEI-Dev.exe,運行開始下載SQL server; 二. ...
  • 前言 隨著物聯網(IoT)技術的迅猛發展,MQTT(消息隊列遙測傳輸)協議憑藉其輕量級和高效性,已成為眾多物聯網應用的首選通信標準。 MQTTnet 作為一個高性能的 .NET 開源庫,為 .NET 平臺上的 MQTT 客戶端與伺服器開發提供了強大的支持。 本文將全面介紹 MQTTnet 的核心功能 ...
  • Serilog支持多種接收器用於日誌存儲,增強器用於添加屬性,LogContext管理動態屬性,支持多種輸出格式包括純文本、JSON及ExpressionTemplate。還提供了自定義格式化選項,適用於不同需求。 ...
  • 目錄簡介獲取 HTML 文檔解析 HTML 文檔測試參考文章 簡介 動態內容網站使用 JavaScript 腳本動態檢索和渲染數據,爬取信息時需要模擬瀏覽器行為,否則獲取到的源碼基本是空的。 本文使用的爬取步驟如下: 使用 Selenium 獲取渲染後的 HTML 文檔 使用 HtmlAgility ...
  • 1.前言 什麼是熱更新 游戲或者軟體更新時,無需重新下載客戶端進行安裝,而是在應用程式啟動的情況下,在內部進行資源或者代碼更新 Unity目前常用熱更新解決方案 HybridCLR,Xlua,ILRuntime等 Unity目前常用資源管理解決方案 AssetBundles,Addressable, ...
  • 本文章主要是在C# ASP.NET Core Web API框架實現向手機發送驗證碼簡訊功能。這裡我選擇是一個互億無線簡訊驗證碼平臺,其實像阿裡雲,騰訊雲上面也可以。 首先我們先去 互億無線 https://www.ihuyi.com/api/sms.html 去註冊一個賬號 註冊完成賬號後,它會送 ...
  • 通過以下方式可以高效,並保證數據同步的可靠性 1.API設計 使用RESTful設計,確保API端點明確,並使用適當的HTTP方法(如POST用於創建,PUT用於更新)。 設計清晰的請求和響應模型,以確保客戶端能夠理解預期格式。 2.數據驗證 在伺服器端進行嚴格的數據驗證,確保接收到的數據符合預期格 ...