首页 > 数据库 >redis单节点移动到集群

redis单节点移动到集群

时间:2023-01-02 14:33:23浏览次数:40  
标签:cli -- redis 11.0 cluster 集群 节点

redis部署
1.redis下载
wget https://download.redis.io/releases/redis-6.2.8.tar.gz

2.安装
yum install -y gcc
tar -xzvf redis-6.2.8.tar.gz
cd redis-6.2.8
make
make install PREFIX=/usr/local/redis6

 


redis cluster部署
protected-mode no
logfile "/data/redis6379/redis.log"
dir /data/redis6379
cluster-enabled yes
cluster-config-file nodes-6379.conf
cluster-node-timeout 15000
io-threads-do-reads yes
io-threads 4

#数据库必须为空flushdb
redis-cli --cluster create 11.0.1.141:6379 11.0.1.142:6379 11.0.1.143:6379 11.0.1.142:6380 11.0.1.143:6380 11.0.1.141:6380 --cluster-replicas 1 -a "123456"

 

#添加用户
acl setuser lucy on >112233 ~* &* +get

#数据迁移
#单节点,aof文件拷贝到集群
BGREWRITEAOF
lastsave

#节点检查
redis-cli --cluster check 11.0.1.141:6379 -a 123456

#节点2的master迁移到节点1master
redis-cli --cluster reshard 11.0.1.141:6379 --cluster-from 905c96bb114deaa5207bf4d39eacb765d98e64e8 --cluster-to cdfabcd560f11b336cc7bc63a37dff2e3f8ddcd5 --cluster-slots 5461 --cluster-yes -a 123456

#节点3的master迁移到节点1master
redis-cli --cluster reshard 11.0.1.141:6379 --cluster-from d9ebb04ca87b38cb492f361a22ed1080648abccf --cluster-to cdfabcd560f11b336cc7bc63a37dff2e3f8ddcd5 --cluster-slots 5461 --cluster-yes -a 123456


#停止redis集群,将单实例的aof文件拷贝到节点1的目录
cp appendonly.aof 节点1

#将节点1的槽位分配给Master2
redis-cli --cluster reshard 11.0.1.141:6379 --cluster-from cdfabcd560f11b336cc7bc63a37dff2e3f8ddcd5 --cluster-to 905c96bb114deaa5207bf4d39eacb765d98e64e8 --cluster-slots 5462 --cluster-yes -a 123456


#将节点1的槽位分配给Master3
redis-cli --cluster reshard 11.0.1.141:6379 --cluster-from cdfabcd560f11b336cc7bc63a37dff2e3f8ddcd5 --cluster-to d9ebb04ca87b38cb492f361a22ed1080648abccf --cluster-slots 5461 --cluster-yes -a 123456


#槽位移动报错

 


#关闭redis集群
#拷贝文件到节点1master

#启动集群,重新分配槽位

 

redis-cli --cluster help
#删除节点
redis-cli --cluster del-node 11.0.1.141:6379 a2d3ab56b231d5ba09eabe72dab4d6ab35b9a832 -a 123456
#新增主节点
redis-cli --cluster add-node 新增节点:port 集群节点:port
#新增从节点
redis-cli --cluster add-node 新增节点:port 集群节点:port --cluster-slave --cluster-master-id 主节点id -a
#新增从节点
redis-cli --cluster add-node 11.0.1.143:6380 11.0.1.141:6379 --cluster-slave --cluster-master-id 905c96bb114deaa5207bf4d39eacb765d98e64e8 -a 123456

标签:cli,--,redis,11.0,cluster,集群,节点
From: https://www.cnblogs.com/52shaidan/p/17019859.html

相关文章