背景:安装redis-5.0.5,使用redis-cli搭建Redis集群并进行分片扩缩容。
安装redis-5.0.5
1.从官网下载redis-5.0.5.tar.gz并上传到您的服务器。
2、上传redis-5.0.5.tar.gz到/usr/local/src目录。
[root@localhost src]# ll /usr/local/src/redis-5.0.5.tar.gz
-rw-r–r–。 1 root root 1975750 5月25日00:13 /usr/local/src/redis-5.0.5.tar.gz
3.解压redis-5.0.5.tar.gz。
[root@localhost src]# tar -zxf redis-5.0.5.tar.gz
4. 移动到解压目录并安装。默认情况下,redis相关的安装文件存放在/usr/local/bin目录下。如果想自定义安装路径,可以将make install替换为: make PREFIX=安装目录
[root@localhost src]# cd redis-5.0.5/
然后输入“make make install”进行编译安装。
[root@localhost redis-5.0.5]# make make install
…………
make[1]: 退出目录`/usr/local/src/redis-5.0.5/src\’
[root@localhost redis-5.0.5]#
5.检查Redis版本,可以看到Redis安装成功。
[root@localhost ~]# redis-server –version
Redis 服务器v=5.0.5 sha=00000000:0 malloc=jemalloc-5.1.0 位=64 build=e53c2b8a69fecf7d
创建redis实例
一个Redis集群默认至少需要3个master和3个slave,所以在生产中,分片master和slave不在同一台机器上。这也是分片的意义。由于这是一个简单的设置,我在一台机器上创建了6 个Redis 实例(我构建集群的机器的IP 地址为192.168.222.133)。
1. 我们将创建6 个Redis 实例,因此需要6 个端口。我们创建了六个目录来存储Redis 实例的数据和配置文件。最好在数据盘上创建数据目录。
[root@localhost ~]# mkdir /data/7000
[root@localhost ~]# mkdir /data/7001
[root@localhost ~]# mkdir /data/8000
[root@localhost ~]# mkdir /data/8001
[root@localhost ~]# mkdir /data/9000
[root@localhost ~]# mkdir /data/9001
2. 为您的Redis实例创建一个配置文件,将配置文件复制到其他五个目录中,并将文件名和文件内容中的ports替换为对应的ports。这些设置是简单的设置。如果需要添加其他参数,请自行添加。
[root@localhost 7000]# cat /data/7000/redis-7000.conf
# 更改为后台启动
守护进程,是的
揉捏
绑定192.168.222.133
# 更改端口号
端口7000
#指定数据文件的保存位置
目录/数据/7000/
# 启用集群模式
集群兼容是
# 集群节点超时
集群节点超时15000
# 关闭保护模式
保护模式无
# 启用aof模式持久化
仅添加是
# 设置连接Redis 123所需的密码(可选)
#需要通过123456
# 设置Redis节点之间访问所需的密码123(可选)
#大师认证123456
3. 复制并修改配置文件后,启动六个Redis实例。
[root@localhost ~]# redis-server /data/7000/redis-7000.conf
[root@localhost ~]# redis-server /data/7001/redis-7001.conf
[root@localhost ~]# redis-server /data/8000/redis-8000.conf
[root@localhost ~]# redis-server /data/8001/redis-8001.conf
[root@localhost ~]# redis-server /data/9000/redis-9000.conf
[root@localhost ~]# redis-server /data/9001/redis-9001.conf
4. 检查Redis实例的启动状态。您可以看到所有六个实例均运行正常。
[root@localhost ~]# ps grep redis |
根2887 0.1 0.1 163216 11776 ?SSL 23:42 0:00 redis 服务器192.168.222.133:7000 [集群]
根2892 0.2 0.1 154000 7684 ?SSL 23:42 0:00 redis 服务器192.168.222.133:7001 [集群]
根2911 0.1 0.1 154000 7684 ?SSL 23:43 0:00 redis 服务器192.168.222.133:8000 [集群]
根2920 0.1 0.1 154000 7684 ?SSL 23:43 0:00 redis 服务器192.168.222.133:8001 [集群]
根2929 0.1 0.1 154000 7684 ?SSL 23:43 0:00 redis 服务器192.168.222.133:9000 [集群]
根2938 0.1 0.1 154000 7684 ?SSL 23:43 0:00 redis 服务器192.168.222.133:9001 [集群]
搭建redis集群
1、搭建3主3从redis集群,6个redis实例。 使用以下命令构建redis集群:
构建集群命令: redis-cli –cluster create 192.168.222.133:7000 192.168.222.133:8000 192.168.222.133:9000 192.168.222.133:7001 .222.1 3 3:8001 192.168.222.133:9001 –集群副本1
#–cluster-replicas 1表示从库是一个实例
#这里你无法控制谁是master、谁是slave,但是如果你有3台机器,master和slave默认不会在一台机器上。
这是运行命令后的输出。可以看到集群已经搭建成功,并且已经分配了相应的槽位。
[root@localhost ~]# redis-cli –cluster 创建192.168.222.133:7000 192.168.222.133:8000 192.168.222.133:9000 192.168.222.133:7001 68.22 .133:8001 192.168.222.133:9001 –集群副本1
在6 个节点上执行哈希槽分配.
主[0] – 插槽0 – 5460
大师[1] – 插槽5461 – 10922
主站[2] – 插槽10923 至16383
将副本192.168.222.133:8001 添加到192.168.222.133:7000
将副本192.168.222.133:9001 添加到192.168.222.133:8000
将副本192.168.222.133:7001 添加到192.168.222.133:9000
我正在尝试优化从属分配以实现反亲和性
[警告] 某些从站与主站位于同一主机
M: 532617682328eee2853ed10f8e7bf5f5f900ab5f 192.168.222.133:7000
插槽:[0-5460](5461 个插槽)主
M: ad413b85bea8dffa4ed78286a483b0f078e76725 192.168.222.133:8000
插槽:[5461-10922](5462 个插槽)主
M: 7d138927259fd5a6847d27c56af05b6f727e379b 192.168.222.133:9000
插槽:[10923-16383](5461个插槽)主
S: e54654f032713280383077d5d677bf6702affcfc 192.168.222.133:7001
复制ad413b85bea8dffa4ed78286a483b0f078e76725
S: d6225c2e8b2e3b19f608c082b2d24a6c87b1c424 192.168.222.133:8001
重复7d138927259fd5a6847d27c56af05b6f727e379b
S: 0bbb8ba6dd94e0897b26e581d5a9f1bec4157759 192.168.222.133:9001
重复532617682328eee2853ed10f8e7bf5f5f900ab5f
可以配置以上配置吗?(输入yes 接受): 是
节点配置更新
为每个节点分配不同的配置纪元
发送CLUSTER MEET 消息加入集群
等待集群加入
……
运行集群检查(使用节点192.168.222.133:7000)
M: 532617682328eee2853ed10f8e7bf5f5f900ab5f 192.168.222.133:7000
插槽:[0-5460](5461 个插槽)主
1 个额外副本
S: e54654f032713280383077d5d677bf6702affcfc 192.168.222.133:7001
插槽:(0 个插槽)从站
复制ad413b85bea8dffa4ed78286a483b0f078e76725
S: d6225c2e8b2e3b19f608c082b2d24a6c87b1c424 192.168.222.133:8001
插槽:(0 个插槽)从站
重复7d138927259fd5a6847d27c56af05b6f727e379b
S: 0bbb8ba6dd94e0897b26e581d5a9f1bec4157759 192.168.222.133:9001
插槽:(0 个插槽)从站
重复532617682328eee2853ed10f8e7bf5f5f900ab5f
M: 7d138927259fd5a6847d27c56af05b6f727e379b 192.168.222.133:9000
插槽:[10923-16383](5461个插槽)主
1 个额外副本
M: ad413b85bea8dffa4ed78286a483b0f078e76725 192.168.222.133:8000
插槽:[5461-10922](5462 个插槽)主
1 个额外副本
[确定] 所有节点都同意插槽配置。
检查可用插槽.
查看我们的老虎机覆盖范围.
[确定] 所有16384 插槽均已覆盖。
[root@localhost ~]#
2. 进入任意节点,通过该redis节点查看您的Redis集群状态。可以看到我们已经成功搭建了一个3主3从的Redis集群。
[root@localhost ~]# redis-cli -c -h 192.168.222.133 -p 7000
192.168.222.133:7000 集群节点
532617682328eee2853ed10f8e7bf5f5f900ab5f 192.168.222.133:7000@17000 自、主- 0 1719071708000 1 已连接0-5460
e54654f032713280383077d5d677bf6702affcfc 192.168.222.133:7001@17001从ad413b85bea8dffa4ed78286a483b0f078e76725 0 1719071711069 4已连接
d6225c2e8b2e3b19f608c082b2d24a6c87b1c424 192.168.222.133:8001@18001 从机7d138927259fd5a6847d27c56af05b6f727e379b 0 17190 71 707964 5 已连接
0bbb8ba6dd94e0897b26e581d5a9f1bec4157759 192.168.222.133:9001@19001从532617682328eee2853ed10f8e7bf5f5f900ab5f 0 17190717080 00 6 已连接
7d138927259fd5a6847d27c56af05b6f727e379b 192.168.222.133:9000@19000 主站- 0 1719071710000 3 连接10923-16383
ad413b85bea8dffa4ed78286a483b0f078e76725 192.168.222.133:8000@18000 主站- 0 1719071710040 2 连接5461-10922
192.168.222.133:7000
redis集群缩容分片
1. 检查集群的状态。 我当前的Redis 集群有3 个主节点和3 个从节点,并分配了插槽。
[root@localhost ~]# redis-cli -c -h 192.168.222.133 -p 7000
192.168.222.133:7000 集群节点
532617682328eee2853ed10f8e7bf5f5f900ab5f 192.168.222.133:7000@17000 自、主- 0 1719071708000 1 已连接0-5460
e54654f032713280383077d5d677bf6702affcfc 192.168.222.133:7001@17001从ad413b85bea8dffa4ed78286a483b0f078e76725 0 1719071711069 4已连接
d6225c2e8b2e3b19f608c082b2d24a6c87b1c424 192.168.222.133:8001@18001 从机7d138927259fd5a6847d27c56af05b6f727e379b 0 17190 71 707964 5 已连接
0bbb8ba6dd94e0897b26e581d5a9f1bec4157759 192.168.222.133:9001@19001从532617682328eee2853ed10f8e7bf5f5f900ab5f 0 17190717080 0 0 6 已连接
7d138927259fd5a6847d27c56af05b6f727e379b 192.168.222.133:9000@19000 主站- 0 1719071710000 3 连接10923-16383
ad413b85bea8dffa4ed78286a483b0f078e76725 192.168.222.133:8000@18000 主站- 0 1719071710040 2 连接5461-10922
192.168.222.133:7000
2.准备收缩两个分片:master:192.168.222.133:9000和slave:192.168.222.133:8001。首先删除从机:192.168.222.133:8001
删除从节点命令:redis-cli –cluster del-node ip:port node-ip
这就是我正在做的:
[root@localhost ~]# redis-cli –cluster del-node 192.168.222.133:8001 d6225c2e8b2e3b19f608c082b2d24a6c87b1c424
从集群192.168.222.133:8001 中删除节点d6225c2e8b2e3b19f608c082b2d24a6c87b1c424
正在向集群发送CLUSTER FORGET 消息.
关闭节点。
[root@localhost ~]#
3、从节点删除成功后,需要删除master 192.168.222.133:9000。要删除主节点,必须先为其分配一个插槽,然后再将其删除。这里,master的slot: 192.168.222.133:9000分配如下: Master: 192.168.222.133:8000
重新分配,导入。
步骤1:redis-cli –cluster reshard应该删除节点IP:port
Step 2: 5461 #这表示9000端口负责5461槽位,所以输入5461。
步骤2:ad413b85bea8dffa4ed78286a483b0f078e76725 #在此输入您为其分配插槽的节点的节点ID。所以节点ID 为9000。
步骤3:7d138927259fd5a6847d27c56af05b6f727e379b #输入槽位中节点接受节点ID的人。所以这里我们的节点ID 为8000。
第4 步:完成#Type“Done”。这意味着开始分配。
第5步:是#类似确认
以下是分配给我的情况的步骤:
[root@localhost ~]# redis-cli –cluster reshard 192.168.222.133:9000
运行集群检查(使用节点192.168.222.133:9000)
M: 7d138927259fd5a6847d27c56af05b6f727e379b 192.168.222.133:9000
插槽:[10923-16383](5461个插槽)主
S: 0bbb8ba6dd94e0897b26e581d5a9f1bec4157759 192.168.222.133:9001
插槽:(0 个插槽)从站
重复532617682328eee2853ed10f8e7bf5f5f900ab5f
M: ad413b85bea8dffa4ed78286a483b0f078e76725 192.168.222.133:8000
插槽:[5461-10922](5462 个插槽)主
1 个额外副本
S: e54654f032713280383077d5d677bf6702affcfc 192.168.222.133:7001
插槽:(0 个插槽)从站
复制ad413b85bea8dffa4ed78286a483b0f078e76725
M: 532617682328eee2853ed10f8e7bf5f5f900ab5f 192.168.222.133:7000
插槽:[0-5460](5461 个插槽)主
1 个额外副本
[确定] 所有节点都同意插槽配置。
检查可用插槽.
查看我们的老虎机覆盖范围.
[确定] 所有16384 插槽均已覆盖。
要移动多少个插槽(1 到16384)?
接收节点ID是什么?
a4ed78286a483b0f078e76725
Please enter all the source node IDs.
Type \’all\’ to use all the nodes as source nodes for the hash slots.
Type \’done\’ once you entered all the source nodes IDs.
Source node #1: 7d138927259fd5a6847d27c56af05b6f727e379b
Source node #2: done
4、查看master: 192.168.222.133:9000的槽位确实已经分配给了:master: 192.168.222.133:8000
[root@localhost ~]# redis-cli -c -h 192.168.222.133 -p 7000
192.168.222.133:7000> cluster nodes
532617682328eee2853ed10f8e7bf5f5f900ab5f 192.168.222.133:7000@17000 myself,master – 0 1719073472000 1 connected 0-5460
e54654f032713280383077d5d677bf6702affcfc 192.168.222.133:7001@17001 slave ad413b85bea8dffa4ed78286a483b0f078e76725 0 1719073471990 7 connected
0bbb8ba6dd94e0897b26e581d5a9f1bec4157759 192.168.222.133:9001@19001 slave 532617682328eee2853ed10f8e7bf5f5f900ab5f 0 1719073474050 6 connected
7d138927259fd5a6847d27c56af05b6f727e379b 192.168.222.133:9000@19000 master – 0 1719073473018 3 connected
ad413b85bea8dffa4ed78286a483b0f078e76725 192.168.222.133:8000@18000 master – 0 1719073475076 7 connected 5461-16383
192.168.222.133:7000>
5、删除master: 192.168.222.133:9000节点。
[root@localhost ~]# redis-cli –cluster del-node 192.168.222.133:9000 7d138927259fd5a6847d27c56af05b6f727e379b
>>> Removing node 7d138927259fd5a6847d27c56af05b6f727e379b from cluster 192.168.222.133:9000
>>> Sending CLUSTER FORGET messages to the cluster…
>>> SHUTDOWN the node.
[root@localhost ~]#
6、查看整个集群的状态,可以看到master:192.168.222.133:9000,slave:192.168.222.133:8001这两个分片已经缩容掉,而且槽位也已经由 192.168.222.133:8000负责。
[root@localhost ~]# redis-cli -c -h 192.168.222.133 -p 7000
192.168.222.133:7000> cluster nodes
532617682328eee2853ed10f8e7bf5f5f900ab5f 192.168.222.133:7000@17000 myself,master – 0 1719073654000 1 connected 0-5460
e54654f032713280383077d5d677bf6702affcfc 192.168.222.133:7001@17001 slave ad413b85bea8dffa4ed78286a483b0f078e76725 0 1719073656652 7 connected
0bbb8ba6dd94e0897b26e581d5a9f1bec4157759 192.168.222.133:9001@19001 slave 532617682328eee2853ed10f8e7bf5f5f900ab5f 0 1719073654568 6 connected
ad413b85bea8dffa4ed78286a483b0f078e76725 192.168.222.133:8000@18000 master – 0 1719073655614 7 connected 5461-16383
192.168.222.133:7000>
redis集群扩容分片
1、查看集群情况,目前redis集群是2主2从,并且都已经分配了槽位。
[root@localhost ~]# redis-cli -c -h 192.168.222.133 -p 7000
192.168.222.133:7000> cluster nodes
532617682328eee2853ed10f8e7bf5f5f900ab5f 192.168.222.133:7000@17000 myself,master – 0 1719073654000 1 connected 0-5460
e54654f032713280383077d5d677bf6702affcfc 192.168.222.133:7001@17001 slave ad413b85bea8dffa4ed78286a483b0f078e76725 0 1719073656652 7 connected
0bbb8ba6dd94e0897b26e581d5a9f1bec4157759 192.168.222.133:9001@19001 slave 532617682328eee2853ed10f8e7bf5f5f900ab5f 0 1719073654568 6 connected
ad413b85bea8dffa4ed78286a483b0f078e76725 192.168.222.133:8000@18000 master – 0 1719073655614 7 connected 5461-16383
192.168.222.133:7000>
2、准备两个redis实例为192.168.222.133:9000,192.168.222.133:8001,并将这两个分片到集群中,期望将192.168.222.133:9000设置为master,192.168.222.133:8001设置为slave。先将192.168.222.133:9000加入集群中:
将节点加入集群的命令:redis-cli –cluster add-node <新加入节点的IP:port> <已经在集群中的任意节点IP:port>
我这里执行的情况,可以看到加入成功:
[root@localhost 8001]# redis-cli –cluster add-node 192.168.222.133:9000 192.168.222.133:7000
>>> Adding node 192.168.222.133:9000 to cluster 192.168.222.133:7000
>>> Performing Cluster Check (using node 192.168.222.133:7000)
M: 532617682328eee2853ed10f8e7bf5f5f900ab5f 192.168.222.133:7000
slots:[0-5460] (5461 slots) master
1 additional replica(s)
S: e54654f032713280383077d5d677bf6702affcfc 192.168.222.133:7001
slots: (0 slots) slave
replicates ad413b85bea8dffa4ed78286a483b0f078e76725
S: 0bbb8ba6dd94e0897b26e581d5a9f1bec4157759 192.168.222.133:9001
slots: (0 slots) slave
replicates 532617682328eee2853ed10f8e7bf5f5f900ab5f
M: ad413b85bea8dffa4ed78286a483b0f078e76725 192.168.222.133:8000
slots:[5461-16383] (10923 slots) master
1 additional replica(s)
[OK] All nodes agree about slots configuration.
>>> Check for open slots…
>>> Check slots coverage…
[OK] All 16384 slots covered.
>>> Send CLUSTER MEET to node 192.168.222.133:9000 to make it join the cluster.
[OK] New node added correctly.
3、可以看到192.168.222.133:9000加入了集群,但是没有槽位。
[root@localhost 8001]# redis-cli -c -h 192.168.222.133 -p 7000
192.168.222.133:7000> cluster nodes
532617682328eee2853ed10f8e7bf5f5f900ab5f 192.168.222.133:7000@17000 myself,master – 0 1719074087000 1 connected 0-5460
e54654f032713280383077d5d677bf6702affcfc 192.168.222.133:7001@17001 slave ad413b85bea8dffa4ed78286a483b0f078e76725 0 1719074089116 7 connected
0bbb8ba6dd94e0897b26e581d5a9f1bec4157759 192.168.222.133:9001@19001 slave 532617682328eee2853ed10f8e7bf5f5f900ab5f 0 1719074087021 6 connected
3cd072d1e134af85e80858993b498958279e321f 192.168.222.133:9000@19000 master – 0 1719074088000 0 connected
ad413b85bea8dffa4ed78286a483b0f078e76725 192.168.222.133:8000@18000 master – 0 1719074089000 7 connected 5461-16383
192.168.222.133:7000>
4、分配槽位给192.168.222.133:9000节点。这里将master:192.168.222.133:8000的5641个端口分配给192.168.222.133:9000
重新分配,输入:
步骤1:redis-cli –cluster reshard <需要新分配槽位的节点IP:port>
步骤2: 5461 #这里表示需要挪动槽位数量,所以输入5461
步骤2:3cd072d1e134af85e80858993b498958279e321f #这里填谁来接受槽位的节点node-id,所以这里是9000的node-id
步骤3:ad413b85bea8dffa4ed78286a483b0f078e76725 #这里填谁分配出槽位的节点node-id,所以里这是8000的node-id
步骤4:done #输入done,可以理解为开始分配
步骤5:yes #类似确认
以下是我分配的情况,输入的步骤:
[root@localhost 8001]# redis-cli –cluster reshard 192.168.222.133:9000
>>> Performing Cluster Check (using node 192.168.222.133:9000)
M: 3cd072d1e134af85e80858993b498958279e321f 192.168.222.133:9000
slots: (0 slots) master
M: ad413b85bea8dffa4ed78286a483b0f078e76725 192.168.222.133:8000
slots:[5461-16383] (10923 slots) master
1 additional replica(s)
S: e54654f032713280383077d5d677bf6702affcfc 192.168.222.133:7001
slots: (0 slots) slave
replicates ad413b85bea8dffa4ed78286a483b0f078e76725
M: 532617682328eee2853ed10f8e7bf5f5f900ab5f 192.168.222.133:7000
slots:[0-5460] (5461 slots) master
1 additional replica(s)
S: 0bbb8ba6dd94e0897b26e581d5a9f1bec4157759 192.168.222.133:9001
slots: (0 slots) slave
replicates 532617682328eee2853ed10f8e7bf5f5f900ab5f
[OK] All nodes agree about slots configuration.
>>> Check for open slots…
>>> Check slots coverage…
[OK] All 16384 slots covered.
How many slots do you want to move (from 1 to 16384)? 5641
What is the receiving node ID? 3cd072d1e134af85e80858993b498958279e321f
Please enter all the source node IDs.
Type \’all\’ to use all the nodes as source nodes for the hash slots.
Type \’done\’ once you entered all the source nodes IDs.
Source node #1: ad413b85bea8dffa4ed78286a483b0f078e76725
Source node #2: done
5、可以看到槽位已经分配成功。
[root@localhost 8001]# redis-cli -c -h 192.168.222.133 -p 7000
192.168.222.133:7000> cluster nodes
532617682328eee2853ed10f8e7bf5f5f900ab5f 192.168.222.133:7000@17000 myself,master – 0 1719074539000 1 connected 0-5460
e54654f032713280383077d5d677bf6702affcfc 192.168.222.133:7001@17001 slave ad413b85bea8dffa4ed78286a483b0f078e76725 0 1719074540000 7 connected
0bbb8ba6dd94e0897b26e581d5a9f1bec4157759 192.168.222.133:9001@19001 slave 532617682328eee2853ed10f8e7bf5f5f900ab5f 0 1719074540722 6 connected
3cd072d1e134af85e80858993b498958279e321f 192.168.222.133:9000@19000 master – 0 1719074537000 8 connected 5461-11101
ad413b85bea8dffa4ed78286a483b0f078e76725 192.168.222.133:8000@18000 master – 0 1719074539000 7 connected 11102-16383
6、给master:192.168.222.133:9000 添加slave:192.168.222.133:8001
给master加slave的命令:redis-cli –cluster add-node <slave节点ip:port> <master节点ip:port> –cluster-slave <master节点的nodes-id>
以下是我执行的情况,执行成功:
[root@localhost 8001]# redis-cli –cluster add-node 192.168.222.133:8001 192.168.222.133:9000 –cluster-slave –cluster-master-id 3cd072d1e134af85e80858993b498958279e321f
>>> Adding node 192.168.222.133:8001 to cluster 192.168.222.133:9000
>>> Performing Cluster Check (using node 192.168.222.133:9000)
M: 3cd072d1e134af85e80858993b498958279e321f 192.168.222.133:9000
slots:[5461-11101] (5641 slots) master
M: ad413b85bea8dffa4ed78286a483b0f078e76725 192.168.222.133:8000
slots:[11102-16383] (5282 slots) master
1 additional replica(s)
S: e54654f032713280383077d5d677bf6702affcfc 192.168.222.133:7001
slots: (0 slots) slave
replicates ad413b85bea8dffa4ed78286a483b0f078e76725
M: 532617682328eee2853ed10f8e7bf5f5f900ab5f 192.168.222.133:7000
slots:[0-5460] (5461 slots) master
1 additional replica(s)
S: 0bbb8ba6dd94e0897b26e581d5a9f1bec4157759 192.168.222.133:9001
slots: (0 slots) slave
replicates 532617682328eee2853ed10f8e7bf5f5f900ab5f
[OK] All nodes agree about slots configuration.
>>> Check for open slots…
>>> Check slots coverage…
[OK] All 16384 slots covered.
>>> Send CLUSTER MEET to node 192.168.222.133:8001 to make it join the cluster.
Waiting for the cluster to join
>>> Configure node as replica of 192.168.222.133:9000.
[OK] New node added correctly.
7、可以看到集群扩容成功,且槽位也分配完成。
[root@localhost 8001]# redis-cli -c -h 192.168.222.133 -p 7000
192.168.222.133:7000> cluster nodes
532617682328eee2853ed10f8e7bf5f5f900ab5f 192.168.222.133:7000@17000 myself,master – 0 1719075042000 1 connected 0-5460
f865c91682b0db91298601755150d7fcc8af5e94 192.168.222.133:8001@18001 slave 3cd072d1e134af85e80858993b498958279e321f 0 1719075045399 8 connected
e54654f032713280383077d5d677bf6702affcfc 192.168.222.133:7001@17001 slave ad413b85bea8dffa4ed78286a483b0f078e76725 0 1719075043342 7 connected
0bbb8ba6dd94e0897b26e581d5a9f1bec4157759 192.168.222.133:9001@19001 slave 532617682328eee2853ed10f8e7bf5f5f900ab5f 0 1719075044364 6 connected
3cd072d1e134af85e80858993b498958279e321f 192.168.222.133:9000@19000 master – 0 1719075043000 8 connected 5461-11101
ad413b85bea8dffa4ed78286a483b0f078e76725 192.168.222.133:8000@18000 master – 0 1719075041000 7 connected 11102-16383
192.168.222.133:7000>
以上就是redis搭建集群、扩缩容分片。
#以上关于redis的相关内容来源网络仅供参考,相关信息请以官方公告为准!
原创文章,作者:CSDN,如若转载,请注明出处:https://www.sudun.com/ask/91747.html