Redis Cluster 搭建(工具)

环境准备

节点 IP 端口
节点① 172.16.1.121 6379,6380
节点② 172.16.1.122 6379,6380
节点③ 172.16.1.123 6379,6380

搭建 Redis 多实例

# 删除以前的 Redis 数据
[root@dbtest01 ~]# rm -rf /service/redis/* # 创建多实例目录
[root@dbtest01 ~]# mkdir /service/redis/{6379,6380}
[root@dbtest02 ~]# mkdir /service/redis/{6379,6380}
[root@dbtest03 ~]# mkdir /service/redis/{6379,6380} # 配置所有 Redis
[root@dbtest01 ~]# vim /service/redis/6379/redis.conf
bind 172.16.1.121 127.0.0.1
port 6379
daemonize yes
pidfile /service/redis/6379/redis.pid
loglevel notice
logfile /service/redis/6379/redis.log
dbfilename dump.rdb
dir /service/redis/6379
cluster-enabled yes
cluster-config-file nodes.conf
cluster-node-timeout 5000 [root@dbtest01 ~]# vim /service/redis/6380/redis.conf
bind 172.16.1.121 127.0.0.1
port 6380
daemonize yes
pidfile /service/redis/6380/redis.pid
loglevel notice
logfile /service/redis/6380/redis.log
dbfilename dump.rdb
dir /service/redis/6380
cluster-enabled yes
cluster-config-file nodes.conf
cluster-node-timeout 5000

启动 Redis 多实例

[root@dbtest01 ~]# redis-server /service/redis/6379/redis.conf
[root@dbtest01 ~]# redis-server /service/redis/6380/redis.conf
[root@dbtest02 ~]# redis-server /service/redis/6379/redis.conf
[root@dbtest02 ~]# redis-server /service/redis/6380/redis.conf
[root@dbtest03 ~]# redis-server /service/redis/6379/redis.conf
[root@dbtest03 ~]# redis-server /service/redis/6380/redis.conf

安装插件

# 配置 EPEL 源,安装 ruby 支持
[root@dbtest01 ~]# yum install ruby rubygems -y # 查看 gem 源
[root@dbtest01 ~]# gem sources -l
*** CURRENT SOURCES *** http://rubygems.org/ # 添加阿里云 gem 源
[root@dbtest01 ~]# gem sources -a http://mirrors.aliyun.com/rubygems/
http://mirrors.aliyun.com/rubygems/ added to sources # 删除国外 gem 源
[root@dbtest01 ~]# gem sources --remove https://rubygems.org/
http://rubygems.org/ removed from sources # 再次查看 gem 源
[root@dbtest01 ~]# gem sources -l # 使用 gem 安装 redis 的 ruby 插件
[root@dbtest01 ~]# gem install redis -v 3.3.3
Successfully installed redis-3.3.3
1 gem installed
Installing ri documentation for redis-3.3.3...
Installing RDoc documentation for redis-3.3.3...

命令工具

# redis-trib.rb 是做分布式集群的命令工具,是 Redis 自带的,但需要 Ruby 插件支持才能使用
[root@dbtest01 ~]# redis-trib.rb
create # 创建一个集群
check # 检查集群
info # 集群状态
fix # 修复集群
reshard # 重新分配槽位
rebalance # 平衡槽位数量
add-node # 添加节点
del-node # 删除节点
set-timeout # 设置超时时间
call # 向集群所有机器输入命令
import # 导入数据
help # 帮助

关联所有节点

# 选项–replicas 1 表示我们希望为集群中的每个主节点创建一个从节点
[root@dbtest01 6380]# redis-trib.rb create --replicas 1 172.16.1.121:6379 172.16.1.122:6379 172.16.1.123:6379 172.16.1.122:6380 172.16.1.123:6380 172.16.1.121:6380
>>> Creating cluster
>>> Performing hash slots allocation on 6 nodes...
Using 3 masters:
172.16.1.121:6379
172.16.1.122:6379
172.16.1.123:6379
Adding replica 172.16.1.122:6380 to 172.16.1.121:6379
Adding replica 172.16.1.121:6380 to 172.16.1.122:6379
Adding replica 172.16.1.123:6380 to 172.16.1.123:6379
M: 85622647ecc43b13ea10083aa59e73399a30b75f 172.16.1.121:6379
slots:0-5460 (5461 slots) master
M: 0f0232ee5ded523a1ccb6c9e281555a1da13c5d9 172.16.1.122:6379
slots:5461-10922 (5462 slots) master
M: 98f828cce3188a3f670dbbd9f77b5723df6cf53b 172.16.1.123:6379
slots:10923-16383 (5461 slots) master
S: 92bf59c43755c92953e50dda2c7d806bbb9d5f7b 172.16.1.122:6380
replicates 85622647ecc43b13ea10083aa59e73399a30b75f
S: cd7afafbf822fb17c26e0e45c921dfa94d8526b9 172.16.1.123:6380
replicates 98f828cce3188a3f670dbbd9f77b5723df6cf53b
S: ed5d625d41f5c3621bdd068dbd0c2c30bc4c0649 172.16.1.121:6380
replicates 0f0232ee5ded523a1ccb6c9e281555a1da13c5d9
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 172.16.1.121:6379)
M: 85622647ecc43b13ea10083aa59e73399a30b75f 172.16.1.121:6379
slots:0-5460 (5461 slots) master
1 additional replica(s)
M: 98f828cce3188a3f670dbbd9f77b5723df6cf53b 172.16.1.123:6379
slots:10923-16383 (5461 slots) master
1 additional replica(s)
S: cd7afafbf822fb17c26e0e45c921dfa94d8526b9 172.16.1.123:6380
slots: (0 slots) slave
replicates 98f828cce3188a3f670dbbd9f77b5723df6cf53b
M: 0f0232ee5ded523a1ccb6c9e281555a1da13c5d9 172.16.1.122:6379
slots:5461-10922 (5462 slots) master
1 additional replica(s)
S: ed5d625d41f5c3621bdd068dbd0c2c30bc4c0649 172.16.1.121:6380
slots: (0 slots) slave
replicates 0f0232ee5ded523a1ccb6c9e281555a1da13c5d9
S: 92bf59c43755c92953e50dda2c7d806bbb9d5f7b 172.16.1.122:6380
slots: (0 slots) slave
replicates 85622647ecc43b13ea10083aa59e73399a30b75f
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

查看集群状态

[root@dbtest01 6380]# redis-cli -h 172.16.1.121 -p 6379 CLUSTER NODES
98f828cce3188a3f670dbbd9f77b5723df6cf53b 172.16.1.123:6379 master - 0 1596788944243 3 connected 10923-16383
cd7afafbf822fb17c26e0e45c921dfa94d8526b9 172.16.1.123:6380 slave 98f828cce3188a3f670dbbd9f77b5723df6cf53b 0 1596788945754 5 connected
0f0232ee5ded523a1ccb6c9e281555a1da13c5d9 172.16.1.122:6379 master - 0 1596788943739 2 connected 5461-10922
85622647ecc43b13ea10083aa59e73399a30b75f 172.16.1.121:6379 myself,master - 0 0 1 connected 0-5460
ed5d625d41f5c3621bdd068dbd0c2c30bc4c0649 172.16.1.121:6380 slave 0f0232ee5ded523a1ccb6c9e281555a1da13c5d9 0 1596788945250 6 connected
92bf59c43755c92953e50dda2c7d806bbb9d5f7b 172.16.1.122:6380 slave 85622647ecc43b13ea10083aa59e73399a30b75f 0 1596788944745 4 connected

重新配置主从

由于使用工具,始终有一台机器从库本机的从库,所以要重新分配主从 ~ ~ ~

# 由于使用工具,始终有一台机器从库本机的从库,所以要重新分配主从
172.16.1.122:6380> CLUSTER REPLICATE 98f828cce3188a3f670dbbd9f77b5723df6cf53b
OK
172.16.1.123:6380> CLUSTER REPLICATE 85622647ecc43b13ea10083aa59e73399a30b75f
OK

插入数据测试

# 执行脚本
[root@dbtest01 ~]# cat data.sh
#!/bin/bash
for i in {1..1000};do
redis-cli -c -h 172.16.1.121 -p 6379 SET k${i} v${i}
done
# 查看槽位分布,数据(keys)分布
[root@dbtest01 ~]# redis-trib.rb info 172.16.1.121:6379
172.16.1.121:6379 (85622647...) -> 341 keys | 5461 slots | 1 slaves.
172.16.1.123:6379 (98f828cc...) -> 327 keys | 5461 slots | 1 slaves.
172.16.1.122:6379 (0f0232ee...) -> 332 keys | 5462 slots | 1 slaves.
[OK] 1000 keys in 3 masters.
0.06 keys per slot on average.

Redis 集群节点修改

①. — 新节点添加槽位

②. — 源节点中的数据进行迁移

③. — 源节点数据迁移完毕

④. — 迁移下一个槽位的数据,依次循环

添加节点

准备新机器

# 此处没有另外准备新的虚拟机,暂时在 dbtest03 上添加 2 个实例,即一对主从节点
[root@dbtest03 ~]# mkdir /service/redis/{6381,6382}
[root@dbtest03 ~]# vim /service/redis/6381/redis.conf
[root@dbtest03 ~]# vim /service/redis/6382/redis.conf # 启动新节点
[root@dbtest03 ~]# redis-server /service/redis/6381/redis.conf
[root@dbtest03 ~]# redis-server /service/redis/6382/redis.conf

关联新节点

# 关联新的节点到 Redis 分布式集群中
[root@dbtest03 ~]# redis-trib.rb add-node 172.16.1.123:6381 172.16.1.121:6379
[root@dbtest03 ~]# redis-trib.rb add-node 172.16.1.123:6382 172.16.1.121:6379
# 或者
[root@dbtest03 ~]# redis-cli -p 6379 -h 172.16.1.121 cluster meet 172.16.1.123 6381
[root@dbtest03 ~]# redis-cli -p 6379 -h 172.16.1.121 cluster meet 172.16.1.123 6382 # 查看节点信息
[root@dbtest03 ~]# redis-trib.rb info 172.16.1.121:6379
172.16.1.121:6379 (85622647...) -> 341 keys | 5461 slots | 1 slaves.
172.16.1.123:6379 (98f828cc...) -> 327 keys | 5461 slots | 1 slaves.
172.16.1.122:6379 (0f0232ee...) -> 332 keys | 5462 slots | 1 slaves.
172.16.1.123:6381 (ac2a7383...) -> 0 keys | 0 slots | 0 slaves.
[OK] 1000 keys in 4 masters.
0.06 keys per slot on average.
# 或者
[root@dbtest03 ~]# redis-cli -p 6379 -h 172.16.1.121 cluster nodes
98f828cce3188a3f670dbbd9f77b5723df6cf53b 172.16.1.123:6379 master - 0 1596791728636 3 connected 10923-16383
cd7afafbf822fb17c26e0e45c921dfa94d8526b9 172.16.1.123:6380 slave 85622647ecc43b13ea10083aa59e73399a30b75f 0 1596791730146 5 connected
0f0232ee5ded523a1ccb6c9e281555a1da13c5d9 172.16.1.122:6379 master - 0 1596791730649 2 connected 5461-10922
85622647ecc43b13ea10083aa59e73399a30b75f 172.16.1.121:6379 myself,master - 0 0 1 connected 0-5460
ed5d625d41f5c3621bdd068dbd0c2c30bc4c0649 172.16.1.121:6380 slave 0f0232ee5ded523a1ccb6c9e281555a1da13c5d9 0 1596791729138 6 connected
ac2a738356e56952a792fc36c51290675bcc7ed9 172.16.1.123:6381 master - 0 1596791729139 0 connected
92bf59c43755c92953e50dda2c7d806bbb9d5f7b 172.16.1.122:6380 slave 98f828cce3188a3f670dbbd9f77b5723df6cf53b 0 1596791729139 4 connected

重新分配槽位

[root@dbtest03 ~]#  redis-trib.rb reshard 172.16.1.121:6379
# 你想移动多少个槽位到新节点
How many slots do you want to move (from 1 to 16384)? 4096
# 新节点的 ID 是什么
What is the receiving node ID? ac2a738356e56952a792fc36c51290675bcc7ed9
# 输入源节点的ID,如果是所有节点直接使用 all
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:all
# 你确定要这么分配?
Do you want to proceed with the proposed reshard plan (yes/no)? yes # 分配完毕,查看分配结果
[root@dbtest03 ~]# redis-cli -p 6379 -h 172.16.1.121 cluster nodes
98f828cce3188a3f670dbbd9f77b5723df6cf53b 172.16.1.123:6379 master - 0 1596792078142 3 connected 12288-16383
cd7afafbf822fb17c26e0e45c921dfa94d8526b9 172.16.1.123:6380 slave 85622647ecc43b13ea10083aa59e73399a30b75f 0 1596792079652 5 connected
0f0232ee5ded523a1ccb6c9e281555a1da13c5d9 172.16.1.122:6379 master - 0 1596792080155 2 connected 6827-10922
85622647ecc43b13ea10083aa59e73399a30b75f 172.16.1.121:6379 myself,master - 0 0 1 connected 1365-5460
ed5d625d41f5c3621bdd068dbd0c2c30bc4c0649 172.16.1.121:6380 slave 0f0232ee5ded523a1ccb6c9e281555a1da13c5d9 0 1596792078645 6 connected
ac2a738356e56952a792fc36c51290675bcc7ed9 172.16.1.123:6381 master - 0 1596792078645 7 connected 0-1364 5461-6826 10923-12287
92bf59c43755c92953e50dda2c7d806bbb9d5f7b 172.16.1.122:6380 slave 98f828cce3188a3f670dbbd9f77b5723df6cf53b 0 1596792079652 4 connected
# 或者
[root@dbtest03 ~]# redis-trib.rb info 172.16.1.121:6379
172.16.1.121:6379 (85622647...) -> 249 keys | 4096 slots | 1 slaves.
172.16.1.123:6379 (98f828cc...) -> 251 keys | 4096 slots | 1 slaves.
172.16.1.122:6379 (0f0232ee...) -> 254 keys | 4096 slots | 1 slaves.
172.16.1.123:6381 (ac2a7383...) -> 246 keys | 4096 slots | 0 slaves.
[OK] 1000 keys in 4 masters.
0.06 keys per slot on average.

添加新节点副本

# 添加新节点的副本
[root@dbtest02 ~]# redis-cli -h 172.16.1.123 -p 6382 cluster replicate ac2a738356e56952a792fc36c51290675bcc7ed9
# 或者
[root@dbtest01 ~]# redis-trib.rb add-node --slave --master-id ac2a738356e56952a792fc36c51290675bcc7ed9 172.16.1.122:6382 172.16.1.121:6379 # 上面的命令中最后的 172.16.1.121:6379 ,可以换成集群中任意一台 Redis 实例节点 # 查看 Redis 集群状态,集群每个节点都有一个从库
[root@dbtest03 ~]# redis-trib.rb info 172.16.1.121:6379
172.16.1.121:6379 (85622647...) -> 249 keys | 4096 slots | 1 slaves.
172.16.1.123:6379 (98f828cc...) -> 251 keys | 4096 slots | 1 slaves.
172.16.1.122:6379 (0f0232ee...) -> 254 keys | 4096 slots | 1 slaves.
172.16.1.123:6381 (ac2a7383...) -> 246 keys | 4096 slots | 1 slaves.
[OK] 1000 keys in 4 masters.
0.06 keys per slot on average.
# 或者
[root@dbtest03 ~]# redis-cli -p 6379 -h 172.16.1.121 cluster nodes
98f828cce3188a3f670dbbd9f77b5723df6cf53b 172.16.1.123:6379 master - 0 1596795522020 3 connected 12288-16383
591fab958ffe8695ea83287b6576cd3ba720b385 172.16.1.123:6382 slave ac2a738356e56952a792fc36c51290675bcc7ed9 0 1596795521515 7 connected
0f0232ee5ded523a1ccb6c9e281555a1da13c5d9 172.16.1.122:6379 master - 0 1596795521515 2 connected 6827-10922
85622647ecc43b13ea10083aa59e73399a30b75f 172.16.1.121:6379 myself,master - 0 0 1 connected 1365-5460
92bf59c43755c92953e50dda2c7d806bbb9d5f7b 172.16.1.122:6380 slave 98f828cce3188a3f670dbbd9f77b5723df6cf53b 0 1596795520508 4 connected
cd7afafbf822fb17c26e0e45c921dfa94d8526b9 172.16.1.123:6380 slave 85622647ecc43b13ea10083aa59e73399a30b75f 0 1596795522523 5 connected
ed5d625d41f5c3621bdd068dbd0c2c30bc4c0649 172.16.1.121:6380 slave 0f0232ee5ded523a1ccb6c9e281555a1da13c5d9 0 1596795521011 6 connected
ac2a738356e56952a792fc36c51290675bcc7ed9 172.16.1.123:6381 master - 0 1596795521515 7 connected 0-1364 5461-6826 10923-12287 # 调整主从,尽量保证每一台机器的副本都不于主节点在一台机器

模拟故障(不作不会死)

# 分配槽位的过程中
[root@dbtest01 ~]# redis-trib.rb reshard 172.16.1.121:6379 # 执行 Ctrl+c # 查看集群状态一些命令看不出来有错
[root@dbtest01 ~]# redis-cli -p 6379 -h 172.16.1.121 cluster info
[root@dbtest01 ~]# redis-cli -p 6379 -h 172.16.1.121 cluster nodes
[root@dbtest01 ~]# redis-trib.rb info 172.16.1.121:6379 # 必须使用工具检查集群
[root@dbtest01 ~]# redis-trib.rb check 172.16.1.121:6379 # 错误一:172.16.1.122:6379 节点正在导出槽位,172.16.1.122:6381 节点正在导入槽位
>>> Check for open slots...
[WARNING] Node 172.16.1.122:6381 has slots in importing state (6885).
[WARNING] Node 172.16.1.122:6379 has slots in migrating state (6885).
[WARNING] The following slots are open: 6885
>>> Check slots coverage... #错误二:172.16.1.122:6379 节点正在导出槽位
>>> Check for open slots...
[WARNING] Node 172.16.1.122:6379 has slots in migrating state (6975).
[WARNING] The following slots are open: 6975
>>> Check slots coverage... #错误三:
>>> Check for open slots...
[WARNING] Node 172.16.1.122:6381 has slots in importing state (7093).
[WARNING] The following slots are open: 7093
>>> Check slots coverage...

修复故障(不作不会死)

#使用fix修复集群
[root@dbtest01 ~]# redis-trib.rb fix 172.16.1.122:6379 #将槽位平均分配
1.平均之前
[root@dbtest01 ~]# redis-trib.rb info 172.16.1.121:6379
172.16.1.121:6379 (5ad7bd95...) -> 499 keys | 4096 slots | 1 slaves.
172.16.1.123:6379 (d2755303...) -> 501 keys | 4096 slots | 1 slaves.
172.16.1.122:6381 (a298dbd2...) -> 648 keys | 5320 slots | 1 slaves.
172.16.1.122:6379 (7c79559b...) -> 352 keys | 2872 slots | 1 slaves.
[OK] 2000 keys in 4 masters.
0.12 keys per slot on average. 2.平均分配(如果节点之间槽位数量相差较小,不会平均分配)
[root@dbtest01 ~]# redis-trib.rb rebalance 172.16.1.121:6379
>>> Performing Cluster Check (using node 172.16.1.121:6379)
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
>>> Rebalancing across 4 nodes. Total weight = 4
Moving 1224 slots from 172.16.1.122:6381 to 172.16.1.122:6379
##################################################################################################### 3平均分配之后
[root@dbtest01 ~]# redis-trib.rb info 172.16.1.121:6379
172.16.1.121:6379 (5ad7bd95...) -> 499 keys | 4096 slots | 1 slaves.
172.16.1.123:6379 (d2755303...) -> 501 keys | 4096 slots | 1 slaves.
172.16.1.122:6381 (a298dbd2...) -> 492 keys | 4096 slots | 1 slaves.
172.16.1.122:6379 (7c79559b...) -> 508 keys | 4096 slots | 1 slaves.
[OK] 2000 keys in 4 masters.
0.12 keys per slot on average.

删除节点

重新分配槽位

# 重新分配
[root@dbtest01 ~]#redis-trib.rb reshard 172.16.1.121:6379
...
How many slots do you want to move (from 1 to 16384)? 1365 # 要分配的槽位数量
What is the receiving node ID? 85622647ecc43b13ea10083aa59e73399a30b75f # 接收槽位的节点 id
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:ac2a738356e56952a792fc36c51290675bcc7ed9 # 要删除的节点 id
Source node #2:done
Do you want to proceed with the proposed reshard plan (yes/no)? yes
... # 第二次重新分配
[root@dbtest03 ~]# redis-trib.rb reshard 172.16.1.121:6379
>>> Performing Cluster Check (using node 172.16.1.121:6379)
M: 85622647ecc43b13ea10083aa59e73399a30b75f 172.16.1.121:6379
slots:0-5460 (5461 slots) master
1 additional replica(s)
M: 98f828cce3188a3f670dbbd9f77b5723df6cf53b 172.16.1.123:6379
slots:12288-16383 (4096 slots) master
1 additional replica(s)
S: 591fab958ffe8695ea83287b6576cd3ba720b385 172.16.1.123:6382
slots: (0 slots) slave
replicates ac2a738356e56952a792fc36c51290675bcc7ed9
M: 0f0232ee5ded523a1ccb6c9e281555a1da13c5d9 172.16.1.122:6379
slots:6827-10922 (4096 slots) master
1 additional replica(s)
S: 92bf59c43755c92953e50dda2c7d806bbb9d5f7b 172.16.1.122:6380
slots: (0 slots) slave
replicates 98f828cce3188a3f670dbbd9f77b5723df6cf53b
S: cd7afafbf822fb17c26e0e45c921dfa94d8526b9 172.16.1.123:6380
slots: (0 slots) slave
replicates 85622647ecc43b13ea10083aa59e73399a30b75f
S: ed5d625d41f5c3621bdd068dbd0c2c30bc4c0649 172.16.1.121:6380
slots: (0 slots) slave
replicates 0f0232ee5ded523a1ccb6c9e281555a1da13c5d9
M: ac2a738356e56952a792fc36c51290675bcc7ed9 172.16.1.123:6381
slots:5461-6826,10923-12287 (2731 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.
How many slots do you want to move (from 1 to 16384)? 1366
What is the receiving node ID? 0f0232ee5ded523a1ccb6c9e281555a1da13c5d9
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:ac2a738356e56952a792fc36c51290675bcc7ed9
Source node #2:done
Do you want to proceed with the proposed reshard plan (yes/no)? yes # 第三次重新分配
[root@dbtest03 ~]# redis-trib.rb reshard 172.16.1.121:6379
>>> Performing Cluster Check (using node 172.16.1.121:6379)
M: 85622647ecc43b13ea10083aa59e73399a30b75f 172.16.1.121:6379
slots:0-5460 (5461 slots) master
1 additional replica(s)
M: 98f828cce3188a3f670dbbd9f77b5723df6cf53b 172.16.1.123:6379
slots:12288-16383 (4096 slots) master
1 additional replica(s)
S: 591fab958ffe8695ea83287b6576cd3ba720b385 172.16.1.123:6382
slots: (0 slots) slave
replicates ac2a738356e56952a792fc36c51290675bcc7ed9
M: 0f0232ee5ded523a1ccb6c9e281555a1da13c5d9 172.16.1.122:6379
slots:5461-6825,6827-10922 (5461 slots) master
1 additional replica(s)
S: 92bf59c43755c92953e50dda2c7d806bbb9d5f7b 172.16.1.122:6380
slots: (0 slots) slave
replicates 98f828cce3188a3f670dbbd9f77b5723df6cf53b
S: cd7afafbf822fb17c26e0e45c921dfa94d8526b9 172.16.1.123:6380
slots: (0 slots) slave
replicates 85622647ecc43b13ea10083aa59e73399a30b75f
S: ed5d625d41f5c3621bdd068dbd0c2c30bc4c0649 172.16.1.121:6380
slots: (0 slots) slave
replicates 0f0232ee5ded523a1ccb6c9e281555a1da13c5d9
M: ac2a738356e56952a792fc36c51290675bcc7ed9 172.16.1.123:6381
slots:6826,10923-12287 (1366 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.
How many slots do you want to move (from 1 to 16384)? 1
What is the receiving node ID? 0f0232ee5ded523a1ccb6c9e281555a1da13c5d9
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:ac2a738356e56952a792fc36c51290675bcc7ed9
Source node #2:done
Do you want to proceed with the proposed reshard plan (yes/no)? yes

查看节点信息

[root@dbtest03 ~]# redis-trib.rb info 172.16.1.121:6379
172.16.1.121:6379 (85622647...) -> 341 keys | 5461 slots | 1 slaves.
172.16.1.123:6379 (98f828cc...) -> 327 keys | 5461 slots | 2 slaves.
172.16.1.122:6379 (0f0232ee...) -> 332 keys | 5462 slots | 1 slaves.
172.16.1.123:6381 (ac2a7383...) -> 0 keys | 0 slots | 0 slaves.
[OK] 1000 keys in 4 masters.
0.06 keys per slot on average.

删除节点(无数据)

# 删除没有数据的主节点
[root@dbtest03 ~]# redis-trib.rb del-node 172.16.1.123:6381 ac2a738356e56952a792fc36c51290675bcc7ed9
>>> Removing node ac2a738356e56952a792fc36c51290675bcc7ed9 from cluster 172.16.1.123:6381
>>> Sending CLUSTER FORGET messages to the cluster...
>>> SHUTDOWN the node. # 删除从节点
[root@dbtest03 ~]# redis-trib.rb del-node 172.16.1.123:6382 591fab958ffe8695ea83287b6576cd3ba720b385
>>> Removing node 591fab958ffe8695ea83287b6576cd3ba720b385 from cluster 172.16.1.123:6382
>>> Sending CLUSTER FORGET messages to the cluster...
>>> SHUTDOWN the node. # 删除时不能删除有数据的主节点,从节点可以随便删除
[root@dbtest03 ~]# redis-trib.rb del-node 172.16.1.121:6379 85622647ecc43b13ea10083aa59e73399a30b75f
>>> Removing node 85622647ecc43b13ea10083aa59e73399a30b75f from cluster 172.16.1.121:6379
[ERR] Node 172.16.1.121:6379 is not empty! Reshard data away and try again.

Redis Cluster 分布式集群(下)的更多相关文章

  1. Redis Cluster 分布式集群(上)

    Redis Cluster 介绍 Redis 集群是一个可以在多个Redis节点之间进行数据共享的设施(installation): Redis 集群不支持那些需要同时处理多个键的 Redis 命令, ...

  2. Redis(1.13)Redis cluster 分布式集群手动配置

    [1]试验环境 结构图如下: (这里试验没有那么多机器,就用3台机器搭建试验) redis1是redis集群的一个节点A,上面运行了两个redis实例,7001 7004 redis2是redis集群 ...

  3. CentOS中搭建Redis伪分布式集群【转】

    解压redis 先到官网https://redis.io/下载redis安装包,然后在CentOS操作系统中解压该安装包: tar -zxvf redis-3.2.9.tar.gz 编译redis c ...

  4. 超详细的 Redis Cluster 官方集群搭建指南

    今天从 0 开始搭建 Redis Cluster 官方集群,解决搭建过程中遇到的问题,超详细. 安装ruby环境 因为官方提供的创建集群的工具是用ruby写的,需要ruby2.2.2+版本支持,rub ...

  5. Redis Cluster(集群)的搭建

    一.Redis的下载.安装.启动(单实例) 我们统一将Redis安装在/opt目录下,执行命令如下: $ cd /opt $ wget http://download.redis.io/release ...

  6. Redis Sentinel分布式集群

    helm部署Redis哨兵分布式集群 Redis Sentinel集群 介绍 Redis Sentinel集群是由若干Sentinel节点组成的分布式集群,可以实现故障发现.故障自动转移.配置中心和客 ...

  7. 分布式集群下的Session存储方式窥探

    传统的应用服务器,自身实现的session管理是大多是基于单机的,对于大型分布式网站来说,支撑其业务的远远不止一台服务器,而是一个分布式集群,请求在不同的服务器之间跳转.那么,如何保持服务器之前的se ...

  8. 用redis实现TOMCAT集群下的session共享

    上篇实现了 LINUX中NGINX反向代理下的TOMCAT集群(http://www.cnblogs.com/yuanjava/p/6850764.html) 这次我们在上篇的基础上实现session ...

  9. redis配置cluster分布式集群

    #下载最新的redis5. wget http://download.redis.io/releases/redis-5.0.3.tar.gz .tar.gz cd redis- make make ...

随机推荐

  1. 【EXPDP】导出全部表的时候,选择不导出某个表

    导出的时候指定某一张表不导出的话,一般都用的是数据泵的expdp来操作 具体方法是: expdp test/test dumpfile=test.dmp directory=test_dir excl ...

  2. ctfhub技能树—web前置技能—http协议—Cookie

    打开靶机环境 查看显示内容 根据提示,需要admin登录才能得到flag 题目介绍为Cookie欺骗.认证.伪造 介绍一下cookie和session 一.cookie: 在网站中,http请求是无状 ...

  3. logicaldisk本地磁盘管理

    在网上搜了很多,但是基本都是一样的,差不多都是互相转载摘抄,就那么几个寥寥无几的例子,所以我冒了很大的风险,自己经过多次的测试,对这个命令有了一些新的认识!拿出来分享一下! LOGICALDISK   ...

  4. 入门OJ:简单的网络游戏

    题目描述 在某款极具技术含量的网络游戏中,佳佳靠着他的聪明智慧垄断了游戏中的油田系统.油田里有许多油井,这些油井排成一个M*N的矩形.每个油井都有一个固定的采油量.每两个相邻的油井之间有一条公路,这些 ...

  5. 使用 .NETCore自带框架快速实现依赖注入

    Startup 在Startup的ConfigureServices()中配置DI的接口与其实现 public void ConfigureServices(IServiceCollection se ...

  6. 無法直接連接互聯網,需要使用代理時(Scrapy)

    在windows系統中,如果無法直接連接互聯網,需要使用代理時該怎麽做呢? 1. 在powershell中設置proxy 背景:使用公司電腦,無法直接訪問互聯網,想要訪問互聯網就得使用代理,但是在控制 ...

  7. Redis 实战 —— 09. 实现任务队列、消息拉取和文件分发

    任务队列 P133 通过将待执行任务的相关信息放入队列里面,并在之后对队列进行处理,可以推迟执行那些耗时对操作,这种将工作交给任务处理器来执行对做法被称为任务队列 (task queue) . P13 ...

  8. OAuth2.0是干什么的?

    OAuth2.0是干什么的? 首先用户有一些数据: 将数据存储在服务器上: 这时候有一个应用要访问数据: 如果这个应用是一个恶意程序呢?所以需要一个检验来判断请求是不是安全的: 如何判断是不是安全的? ...

  9. Bitter.Core系列十一:Bitter ORM NETCORE ORM 全网最粗暴简单易用高性能的 NETCore 之 字段变更收集器

    有时候我们业务层需要记录 数据库表更改之前的值和更改之后的值的记录集合--此过程在 Bitter.Core 中有强有力的支持.Bitter.Core 字段收集器提供了方便简单易用的 收集对象在修改之前 ...

  10. 接口新建学习---cookie策略

    一.为什么要添加cookie? 模拟浏览器,因为http是无状态协议,像览器一样的存储和发送Cookie,如果发送一个http请求他的响应中包含Cookie,那么Cookie Manager就会自动地 ...