安装redis集群

2022-01-15 625点热度 0人点赞 0条评论

参考博文

  1. redis集群搭建(非常详细,适合新手)
  2. redis集群扩容(添加新节点)

安装环境

使用腾讯云的轻应用服务器,操作系统为centos,新建用户aiuyo,home目录为:/home/aiuyo,redis直接放在home目录下,即:/home/aiuyo/redis

下载redis

直接在redis官网下载最新版本,如我下载的是redis-6.2.6,下载链接是:
https://download.redis.io/releases/redis-6.2.6.tar.gz

下载完成之后使用如下命令解压,获取解压目录redis-6.2.6,并重命名为redis:

tar xzvf redis-6.2.6.tar.gz
mv redis-6.2.6 redis

编译安装

编译安装需要系统中存在gcc,即具备c程序编译环境,因此root用户安装gcc

yum install gcc

切换回aiuyo用户,执行以下命令:

make && make install

编译的时候出现错误:

zmalloc.h:50:10: fatal error: jemalloc/jemalloc.h: No such file or directory
 #include <jemalloc/jemalloc.h>
          ^~~~~~~~~~~~~~~~~~~~~
compilation terminated.

解决方法参考博文Redis安装报错error:jemalloc/jemalloc.h:No such file or directory解决方法

Redis在安装时关于内存分配器allocator, 如果指定了MALLOC这个环境变量,那么会用这个环境变量的去建立Redis。如果没有,那么就是用默认的分配器

Redis 2.4版本之后,默认使用jemalloc来做内存管理,因为jemalloc被证明解决fragmentation problems(内存碎片化问题)比libc更好。但是如果你又没有jemalloc而只有libc,当make出错时,你可以加这么一个参数即可。

make MALLOC=libc

如果想用jemalloc,安装jemalloc即可。如果使用yum安装的话需要安装EPEL源。由于我已经安装了EPEL源,因此直接安装,切换回root,运行以下命令:

yum install jemalloc

然后再切换回aiuyo用户,再编译redis的时候指定MALLOC,如下::

make MALLOC=/usr/local/jemalloc/lib
make install

当Redis进程跑起来之后,在你的实例中使用info命令可以查看你所使用的内存管理器。

mem_allocator:jemalloc-4.2.1

如果你使用的是libc,那么mem_allocator的参数就会是libc。

运行make install之后,输出如下:

make install
cd src && make install
make[1]: Entering directory '/home/aiuyo/redis/src'

Hint: It's a good idea to run 'make test' ;)

    INSTALL redis-server
install: cannot remove '/usr/local/bin/redis-server': Permission denied
make[1]: *** [Makefile:435: install] Error 1
make[1]: Leaving directory '/home/aiuyo/redis/src'
make: *** [Makefile:9: install] Error 2

报错没有关系,因为不是root用户,无法把redis-server复制到/usr/local/bin/redis-server,这时redis-server已经在src目录了,我们只需要用src目录下的redis-server就行了。

安装集群

准备安装6个节点,3主3从,然后再添加2个节点,1主1从,总共8个节点,4主4从

添加集群配置文件

在redis目录下新建cluster目录,复制redis目录下的redis.conf到cluster并重命名为3261.conf-3266.conf,节点分别使用3261-3266端口。

修改节点配置

以3261.conf为例,修改的配置内容如下:

# redis后台运行
daemonize yes
# 监听所有设备端口
# IF YOU ARE SURE YOU WANT YOUR INSTANCE TO LISTEN TO ALL THE INTERFACES
# JUST COMMENT OUT THE FOLLOWING LINE.
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#bind 127.0.0.1 -::1
# 数据存放目录
dir /home/aiuyo/redis/data/3261
# 进程文件
pidfile /home/aiuyo/redis/cluster/3601.pid
# 日志文件
logfile /home/aiuyo/redis/log/3601.log
# 端口号
port 3261
# 开启集群模式,把注释#去掉
cluster-enabled yes
# 集群的配置,配置文件首次启动自动生成
cluster-config-file /home/aiuyo/redis/cluster/conf/3601.conf
# 请求超时,设置10秒
cluster-node-timeout 15000
# aof日志开启,有需要就开启,它会每次写操作都记录一条日志
appendonly yes
# 设置保护模式为关闭
protected-mode no

补充需要新建的目录:在redis目录下新建数据目录data,在data下进件目录3261-3266,在cluster目录下新建conf目录,在redis目录下新建目录log。

其他节点配置只需要把3261修改成其他端口即可。

设置保护模式为关闭的原因说明如下:
由于我是在云服务器上部署的,无法直接绑定公网IP,即按照如下这么配置:

bind 49.235.119.106 3261

配置文件注释掉了绑定配置,redis默认启用保护模式,解决方式官方给出了如下几种:

Redis is running in protected mode because protected mode is enabled, no bind address was specified, no authentication password is requested to clients. In this mode connections are only accepted from the loopback interface. If you want to connect from external computers to Redis you may adopt one of the following solutions:
1) Just disable protected mode sending the command 'CONFIG SET protected-mode no' from the loopback interface by connecting to Redis from the same host the server is running, however MAKE SURE Redis is not publicly accessible from internet if you do so. Use CONFIG REWRITE to make this change permanent. 
2) Alternatively you can just disable the protected mode by editing the Redis configuration file, and setting the protected mode option to 'no', and then restarting the server. 
3) If you started the server manually just for testing, restart it with the '--protected-mode no' option. 
4) Setup a bind address or an authentication password. NOTE: You only need to do one of the above things in order for the server to start accepting connections from the outside.

启动实例

切换到/home/aiuyo/redis目录,运行以下命令:

./src/redis-server cluster/3261.conf;
./src/redis-server cluster/3262.conf;
./src/redis-server cluster/3263.conf;
./src/redis-server cluster/3264.conf;
./src/redis-server cluster/3265.conf;
./src/redis-server cluster/3266.conf;

可以通过以下命令查看进程是否启动

ps -ef|grep redis|grep cluster
aiuyo    1180684       1  0 07:51 ?        00:00:00 ./src/redis-server *:3261 [cluster]
aiuyo    1180733       1  0 07:51 ?        00:00:00 ./src/redis-server *:3262 [cluster]
aiuyo    1180778       1  0 07:51 ?        00:00:00 ./src/redis-server *:3263 [cluster]
aiuyo    1180794       1  0 07:51 ?        00:00:00 ./src/redis-server *:3264 [cluster]
aiuyo    1180805       1  0 07:51 ?        00:00:00 ./src/redis-server *:3265 [cluster]
aiuyo    1180822       1  0 07:51 ?        00:00:00 ./src/redis-server *:3266 [cluster]

查看其中一个节点日志,如下代表启动正常:

1180822:C 17 Jan 2022 07:51:44.656 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
1180822:C 17 Jan 2022 07:51:44.656 # Redis version=6.2.6, bits=64, commit=00000000, modified=0, pid=1180822, just started
1180822:C 17 Jan 2022 07:51:44.656 # Configuration loaded
1180822:M 17 Jan 2022 07:51:44.657 * monotonic clock: POSIX clock_gettime
1180822:M 17 Jan 2022 07:51:44.658 * No cluster configuration found, I'm 62cb53e25ac3880b74b271acd311b9e93b16255c
1180822:M 17 Jan 2022 07:51:44.662 * Running mode=cluster, port=3266.
1180822:M 17 Jan 2022 07:51:44.662 # Server initialized
1180822:M 17 Jan 2022 07:51:44.662 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
1180822:M 17 Jan 2022 07:51:44.662 * Ready to accept connections

有一些警告,暂且忽略,也可以根据提示修改系统参数。

启动集群

使用如下命令创建集群:

src/redis-cli --cluster create 49.235.119.106:3261 49.235.119.106:3262 49.235.119.106:3263  49.235.119.106:3264  49.235.119.106:3265  49.235.119.106:3266  --cluster-replicas 1

输出如下:

$ src/redis-cli --cluster create 49.235.119.106:3261 49.235.119.106:3262 49.235.119.106:3263  49.235.119.106:3264  49.235.119.106:3265  49.235.119.106:3266  --cluster-replicas 1
>>> Performing hash slots allocation on 6 nodes...
Master[0] -> Slots 0 - 5460
Master[1] -> Slots 5461 - 10922
Master[2] -> Slots 10923 - 16383
Adding replica 49.235.119.106:3265 to 49.235.119.106:3261
Adding replica 49.235.119.106:3266 to 49.235.119.106:3262
Adding replica 49.235.119.106:3264 to 49.235.119.106:3263
>>> Trying to optimize slaves allocation for anti-affinity
[WARNING] Some slaves are in the same host as their master
M: 7a9290eb02cb6c980e015b46784f2e5589a67658 49.235.119.106:3261
   slots:[0-5460] (5461 slots) master
M: 4f4c762762f27da16ae122083c0247dc9caf8454 49.235.119.106:3262
   slots:[5461-10922] (5462 slots) master
M: 1d15cb3c53dbb7075663919d023cb4751bc60ae2 49.235.119.106:3263
   slots:[10923-16383] (5461 slots) master
S: 1a4c9a538ee0b245ed2372a66b22416b714f1a74 49.235.119.106:3264
   replicates 1d15cb3c53dbb7075663919d023cb4751bc60ae2
S: 437dd81e8a41eaa6fdd222cf04a4ea412fbeff5c 49.235.119.106:3265
   replicates 7a9290eb02cb6c980e015b46784f2e5589a67658
S: 62cb53e25ac3880b74b271acd311b9e93b16255c 49.235.119.106:3266
   replicates 4f4c762762f27da16ae122083c0247dc9caf8454
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 49.235.119.106:3261)
M: 7a9290eb02cb6c980e015b46784f2e5589a67658 49.235.119.106:3261
   slots:[0-5460] (5461 slots) master
   1 additional replica(s)
S: 62cb53e25ac3880b74b271acd311b9e93b16255c 49.235.119.106:3266
   slots: (0 slots) slave
   replicates 4f4c762762f27da16ae122083c0247dc9caf8454
S: 1a4c9a538ee0b245ed2372a66b22416b714f1a74 49.235.119.106:3264
   slots: (0 slots) slave
   replicates 1d15cb3c53dbb7075663919d023cb4751bc60ae2
M: 4f4c762762f27da16ae122083c0247dc9caf8454 49.235.119.106:3262
   slots:[5461-10922] (5462 slots) master
   1 additional replica(s)
M: 1d15cb3c53dbb7075663919d023cb4751bc60ae2 49.235.119.106:3263
   slots:[10923-16383] (5461 slots) master
   1 additional replica(s)
S: 437dd81e8a41eaa6fdd222cf04a4ea412fbeff5c 49.235.119.106:3265
   slots: (0 slots) slave
   replicates 7a9290eb02cb6c980e015b46784f2e5589a67658
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

此命令会自动选定主、从节点,并把16384个槽自动分配到3个主节点上。
这样,redis集群启动建完成了。

验证集群

连接任意一个客户端即可:
cluster info(查看集群信息)、cluster nodes(查看节点列表)

$ src/redis-cli -c -h 49.235.119.106 -p 3266
49.235.119.106:3266> 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:2
cluster_stats_messages_ping_sent:363
cluster_stats_messages_pong_sent:380
cluster_stats_messages_meet_sent:1
cluster_stats_messages_sent:744
cluster_stats_messages_ping_received:380
cluster_stats_messages_pong_received:364
cluster_stats_messages_received:744
49.235.119.106:3266> cluster nodes
437dd81e8a41eaa6fdd222cf04a4ea412fbeff5c 49.235.119.106:3265@13265 slave 7a9290eb02cb6c980e015b46784f2e5589a67658 0 1642407833000 1 connected
62cb53e25ac3880b74b271acd311b9e93b16255c 10.0.4.3:3266@13266 myself,slave 4f4c762762f27da16ae122083c0247dc9caf8454 0 1642407832000 2 connected
1d15cb3c53dbb7075663919d023cb4751bc60ae2 49.235.119.106:3263@13263 master - 0 1642407833019 3 connected 10923-16383
4f4c762762f27da16ae122083c0247dc9caf8454 49.235.119.106:3262@13262 master - 0 1642407835024 2 connected 5461-10922
7a9290eb02cb6c980e015b46784f2e5589a67658 49.235.119.106:3261@13261 master - 0 1642407834000 1 connected 0-5460
1a4c9a538ee0b245ed2372a66b22416b714f1a74 49.235.119.106:3264@13264 slave 1d15cb3c53dbb7075663919d023cb4751bc60ae2 0 1642407834021 3 connected

给redis集群设置密码

  1. 集群构建完成前不要配置密码,集群构建完毕再通过config set + config rewrite命令逐个机器设置密码
  2. 如果对集群设置密码,那么requirepass和masterauth都需要设置,否则发生主从切换时,就会遇到授权问题,可以模拟并观察日志
  3. 各个节点的密码都必须一致,否则Redirected就会失败

设置密码

分别连接6个节点,执行如下命令:

src/redis-cli -c -h 49.235.119.106 -p 3261
config set masterauth rqCts6hM&hLOqdQcevZsInNe01h3jzyGEz84C*WdLS4k1H2t
config set requirepass rqCts6hM&hLOqdQcevZsInNe01h3jzyGEz84C*WdLS4k1H2t
config rewrite

验证密码

6个节点均执行如上命令之后,验证执行结果:

$ src/redis-cli -c -h 49.235.119.106 -p 3266
49.235.119.106:3266> config get requirepass
(error) NOAUTH Authentication required.
49.235.119.106:3266> auth rqCts6hM&hLOqdQcevZsInNe01h3jzyGEz84C*WdLS4k1H2t
OK
49.235.119.106:3266> config get requirepass
1) "requirepass"
2) "rqCts6hM&hLOqdQcevZsInNe01h3jzyGEz84C*WdLS4k1H2t"

验证存储

$ src/redis-cli -c -h 49.235.119.106 -p 3261 --askpass
Please input password: ************************************************
49.235.119.106:3261> set name wangxianfeng ex 1000
-> Redirected to slot [5798] located at 49.235.119.106:3262
OK
49.235.119.106:3262> get name
"wangxianfeng"

扩充集群节点

新增主节点

首先新增2个节点,端口分别使用3267,3268,其中3267将作为主节点,3268将作为从节点。
首先添加节点配置,启动实例:

./src/redis-server cluster/3267.conf;
./src/redis-server cluster/3268.conf;

然后通过以下命令添加主节点(第一个ip:port 为需要添加的节点ip和端口,第二个ip:port为当前集群中的节点和端口):

$ ./src/redis-cli --cluster add-node 49.235.119.106:3267 49.235.119.106:3261 --user default --askpass
Please input password: ************************************************
>>> Adding node 49.235.119.106:3267 to cluster 49.235.119.106:3261
>>> Performing Cluster Check (using node 49.235.119.106:3261)
M: 7a9290eb02cb6c980e015b46784f2e5589a67658 49.235.119.106:3261
   slots:[0-5460] (5461 slots) master
   1 additional replica(s)
S: 62cb53e25ac3880b74b271acd311b9e93b16255c 49.235.119.106:3266
   slots: (0 slots) slave
   replicates 4f4c762762f27da16ae122083c0247dc9caf8454
S: 1a4c9a538ee0b245ed2372a66b22416b714f1a74 49.235.119.106:3264
   slots: (0 slots) slave
   replicates 1d15cb3c53dbb7075663919d023cb4751bc60ae2
M: 4f4c762762f27da16ae122083c0247dc9caf8454 49.235.119.106:3262
   slots:[5461-10922] (5462 slots) master
   1 additional replica(s)
M: 1d15cb3c53dbb7075663919d023cb4751bc60ae2 49.235.119.106:3263
   slots:[10923-16383] (5461 slots) master
   1 additional replica(s)
S: 437dd81e8a41eaa6fdd222cf04a4ea412fbeff5c 49.235.119.106:3265
   slots: (0 slots) slave
   replicates 7a9290eb02cb6c980e015b46784f2e5589a67658
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
>>> Send CLUSTER MEET to node 49.235.119.106:3267 to make it join the cluster.
[OK] New node added correctly.

分配哈希槽

注意:新添加的节点是没有哈希槽的,所以并不能正常存储数据,需要给新添加的节点分配哈希曹:哈希槽的配置不均匀,可能导致数据不同步;
1. 重新分配哈希槽
ip:port 为当前redis集群任意节点ip和port,--askpass表示后输入密码

$ ./src/redis-cli --cluster reshard  49.235.119.106:3267 --askpass
Please input password: ************************************************
>>> Performing Cluster Check (using node 49.235.119.106:3267)
M: 602cea8f58f677d7d71ae394c06e76d743ff729f 49.235.119.106:3267
   slots: (0 slots) master
S: 62cb53e25ac3880b74b271acd311b9e93b16255c 49.235.119.106:3266
   slots: (0 slots) slave
   replicates 4f4c762762f27da16ae122083c0247dc9caf8454
M: 4f4c762762f27da16ae122083c0247dc9caf8454 49.235.119.106:3262
   slots:[5461-10922] (5462 slots) master
   1 additional replica(s)
M: 7a9290eb02cb6c980e015b46784f2e5589a67658 49.235.119.106:3261
   slots:[0-5460] (5461 slots) master
   1 additional replica(s)
M: 1d15cb3c53dbb7075663919d023cb4751bc60ae2 49.235.119.106:3263
   slots:[10923-16383] (5461 slots) master
   1 additional replica(s)
S: 1a4c9a538ee0b245ed2372a66b22416b714f1a74 49.235.119.106:3264
   slots: (0 slots) slave
   replicates 1d15cb3c53dbb7075663919d023cb4751bc60ae2
S: 437dd81e8a41eaa6fdd222cf04a4ea412fbeff5c 49.235.119.106:3265
   slots: (0 slots) slave
   replicates 7a9290eb02cb6c980e015b46784f2e5589a67658
[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)? 
  1. 输入要分配多少个哈希槽(数量)?比如我要分配4096个哈希槽
    (16384分配到4个节点上,每个分配4096个)
[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)? 4096 
What is the receiving node ID?
  1. 输入指定要分配哈希槽的节点ID,如上上图端口号为3267的主节点哈希槽的数量为0,输入其ID:
What is the receiving node ID? 602cea8f58f677d7d71ae394c06e76d743ff729f
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: 
  1. 选择需要分配的哈希槽来源,输入all
    输入all 需要分配给目标节点的哈希槽来着当前集群的其他主节点(每个节点拿出的数量为集群自动决定)
Moving slot 12284 from 1d15cb3c53dbb7075663919d023cb4751bc60ae2
    Moving slot 12285 from 1d15cb3c53dbb7075663919d023cb4751bc60ae2
    Moving slot 12286 from 1d15cb3c53dbb7075663919d023cb4751bc60ae2
    Moving slot 12287 from 1d15cb3c53dbb7075663919d023cb4751bc60ae2
Do you want to proceed with the proposed reshard plan (yes/no)? 
  1. 是否继续执行建议的reshard计划, 输入yes后,就会完成分配哈希槽:
……
Moving slot 12278 from 49.235.119.106:3263 to 49.235.119.106:3267: 
Moving slot 12279 from 49.235.119.106:3263 to 49.235.119.106:3267: 
Moving slot 12280 from 49.235.119.106:3263 to 49.235.119.106:3267: 
Moving slot 12281 from 49.235.119.106:3263 to 49.235.119.106:3267: 
Moving slot 12282 from 49.235.119.106:3263 to 49.235.119.106:3267: 
Moving slot 12283 from 49.235.119.106:3263 to 49.235.119.106:3267: 
Moving slot 12284 from 49.235.119.106:3263 to 49.235.119.106:3267: 
Moving slot 12285 from 49.235.119.106:3263 to 49.235.119.106:3267: 
Moving slot 12286 from 49.235.119.106:3263 to 49.235.119.106:3267: 
Moving slot 12287 from 49.235.119.106:3263 to 49.235.119.106:3267:
  1. 验证哈希槽分配情况:
$ src/redis-cli -c -h 49.235.119.106 -p 3261 --askpass
Please input password: ************************************************
49.235.119.106:3261> cluster nodes
62cb53e25ac3880b74b271acd311b9e93b16255c 49.235.119.106:3266@13266 slave 4f4c762762f27da16ae122083c0247dc9caf8454 0 1642411885734 2 connected
1a4c9a538ee0b245ed2372a66b22416b714f1a74 49.235.119.106:3264@13264 slave 1d15cb3c53dbb7075663919d023cb4751bc60ae2 0 1642411888000 3 connected
4f4c762762f27da16ae122083c0247dc9caf8454 49.235.119.106:3262@13262 master - 0 1642411885000 2 connected 6827-10922
7a9290eb02cb6c980e015b46784f2e5589a67658 10.0.4.3:3261@13261 myself,master - 0 1642411887000 1 connected 1365-5460
1d15cb3c53dbb7075663919d023cb4751bc60ae2 49.235.119.106:3263@13263 master - 0 1642411888745 3 connected 12288-16383
602cea8f58f677d7d71ae394c06e76d743ff729f 49.235.119.106:3267@13267 master - 0 1642411886000 7 connected 0-1364 5461-6826 10923-12287
437dd81e8a41eaa6fdd222cf04a4ea412fbeff5c 49.235.119.106:3265@13265 slave 7a9290eb02cb6c980e015b46784f2e5589a67658 0 1642411886738 1 connected

可以看到,3267分配的槽值为0-1364 5461-6826 10923-12287,共4096个。

添加从节点

把3268节点作为3267节点的从节点加入集群:

新增3268节点为从节点,主节点为3267
# 节点ID是主节点的ID
# 49.235.119.106:3268 是新加的从节点
# 49.235.119.106:3267 作为从节点的主节点
./src/redis-cli --cluster add-node --cluster-slave --cluster-master-id 602cea8f58f677d7d71ae394c06e76d743ff729f 49.235.119.106:3268 49.235.119.106:3267 --askpass
$ ./src/redis-cli --cluster add-node --cluster-slave --cluster-master-id 602cea8f58f677d7d71ae394c06e76d743ff729f 49.235.119.106:3268 49.235.119.106:3267 --askpass
Please input password: ************************************************
>>> Adding node 49.235.119.106:3268 to cluster 49.235.119.106:3267
>>> Performing Cluster Check (using node 49.235.119.106:3267)
M: 602cea8f58f677d7d71ae394c06e76d743ff729f 49.235.119.106:3267
   slots:[0-1364],[5461-6826],[10923-12287] (4096 slots) master
S: 62cb53e25ac3880b74b271acd311b9e93b16255c 49.235.119.106:3266
   slots: (0 slots) slave
   replicates 4f4c762762f27da16ae122083c0247dc9caf8454
M: 4f4c762762f27da16ae122083c0247dc9caf8454 49.235.119.106:3262
   slots:[6827-10922] (4096 slots) master
   1 additional replica(s)
M: 7a9290eb02cb6c980e015b46784f2e5589a67658 49.235.119.106:3261
   slots:[1365-5460] (4096 slots) master
   1 additional replica(s)
M: 1d15cb3c53dbb7075663919d023cb4751bc60ae2 49.235.119.106:3263
   slots:[12288-16383] (4096 slots) master
   1 additional replica(s)
S: 1a4c9a538ee0b245ed2372a66b22416b714f1a74 49.235.119.106:3264
   slots: (0 slots) slave
   replicates 1d15cb3c53dbb7075663919d023cb4751bc60ae2
S: 437dd81e8a41eaa6fdd222cf04a4ea412fbeff5c 49.235.119.106:3265
   slots: (0 slots) slave
   replicates 7a9290eb02cb6c980e015b46784f2e5589a67658
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
>>> Send CLUSTER MEET to node 49.235.119.106:3268 to make it join the cluster.
Waiting for the cluster to join

>>> Configure node as replica of 49.235.119.106:3267.
[OK] New node added correctly.

验证集群状态

$ src/redis-cli -c -h 49.235.119.106 -p 3261 --askpass
Please input password: ************************************************
49.235.119.106:3261> cluster info
cluster_state:ok
cluster_slots_assigned:16384
cluster_slots_ok:16384
cluster_slots_pfail:0
cluster_slots_fail:0
cluster_known_nodes:8
cluster_size:4
cluster_current_epoch:7
cluster_my_epoch:1
cluster_stats_messages_ping_sent:6767
cluster_stats_messages_pong_sent:7284
cluster_stats_messages_update_sent:12
cluster_stats_messages_sent:14063
cluster_stats_messages_ping_received:7278
cluster_stats_messages_pong_received:10862
cluster_stats_messages_meet_received:6
cluster_stats_messages_update_received:17
cluster_stats_messages_received:18163
49.235.119.106:3261> cluster nodes
62cb53e25ac3880b74b271acd311b9e93b16255c 49.235.119.106:3266@13266 slave 4f4c762762f27da16ae122083c0247dc9caf8454 0 1642414236162 2 connected
1a4c9a538ee0b245ed2372a66b22416b714f1a74 49.235.119.106:3264@13264 slave 1d15cb3c53dbb7075663919d023cb4751bc60ae2 0 1642414234155 3 connected
4f4c762762f27da16ae122083c0247dc9caf8454 49.235.119.106:3262@13262 master - 0 1642414233000 2 connected 6827-10922
7a9290eb02cb6c980e015b46784f2e5589a67658 10.0.4.3:3261@13261 myself,master - 0 1642414234000 1 connected 1365-5460
1d15cb3c53dbb7075663919d023cb4751bc60ae2 49.235.119.106:3263@13263 master - 0 1642414235159 3 connected 12288-16383
602cea8f58f677d7d71ae394c06e76d743ff729f 49.235.119.106:3267@13267 master - 0 1642414231148 7 connected 0-1364 5461-6826 10923-12287
563b5e13a31c8fe11f6f97312df242d6c3e9ecc7 49.235.119.106:3268@13268 slave 602cea8f58f677d7d71ae394c06e76d743ff729f 0 1642414233000 7 connected
437dd81e8a41eaa6fdd222cf04a4ea412fbeff5c 49.235.119.106:3265@13265 slave 7a9290eb02cb6c980e015b46784f2e5589a67658 0 1642414233152 1 connected

至此,4主4从节点全部添加完成。

王显锋

激情工作,快乐生活!

文章评论