Redis 集群搭建

Redis集群搭建 7.2.5

文章目录

  • 1. 环境介绍
  • 2. 环境前准备工作(所有机器)
  • 3. 安装 Redis 7.2.5
  • 4. redis 配置修改
    • 4.1 node-01主机添加配置信息
    • 4.2 node-02主机添加配置信息
    • 4.3 node-03主机添加配置信息
  • 5. 制作脚本
    • 5.1 编写脚本
    • 5.2 测试脚本
  • 6. 启动Redis 集群
    • 6.1 启动集群
    • 6.2 查看集群状态
    • 6.3 查看集群节点
    • 6.4 测试用例
  • 7. 集群扩容节点
    • 7.1 node-02
    • 7.2 node-03
    • 7.3 添加主节点
    • 7.4 添加从节点
    • 7.5 集群缩容节点

1. 环境介绍

使用 Redis 集群进行扩展 |文档

Note that the minimal cluster that works as expected must contain at least three master nodes. For deployment, we strongly recommend a six-node cluster, with three masters and three replicas.

请注意,按预期工作的小集群必须包含 至少三个主节点。对于部署,我们强烈建议 一个六节点集群,包含三个主节点和三个副本。

三台服务器各部署一个主节点、一个从节点,同一台服务器上不是直接主从关系。

操作系统Centos 7Centos 7Centos 7
内核版本Linux 3.10.0-957.el7.x86_64Linux 3.10.0-957.el7.x86_64Linux 3.10.0-957.el7.x86_64
主机名称node-01node-02node-03
角色master1/slave2master2/slave3master3/slave1
IP地址192.168.1.100:7000/192.168.1.100:7001192.168.1.200:7000/192.168.1.200:7001192.168.1.250:7000/192.168.1.250:7001
Redis7.2.57.2.57.2.5

2. 环境前准备工作(所有机器)

# 关闭防火墙
systemctl stop firewalld
systemctl disable firewalld# 修改 hostname
hostnamectl set-hostname xxxx  # 修改后退出当前终端重新连接即可# 更新下软件源
# 地址 https://developer.aliyun.com/mirror/# 时区调整,时间校准
date -R
timedatectl set-timezone Asia/Shanghai
yum -y install ntp
ntpdate ntp1.aliyun.com# 关闭 selinux: 
sed -i 's/enforcing/disabled/' /etc/selinux/config
setenforce 0

3. 安装 Redis 7.2.5

# 下载地址
http://download.redis.io/releases/# 下载
wget http://download.redis.io/releases/redis-7.2.5.tar.gz
# 解压
tar -xf redis-7.2.5.tar.gz -C /opt/redis# 编译
make MALLOC=libc# 安装 注意如果安装提示python3不存在 执行 yum install -y python3
make install PREFIX=/usr/local/redis# 配置环境变量
vi /etc/profile.d/redis.sh#!/bin/bashexport REDIS_HOME=/usr/local/redis
export PATH=$PATH:$REDIS_HOME/bin # 使其配置生效
source /etc/profile.d/redis.sh

4. redis 配置修改

4.1 node-01主机添加配置信息

# 创建对应的文件夹
mkdir -p /usr/local/redis/run
mkdir -p /usr/local/redis/log
mkdir -p /usr/local/redis/data/7000
mkdir -p /usr/local/redis/data/7001
mkdir -p /usr/local/redis/conf# cp 配置文件
cp /opt/redis/redis-7.2.5/redis.conf /usr/local/redis/conf/redis_7000.conf# 可能需要清空配置文件信息
echo > /usr/local/redis/conf/redis_7000.conf# 添加配置信息 master1
vi /usr/local/redis/conf/redis_7000.conf  # 关闭保护模式
protected-mode no
# 添加本机的ip
bind 192.168.1.100   
# 端口  
port 7000
# pid存储目录
pidfile /usr/local/redis/run/redis_7000.pid   
# 日志存储目录
logfile /usr/local/redis/log/redis_7000.log 
# 数据存储目录,目录要提前创建好
dir /usr/local/redis/data/7000
# 开启集群 
cluster-enabled yes  
# 集群节点配置文件,这个文件是不能手动编辑的。确保每一个集群节点的配置文件不通
cluster-config-file nodes-7000.conf
# 集群节点的超时时间,单位:ms,超时后集群会认为该节点失败
cluster-node-timeout 15000 
# 持久化 
appendonly yes 
# 守护进程
daemonize yes   cp /opt/redis/redis-7.2.5/redis.conf /usr/local/redis/conf/redis_7001.conf# 可能需要清空配置文件信息
echo > /usr/local/redis/conf/redis_7001.conf# 添加配置信息 sa
vi /usr/local/redis/conf/redis_7001.conf# 关闭保护模式
protected-mode no
# 添加本机的ip
bind 192.168.1.100
# 端口
port 7001
# pid存储目录
pidfile /usr/local/redis/run/redis_7001.pid
# 日志存储目录
logfile /usr/local/redis/log/redis_7001.log
# 数据存储目录,目录要提前创建好
dir /usr/local/redis/data/7001
# 开启集群 
cluster-enabled yes  
# 集群节点配置文件,这个文件是不能手动编辑的。确保每一个集群节点的配置文件不通
cluster-config-file nodes-7001.conf   
# 持久化 
appendonly yes 
# 守护进程
daemonize yes 

4.2 node-02主机添加配置信息

# 创建对应的文件夹
mkdir -p /usr/local/redis/run
mkdir -p /usr/local/redis/log
mkdir -p /usr/local/redis/data/7000
mkdir -p /usr/local/redis/data/7001
mkdir -p /usr/local/redis/conf# cp 配置文件
cp /opt/redis/redis-7.2.5/redis.conf /usr/local/redis/conf/redis_7000.conf# 可能需要清空配置文件信息
echo > /usr/local/redis/conf/redis_7000.conf# 添加配置信息 master1
vi /usr/local/redis/conf/redis_7000.conf  # 关闭保护模式
protected-mode no
# 添加本机的ip
bind 192.168.1.200
# 端口
port 7000
# pid存储目录
pidfile /usr/local/redis/run/redis_7000.pid
# 日志存储目录
logfile /usr/local/redis/log/redis_7000.log
# 数据存储目录,目录要提前创建好
dir /usr/local/redis/data/7000
# 开启集群 
cluster-enabled yes  
# 集群节点配置文件,这个文件是不能手动编辑的。确保每一个集群节点的配置文件不通
cluster-config-file nodes-7000.conf   
# 持久化 
appendonly yes 
# 守护进程
daemonize yes cp /opt/redis/redis-7.2.5/redis.conf /usr/local/redis/conf/redis_7001.conf# 可能需要清空配置文件信息
echo > /usr/local/redis/conf/redis_7001.conf# 添加配置信息 sa
vi /usr/local/redis/conf/redis_7001.conf# 关闭保护模式
protected-mode no
# 添加本机的ip
bind 192.168.1.200
# 端口
port 7001
# pid存储目录
pidfile /usr/local/redis/run/redis_7001.pid
# 日志存储目录
logfile /usr/local/redis/log/redis_7001.log
# 数据存储目录,目录要提前创建好
dir /usr/local/redis/data/7001
# 开启集群 
cluster-enabled yes  
# 集群节点配置文件,这个文件是不能手动编辑的。确保每一个集群节点的配置文件不通
cluster-config-file nodes-7001.conf   
# 持久化 
appendonly yes 
# 守护进程
daemonize yes 

4.3 node-03主机添加配置信息

# 创建对应的文件夹
mkdir -p /usr/local/redis/run
mkdir -p /usr/local/redis/log
mkdir -p /usr/local/redis/data/7000
mkdir -p /usr/local/redis/data/7001
mkdir -p /usr/local/redis/conf# cp 配置文件
cp /opt/redis/redis-7.2.5/redis.conf /usr/local/redis/conf/redis_7000.conf# 可能需要清空配置文件信息
echo > /usr/local/redis/conf/redis_7000.conf# 添加配置信息 master1
vi /usr/local/redis/conf/redis_7000.conf  # 关闭保护模式
protected-mode no
# 添加本机的ip
bind 192.168.1.250
# 端口
port 7000
# pid存储目录
pidfile /usr/local/redis/run/redis_7000.pid
# 日志存储目录
logfile /usr/local/redis/log/redis_7000.log
# 数据存储目录,目录要提前创建好
dir /usr/local/redis/data/7000
# 开启集群 
cluster-enabled yes  
# 集群节点配置文件,这个文件是不能手动编辑的。确保每一个集群节点的配置文件不通
cluster-config-file nodes-7000.conf 
# 持久化 
appendonly yes 
# 守护进程
daemonize yes cp /opt/redis/redis-7.2.5/redis.conf /usr/local/redis/conf/redis_7001.conf# 可能需要清空配置文件信息
echo > /usr/local/redis/conf/redis_7001.conf# 添加配置信息 sa
vi /usr/local/redis/conf/redis_7001.conf# 关闭保护模式
protected-mode no
# 添加本机的ip
bind 192.168.1.250
# 端口
port 7001
# pid存储目录
pidfile /usr/local/redis/run/redis_7001.pid
# 日志存储目录
logfile /usr/local/redis/log/redis_7001.log
# 数据存储目录,目录要提前创建好
dir /usr/local/redis/data/7001
# 开启集群 
cluster-enabled yes  
# 集群节点配置文件,这个文件是不能手动编辑的。确保每一个集群节点的配置文件不通
cluster-config-file nodes-7001.conf
# 持久化 
appendonly yes 
# 守护进程
daemonize yes 

5. 制作脚本

5.1 编写脚本

# 启动脚本
vi /usr/local/redis/bin/cluster_start.sh#!/bin/bashredis-server /usr/local/redis/conf/redis_7000.conf
redis-server /usr/local/redis/conf/redis_7001.conf# 添加可执行权限
chmod +x /usr/local/redis/bin/cluster_start.sh# 关闭脚本
vi /usr/local/redis/bin/cluster_shutdown.sh#!/bin/bashpgrep redis-server | xargs -exec kill -9# 添加可执行权限
chmod +x /usr/local/redis/bin/cluster_shutdown.sh

5.2 测试脚本

sh /usr/local/redis/bin/cluster_start.sh[root@node-01 ~]# ps -ef | grep redis
root      28167      1  0 20:46 ?        00:00:00 redis-server 192.168.1.100:7001
root      28218      1  0 20:49 ?        00:00:00 redis-server 192.168.1.100:7000
root      28227   9872  0 20:50 pts/0    00:00:00 grep --color=auto redissh /usr/local/redis/bin/cluster_shutdown.sh[root@node-01 ~]# ps -ef | grep redis
root      28234   9872  0 20:51 pts/0    00:00:00 grep --color=auto redis

6. 启动Redis 集群

6.1 启动集群

# 任意一台机器上都可以   得保证每个节点 redis服务是可用状态
redis-cli --cluster create 192.168.1.100:7000 192.168.1.100:7001 192.168.1.200:7000 192.168.1.200:7001 192.168.1.250:7000 192.168.1.250:7001 --cluster-replicas 1[root@node-01 redis]# redis-cli --cluster create 192.168.1.100:7000 192.168.1.100:7001 192.168.1.200:7000 192.168.1.200:7001 192.168.1.250:7000 192.168.1.250:7001 --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 192.168.1.200:7001 to 192.168.1.100:7000
Adding replica 192.168.1.250:7001 to 192.168.1.200:7000
Adding replica 192.168.1.100:7001 to 192.168.1.250:7000
M: a866e2efff44ddaf8b3553037d72d247f35c5b95 192.168.1.100:7000slots:[0-5460] (5461 slots) master
S: 6d4411b05daa67d521eff4128e7ff4dbf1429279 192.168.1.100:7001replicates 9b12bbf161e6166153a448ea400e02bfbf2a7f3b
M: 99e6ca5ed6cd7d15096d553cb0c66ce595c492e3 192.168.1.200:7000slots:[5461-10922] (5462 slots) master
S: 74ad52e17d645ebe3b0b1976be4b6f9091659a88 192.168.1.200:7001replicates a866e2efff44ddaf8b3553037d72d247f35c5b95
M: 9b12bbf161e6166153a448ea400e02bfbf2a7f3b 192.168.1.250:7000slots:[10923-16383] (5461 slots) master
S: 04910d12340a2a982876eaed68dd87a02539c416 192.168.1.250:7001replicates 99e6ca5ed6cd7d15096d553cb0c66ce595c492e3
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 192.168.1.100:7000)
M: a866e2efff44ddaf8b3553037d72d247f35c5b95 192.168.1.100:7000slots:[0-5460] (5461 slots) master1 additional replica(s)
M: 99e6ca5ed6cd7d15096d553cb0c66ce595c492e3 192.168.1.200:7000slots:[5461-10922] (5462 slots) master1 additional replica(s)
M: 9b12bbf161e6166153a448ea400e02bfbf2a7f3b 192.168.1.250:7000slots:[10923-16383] (5461 slots) master1 additional replica(s)
S: 04910d12340a2a982876eaed68dd87a02539c416 192.168.1.250:7001slots: (0 slots) slavereplicates 99e6ca5ed6cd7d15096d553cb0c66ce595c492e3
S: 6d4411b05daa67d521eff4128e7ff4dbf1429279 192.168.1.100:7001slots: (0 slots) slavereplicates 9b12bbf161e6166153a448ea400e02bfbf2a7f3b
S: 74ad52e17d645ebe3b0b1976be4b6f9091659a88 192.168.1.200:7001slots: (0 slots) slavereplicates a866e2efff44ddaf8b3553037d72d247f35c5b95
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.# 如果出现Node xxxx is not empty. Either the node already knows other nodes (check with CLUSTER NODES) or contains some key in database 0.   请删除 appendonly.aof、dump.rdb、node_xxx.conf 这些文件 重新启动redis服务 再执行集群创建命令# 如果出现 [ERR] Node xxxx is not configured as a cluster node.   请检查配置文件是否设置cluster-enabled yes  这个配置项

6.2 查看集群状态

# -c 参数表示以集群模式,否则报 (error) MOVED 9421 192.168.1.100:7000
redis-cli -c -h 192.168.1.100 -p 7000 cluster info[root@node-01 redis]# redis-cli -c  -h 192.168.1.100 -p 7000 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:737
cluster_stats_messages_pong_sent:671
cluster_stats_messages_sent:1408
cluster_stats_messages_ping_received:666
cluster_stats_messages_pong_received:737
cluster_stats_messages_meet_received:5
cluster_stats_messages_received:1408
total_cluster_links_buffer_limit_exceeded:0

6.3 查看集群节点

# -c 参数表示以集群模式,否则报 (error) MOVED 9421 192.168.1.100:7000
redis-cli -c -h 192.168.1.100 -p 7000 cluster nodes[root@node-01 redis]# redis-cli -c -h 192.168.1.100 -p 7000 cluster nodes
99e6ca5ed6cd7d15096d553cb0c66ce595c492e3 192.168.1.200:7000@17000 master - 0 1721181315000 3 connected 5461-10922
9b12bbf161e6166153a448ea400e02bfbf2a7f3b 192.168.1.250:7000@17000 master - 0 1721181316761 5 connected 10923-16383
04910d12340a2a982876eaed68dd87a02539c416 192.168.1.250:7001@17001 slave 99e6ca5ed6cd7d15096d553cb0c66ce595c492e3 0 1721181315736 3 connected
a866e2efff44ddaf8b3553037d72d247f35c5b95 192.168.1.100:7000@17000 myself,master - 0 1721181314000 1 connected 0-5460
6d4411b05daa67d521eff4128e7ff4dbf1429279 192.168.1.100:7001@17001 slave 9b12bbf161e6166153a448ea400e02bfbf2a7f3b 0 1721181312000 5 connected
74ad52e17d645ebe3b0b1976be4b6f9091659a88 192.168.1.200:7001@17001 slave a866e2efff44ddaf8b3553037d72d247f35c5b95 0 1721181316000 1 connected

6.4 测试用例

[root@node-01 redis]# redis-cli -c -h 192.168.1.100 -p 7000
192.168.1.100:7000> set name dongdong
-> Redirected to slot [5798] located at 192.168.1.200:7000
OK[root@node-02 redis]# redis-cli -c -h 192.168.1.200 -p 7000
192.168.1.200:7000> get name
"dongdong"[root@node-03 redis]#  redis-cli -c -h 192.168.1.250 -p 7000
192.168.1.250:7000> get name
-> Redirected to slot [5798] located at 192.168.1.200:7000
"dongdong"
192.168.1.250:7000> del name
-> Redirected to slot [5798] located at 192.168.1.200:7000
(integer) 1

7. 集群扩容节点

扩容时,先增加主节点,再增加从节点

可以在同一个节点 ,也可以在不同节点 ,推荐在不同节点

7.1 node-02

mkdir -p /usr/local/redis/data/7002#  端口 7002
vi /usr/local/redis/conf/redis_7002.conf# 关闭保护模式
protected-mode no
# 添加本机的ip
bind 192.168.1.200
# 端口
port 7002
# pid存储目录
pidfile /usr/local/redis/run/redis_7002.pid
# 日志存储目录
logfile /usr/local/redis/log/redis_7002.log
# 数据存储目录,目录要提前创建好
dir /usr/local/redis/data/7002
# 开启集群 
cluster-enabled yes  
# 集群节点配置文件,这个文件是不能手动编辑的。确保每一个集群节点的配置文件不通
cluster-config-file nodes-7002.conf
# 持久化 
appendonly yes 
# 守护进程
daemonize yes # 启动redis
redis-server /usr/local/redis/conf/redis_7002.conf

7.2 node-03

mkdir -p /usr/local/redis/data/7002#  端口 7002
vi /usr/local/redis/conf/redis_7002.conf# 关闭保护模式
protected-mode no
# 添加本机的ip
bind 192.168.1.250
# 端口
port 7002
# pid存储目录
pidfile /usr/local/redis/run/redis_7002.pid
# 日志存储目录
logfile /usr/local/redis/log/redis_7002.log
# 数据存储目录,目录要提前创建好
dir /usr/local/redis/data/7002
# 开启集群 
cluster-enabled yes  
# 集群节点配置文件,这个文件是不能手动编辑的。确保每一个集群节点的配置文件不通
cluster-config-file nodes-7002.conf
# 持久化 
appendonly yes 
# 守护进程
daemonize yes # 启动redis
redis-server /usr/local/redis/conf/redis_7002.conf

7.3 添加主节点

# 使用redis-cli的add-node命令新增一个主节点192.168.1.200:7002(master),前面的ip:port为新增节点,后面的ip:port为集群中已存在的节点。redis-cli --cluster add-node 192.168.1.200:7002 192.168.1.100:7000root@node-01 redis]# redis-cli --cluster add-node 192.168.1.200:7002 192.168.1.100:7000
>>> Adding node 192.168.1.200:7002 to cluster 192.168.1.100:7000
>>> Performing Cluster Check (using node 192.168.1.100:7000)
M: 9037a70744f728d436a7c37e5e841f3b1ae3f099 192.168.1.100:7000slots:[0-5460] (5461 slots) master1 additional replica(s)
M: a10c431ac4acb90c1da27fd76fd8c3479b32a902 192.168.1.200:7000slots:[5461-10922] (5462 slots) master1 additional replica(s)
S: 844876c169666de7665c51b5bdad01807ee62ae4 192.168.1.200:7001slots: (0 slots) slavereplicates 9037a70744f728d436a7c37e5e841f3b1ae3f099
M: cf6df070f4102a3c5cc8d4577ab30e9dee5906b4 192.168.1.250:7000slots:[10923-16383] (5461 slots) master1 additional replica(s)
S: 55792b63bc0b23b1900b5c9ee03a488f8ed76988 192.168.1.100:7001slots: (0 slots) slavereplicates cf6df070f4102a3c5cc8d4577ab30e9dee5906b4
S: 90f1e06b26cbdcbe884f22aba7fc37e98ca5d58f 192.168.1.250:7001slots: (0 slots) slavereplicates a10c431ac4acb90c1da27fd76fd8c3479b32a902
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
>>> Getting functions from cluster
>>> Send FUNCTION LIST to 192.168.1.200:7002 to verify there is no functions in it
>>> Send FUNCTION RESTORE to 192.168.1.200:7002
>>> Send CLUSTER MEET to node 192.168.1.200:7002 to make it join the cluster.
[OK] New node added correctly.# 查看集群状态
redis-cli --cluster check 192.168.1.100:7000[root@node-01 redis]# redis-cli --cluster check 192.168.1.100:7000
192.168.1.100:7000 (9037a707...) -> 0 keys | 5461 slots | 1 slaves.
192.168.1.200:7000 (a10c431a...) -> 0 keys | 5462 slots | 1 slaves.
192.168.1.250:7000 (cf6df070...) -> 0 keys | 5461 slots | 1 slaves.
192.168.1.200:7002 (990bb934...) -> 0 keys | 0 slots | 0 slaves.
[OK] 0 keys in 4 masters.
0.00 keys per slot on average.
>>> Performing Cluster Check (using node 192.168.1.100:7000)
M: 9037a70744f728d436a7c37e5e841f3b1ae3f099 192.168.1.100:7000slots:[0-5460] (5461 slots) master1 additional replica(s)
M: a10c431ac4acb90c1da27fd76fd8c3479b32a902 192.168.1.200:7000slots:[5461-10922] (5462 slots) master1 additional replica(s)
S: 844876c169666de7665c51b5bdad01807ee62ae4 192.168.1.200:7001slots: (0 slots) slavereplicates 9037a70744f728d436a7c37e5e841f3b1ae3f099
M: cf6df070f4102a3c5cc8d4577ab30e9dee5906b4 192.168.1.250:7000slots:[10923-16383] (5461 slots) master1 additional replica(s)
S: 55792b63bc0b23b1900b5c9ee03a488f8ed76988 192.168.1.100:7001slots: (0 slots) slavereplicates cf6df070f4102a3c5cc8d4577ab30e9dee5906b4
S: 90f1e06b26cbdcbe884f22aba7fc37e98ca5d58f 192.168.1.250:7001slots: (0 slots) slavereplicates a10c431ac4acb90c1da27fd76fd8c3479b32a902
M: 990bb934a52a74ec9ebb2b73e9dc6016244293f6 192.168.1.200:7002slots: (0 slots) master
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.# 注意:当添加节点成功以后,新增的节点不会有任何数据,因为它还没有分配任何的slot(hash槽),我们需要为新节点手工分配hash槽。
# 重新分配槽位
# 注意:槽位迁移后,对应槽位中的数据也会迁移!
redis-cli --cluster reshard 192.168.1.100:7000... ...
How many slots do you want to move (from 1 to 16384)? 800
(ps:需要多少个槽移动到新的节点上,自己设置,比如600个hash槽)
What is the receiving node ID? 990bb934a52a74ec9ebb2b73e9dc6016244293f6  # 192.168.1.200:7002 节点id
(ps:把这600个hash槽移动到哪个节点上去,需要指定节点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:all
(ps:输入all为从所有主节点(7000)中分别抽取相应的槽数指定到新节点中,抽取的总槽数为800个)... ...
Do you want to proceed with the proposed reshard plan (yes/no)? yes
(ps:输入yes确认开始执行分片任务)
... ...

7.4 添加从节点

redis-cli --cluster add-node 192.168.1.250:7002 192.168.1.200:7002[root@node-01 data]# redis-cli --cluster add-node 192.168.1.250:7002 192.168.1.200:7002
>>> Adding node 192.168.1.250:7002 to cluster 192.168.1.200:7002
>>> Performing Cluster Check (using node 192.168.1.200:7002)
M: 990bb934a52a74ec9ebb2b73e9dc6016244293f6 192.168.1.200:7002slots:[0-265],[5461-5727],[10923-11188] (799 slots) master
M: cf6df070f4102a3c5cc8d4577ab30e9dee5906b4 192.168.1.250:7000slots:[11189-16383] (5195 slots) master1 additional replica(s)
S: 90f1e06b26cbdcbe884f22aba7fc37e98ca5d58f 192.168.1.250:7001slots: (0 slots) slavereplicates a10c431ac4acb90c1da27fd76fd8c3479b32a902
S: 55792b63bc0b23b1900b5c9ee03a488f8ed76988 192.168.1.100:7001slots: (0 slots) slavereplicates cf6df070f4102a3c5cc8d4577ab30e9dee5906b4
S: 844876c169666de7665c51b5bdad01807ee62ae4 192.168.1.200:7001slots: (0 slots) slavereplicates 9037a70744f728d436a7c37e5e841f3b1ae3f099
M: a10c431ac4acb90c1da27fd76fd8c3479b32a902 192.168.1.200:7000slots:[5728-10922] (5195 slots) master1 additional replica(s)
M: 9037a70744f728d436a7c37e5e841f3b1ae3f099 192.168.1.100:7000slots:[266-5460] (5195 slots) master1 additional replica(s)
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
>>> Getting functions from cluster
>>> Send FUNCTION LIST to 192.168.1.250:7002 to verify there is no functions in it
>>> Send FUNCTION RESTORE to 192.168.1.250:7002
>>> Send CLUSTER MEET to node 192.168.1.250:7002 to make it join the cluster.
[OK] New node added correctly.# 挂载节点 在挂在节点上执行
# 990bb934a52a74ec9ebb2b73e9dc6016244293f6 id  192.168.1.200:7002 主节点id 
redis-cli -c -h 192.168.1.250 -p 7002 cluster replicate  990bb934a52a74ec9ebb2b73e9dc6016244293f6[root@node-03 data]# redis-cli -c -h 192.168.1.250 -p 7002 cluster replicate  990bb934a52a74ec9ebb2b73e9dc6016244293f6
OK# 此时查看集群节点数
redis-cli -c -h 192.168.1.100 -p 7000 cluster nodes[root@node-01 redis]# redis-cli -c -h 192.168.1.100 -p 7000 cluster nodes
a10c431ac4acb90c1da27fd76fd8c3479b32a902 192.168.1.200:7000@17000 master - 0 1721207538000 3 connected 5728-10922
844876c169666de7665c51b5bdad01807ee62ae4 192.168.1.200:7001@17001 slave 9037a70744f728d436a7c37e5e841f3b1ae3f099 0 1721207539000 1 connected
cf6df070f4102a3c5cc8d4577ab30e9dee5906b4 192.168.1.250:7000@17000 master - 0 1721207542440 5 connected 11189-16383
9037a70744f728d436a7c37e5e841f3b1ae3f099 192.168.1.100:7000@17000 myself,master - 0 1721207541000 1 connected 266-5460
55792b63bc0b23b1900b5c9ee03a488f8ed76988 192.168.1.100:7001@17001 slave cf6df070f4102a3c5cc8d4577ab30e9dee5906b4 0 1721207541000 5 connected
90f1e06b26cbdcbe884f22aba7fc37e98ca5d58f 192.168.1.250:7001@17001 slave a10c431ac4acb90c1da27fd76fd8c3479b32a902 0 1721207540400 3 connected
6c15b61a14a10fdc8b122708b6240b9fe3cbb2f6 192.168.1.250:7002@17002 master - 0 1721207541422 0 connected
990bb934a52a74ec9ebb2b73e9dc6016244293f6 192.168.1.200:7002@17002 master - 0 1721207540000 7 connected 0-265 5461-5727 10923-11188
[root@node-01 redis]# redis-cli -c -h 192.168.1.100 -p 7000 cluster nodes
a10c431ac4acb90c1da27fd76fd8c3479b32a902 192.168.1.200:7000@17000 master - 0 1721207800010 3 connected 5728-10922
844876c169666de7665c51b5bdad01807ee62ae4 192.168.1.200:7001@17001 slave 9037a70744f728d436a7c37e5e841f3b1ae3f099 0 1721207800000 1 connected
cf6df070f4102a3c5cc8d4577ab30e9dee5906b4 192.168.1.250:7000@17000 master - 0 1721207796000 5 connected 11189-16383
9037a70744f728d436a7c37e5e841f3b1ae3f099 192.168.1.100:7000@17000 myself,master - 0 1721207799000 1 connected 266-5460
55792b63bc0b23b1900b5c9ee03a488f8ed76988 192.168.1.100:7001@17001 slave cf6df070f4102a3c5cc8d4577ab30e9dee5906b4 0 1721207801000 5 connected
90f1e06b26cbdcbe884f22aba7fc37e98ca5d58f 192.168.1.250:7001@17001 slave a10c431ac4acb90c1da27fd76fd8c3479b32a902 0 1721207800000 3 connected
6c15b61a14a10fdc8b122708b6240b9fe3cbb2f6 192.168.1.250:7002@17002 slave 990bb934a52a74ec9ebb2b73e9dc6016244293f6 0 1721207798981 7 connected
990bb934a52a74ec9ebb2b73e9dc6016244293f6 192.168.1.200:7002@17002 master - 0 1721207801033 7 connected 0-265 5461-5727 10923-11188
# 至此集群扩容完毕

7.5 集群缩容节点

注意:先将缩容节点槽位信息移动到其他master 如果不这么操作 可能会导致槽位数据丢失

# 删除信息之前查询集群中的节点数量
redis-cli -c -h 192.168.1.100 -p 7000 cluster nodes
[root@node-01 redis]# redis-cli -c -h 192.168.1.100 -p 7000 cluster nodes
a10c431ac4acb90c1da27fd76fd8c3479b32a902 192.168.1.200:7000@17000 master - 0 1721208952176 3 connected 5728-10922
844876c169666de7665c51b5bdad01807ee62ae4 192.168.1.200:7001@17001 slave 9037a70744f728d436a7c37e5e841f3b1ae3f099 0 1721208951000 1 connected
cf6df070f4102a3c5cc8d4577ab30e9dee5906b4 192.168.1.250:7000@17000 master - 0 1721208953000 5 connected 11189-16383
9037a70744f728d436a7c37e5e841f3b1ae3f099 192.168.1.100:7000@17000 myself,master - 0 1721208949000 1 connected 266-5460
55792b63bc0b23b1900b5c9ee03a488f8ed76988 192.168.1.100:7001@17001 slave cf6df070f4102a3c5cc8d4577ab30e9dee5906b4 0 1721208953199 5 connected
90f1e06b26cbdcbe884f22aba7fc37e98ca5d58f 192.168.1.250:7001@17001 slave a10c431ac4acb90c1da27fd76fd8c3479b32a902 0 1721208953000 3 connected
6c15b61a14a10fdc8b122708b6240b9fe3cbb2f6 192.168.1.250:7002@17002 slave 990bb934a52a74ec9ebb2b73e9dc6016244293f6 0 1721208954216 7 connected
990bb934a52a74ec9ebb2b73e9dc6016244293f6 192.168.1.200:7002@17002 master - 0 1721208950131 7 connected 0-265 5461-5727 10923-11188# 把192.168.1.200:7002的槽位信息分配给192.168.1.100:7000
redis-cli --cluster reshard 192.168.1.100:7000[OK] All 16384 slots covered.
How many slots do you want to move (from 1 to 16384)? 800
What is the receiving node ID? 9037a70744f728d436a7c37e5e841f3b1ae3f099 #192.168.1.100:7000 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: 990bb934a52a74ec9ebb2b73e9dc6016244293f6
(ps:这里是需要数据源,也就是我们的192.168.1.200:7002节点id)
Source node 2:done
(ps:这里直接输入done 开始生成迁移计划)
Do you want to proceed with the proposed reshard plan (yes/no)? Yes
(ps:这里输入yes开始迁移)# 删除 192.168.1.200:7002 	主节点
redis-cli --cluster del-node 192.168.1.200:7002 990bb934a52a74ec9ebb2b73e9dc6016244293f6[root@node-01 redis]# redis-cli --cluster del-node 192.168.1.200:7002 990bb934a52a74ec9ebb2b73e9dc6016244293f6
>>> Removing node 990bb934a52a74ec9ebb2b73e9dc6016244293f6 from cluster 192.168.1.200:7002
>>> Sending CLUSTER FORGET messages to the cluster...
>>> Sending CLUSTER RESET SOFT to the deleted node.# 删除 192.168.1.250:7002   从节点
redis-cli --cluster del-node 192.168.1.250:7002 6c15b61a14a10fdc8b122708b6240b9fe3cbb2f6[root@node-01 redis]# redis-cli --cluster del-node 192.168.1.250:7002 6c15b61a14a10fdc8b122708b6240b9fe3cbb2f6
>>> Removing node 6c15b61a14a10fdc8b122708b6240b9fe3cbb2f6 from cluster 192.168.1.250:7002
>>> Sending CLUSTER FORGET messages to the cluster...
>>> Sending CLUSTER RESET SOFT to the deleted node.# 再次查看节点数量
redis-cli -c -h 192.168.1.100 -p 7000 cluster nodes
[root@node-01 redis]# redis-cli -c -h 192.168.1.100 -p 7000 cluster nodes
a10c431ac4acb90c1da27fd76fd8c3479b32a902 192.168.1.200:7000@17000 master - 0 1721209888104 3 connected 5728-10922
844876c169666de7665c51b5bdad01807ee62ae4 192.168.1.200:7001@17001 slave 9037a70744f728d436a7c37e5e841f3b1ae3f099 0 1721209889128 8 connected
cf6df070f4102a3c5cc8d4577ab30e9dee5906b4 192.168.1.250:7000@17000 master - 0 1721209887085 5 connected 11189-16383
9037a70744f728d436a7c37e5e841f3b1ae3f099 192.168.1.100:7000@17000 myself,master - 0 1721209887000 8 connected 0-5727 10923-11188
55792b63bc0b23b1900b5c9ee03a488f8ed76988 192.168.1.100:7001@17001 slave cf6df070f4102a3c5cc8d4577ab30e9dee5906b4 0 1721209890146 5 connected
90f1e06b26cbdcbe884f22aba7fc37e98ca5d58f 192.168.1.250:7001@17001 slave a10c431ac4acb90c1da27fd76fd8c3479b32a902 0 1721209889000 3 connected# 已经成功移除节点

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/diannao/50016.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

React前端面试每日一试 3.状态(State)和属性(Props)的区别是什么?

加粗样式先简单介绍一下Props和State的特点 Props(属性) Props(Properties)是React组件间传递数据的一种方式。它们是从父组件传递给子组件的只读数据,子组件不能修改这些数据。Props主要用于配置组件,使…

Java开发之反射与动态代理

#来自ゾフィー(佐菲) 1 反射(Reflect) 运行期间,获取类的信息,进行一些操作。 运行时构造类的对象。运行时获取类的成员变量和方法。运行时调用对象的方法(属性)。 2 Class 类 Cla…

IntelliJ IDEA 2024.1.4最新实用教程!!爽到飞起!!

IntelliJ IDEA 2024.1.4最新破解教程!!直接2099!!爽到飞起!!【资源在末尾】安装馆长为各位看官准备了多个版本,看官可根据自己的需求进行下载和选择安装。https://mp.weixin.qq.com/s/oBgoHdFU4…

视图,存储过程和触发器

目录 视图 创建视图: 视图的使用 查看库中所有的视图 删除视图 视图的作用: 存储过程: 为什么使用存储过程? 什么是存储过程? 存储过程的创建 创建一个最简单的存储过程 使用存储过程 删除存储过程 带参的存储…

探索Transformer在目标检测的革命:超越传统CNN的边界

探索Transformer在目标检测的革命:超越传统CNN的边界 在深度学习领域,卷积神经网络(CNN)长期以来一直是图像处理任务的主力军,尤其是在目标检测领域。然而,随着Transformer模型的兴起,这一局面…

前端面试宝典【Javascript篇】【1】

欢迎来到《前端面试宝典》,这里是你通往互联网大厂的专属通道,专为渴望在前端领域大放异彩的你量身定制。通过本专栏的学习,无论是一线大厂还是初创企业的面试,都能自信满满地展现你的实力。 核心特色: 独家实战案例…

VMare centos 7 设置固定ip

第一步获取网关 查看虚拟机的网关-》编辑-》虚拟网络编辑器 NAT模式-》NAT设置 获取网关IP 192.168.70.2 第二步获取主机dns1 在本地主机获取dns1,本地主机调出cmd输入ipconfig dns1为192.168.31.1 用管理员权限的账号进入需要设置固定ip的虚拟机,在t…

使用AOP优化Spring Boot Controller参数:自动填充常用字段的技巧

欢迎来到我的博客,代码的世界里,每一行都是一个故事 🎏:你只管努力,剩下的交给时间 🏠 :小破站 使用AOP优化Spring Boot Controller参数:自动填充常用字段的技巧 前言为什么使用AOP为…

java8函数式编程学习(二):optional,函数式接口和并行流的学习

简介 java8函数式编程中optional的简单使用,函数式接口的了解,并行流的使用。 optional 可以更优雅的来避免空指针异常。类似于包装类,把具体的数据封装到optional对象内部,然后使用optional的方法去操作封装好的数据。 创建o…

Python编程入门指南:从基础到高级

Python编程入门指南:从基础到高级 一、Python编程语言简介 1. Python是什么? Python是一门广泛使用的计算机程序编程语言,由荷兰人吉多范罗苏姆(Guido van Rossum)于1991年首次发行。Python是一种解释型、交互式、面…

汽车免拆诊断案例 | 2018 款别克阅朗车蓄电池偶尔亏电

故障现象 一辆2018款别克阅朗车,搭载LI6发动机和GF6变速器,累计行驶里程约为9.6万km。车主反映,该车停放一晚后,蓄电池偶尔亏电。 故障诊断 接车后用虹科Pico汽车示波器和高精度电流钳(30 A)测量该车的寄…

Spring AOP(2)原理(代理模式和源码解析)

目录 一、代理模式 二、静态代理 三、动态代理 1、JDK动态代理 (1)JDK动态代理实现步骤 (2)定义JDK动态代理类 (3)代码简单讲解 2、CGLIB动态代理 (1)CGLIB 动态代理类实现…

k8s中的重启策略

一、k8s的pod,kill进程和上节点停止容器,容器是否被重启(重启策略为OnFailure): 解释:docker ps -a看到容器退出码为: kill进程,其容器退出码为:exit(137)stop 容器&am…

【数据结构】稀疏数组

问题引导 在编写五子棋程序的时候,有“存盘退出”和“续上盘”的功能。现在我们要把一个棋盘保存起来,容易想到用二维数组的方式把棋盘表示出来,但是由于在数组中很多数值取默认值0,因此记录了很多没有意义的数据。此时我们使用稀…

Apache压测工具ab(Apache Bench)工具的下载安装和使用示例

场景 Jmeter进行http接口压力测试: Jmeter进行http接口压力测试_接口压测两万量-CSDN博客 上面讲压测工具Jmeter的使用,下面介绍另外一个ab(Apache Bench)压测工具的使用。 apache bench apache bench是apache自带的压力测试工具。 ab不仅可以对ap…

构件组装不兼容-系统架构师(三十三)

1、(系统工程与信息系统基础->信息系统战略规划)企业信息化程度是国家信息化建设的基础和关键,企业信息化方法不包括()。 A业务流程重组 B组织机构变革 C供应链管理 D人力资本投入 解析: 企业信息化…

CSS 创建:从入门到精通

CSS 创建:从入门到精通 CSS(层叠样式表)是网页设计中不可或缺的一部分,它用于控制网页的布局和样式。本文将详细介绍CSS的创建过程,包括基本概念、语法结构、选择器、样式属性以及如何将CSS应用到HTML中。无论您是初学者还是有经验的开发者,本文都将为您提供宝贵的信息。…

awk的模式

在awk 中,匹配模式处于非常重要的地位,它决定着匹配模式后面的操作会影响到哪些文本行。 awk 中 的匹配模式主要包括关系表达式、正则表达式、混合模式, BEGIN 模式以及 END 模式等。 ( 1 )关系表达式 awk 提供了许…

localSorage,sessionStorage,cookie三者的区别和特点

LocalStorage、SessionStorage、Cookie三者的区别和特点? 什么是Cookie HTTP协议本身是无状态的。什么是无状态呢,即服务器无法判断用户身份。 Cookie实际上是一小段的文本信息(key-value格式)。客户端向服务器发起请求,如果服务…

培训第十三天(DNS逆向解析与主从服务、ntp时间服务器)

上午 编号主机名ip地址说明修改1web服务器10.0.0.10发布部署web服务发布了一个nginx web服务2dns服务器10.0.0.11用于解析域名和ip地址1、安装bind 2、配置一个conf,zones,zone 3、检查了3个文件,启动3cli主机10.0.0.12用于模拟客户机修改了…