当前位置:网站首页>Redis cluster creation, capacity expansion and capacity reduction
Redis cluster creation, capacity expansion and capacity reduction
2022-07-03 06:10:00 【vincentwc】
Pull the mirror image
```bash
docker pull redis:6.0.8
```
establish redis Cluster container
perform docker command
```bash
docker run -d --name redis-node-1 --net host --privileged=true -v /data/redis/share/redis-node-1:/data redis:6.0.8 --cluster-enabled yes --appendonly yes --port 6381
docker run -d --name redis-node-2 --net host --privileged=true -v /data/redis/share/redis-node-2:/data redis:6.0.8 --cluster-enabled yes --appendonly yes --port 6382
docker run -d --name redis-node-3 --net host --privileged=true -v /data/redis/share/redis-node-3:/data redis:6.0.8 --cluster-enabled yes --appendonly yes --port 6383
docker run -d --name redis-node-4 --net host --privileged=true -v /data/redis/share/redis-node-4:/data redis:6.0.8 --cluster-enabled yes --appendonly yes --port 6384
docker run -d --name redis-node-5 --net host --privileged=true -v /data/redis/share/redis-node-5:/data redis:6.0.8 --cluster-enabled yes --appendonly yes --port 6385
docker run -d --name redis-node-6 --net host --privileged=true -v /data/redis/share/redis-node-6:/data redis:6.0.8 --cluster-enabled yes --appendonly yes --port 6386
```

Into the container
```bash
docker exec -ti redis-node-1 /bin/bash
```
Execute the following command
redis-cli --cluster create 10.255.237.120:6381 10.255.237.120:6382 10.255.237.120:6383 10.255.237.120:6384 10.255.237.120:6385 10.255.237.120:6386 --cluster-replicas 1

Input yes after

- At this time, the representative has been successfully created
View the cluster
stay redis-node-1 Execute the following commands in the container
redis-cli -p 6381 -c
Check it with the following command redis Cluster situation
```bash
cluster info
cluster nodes
```
redis Cluster expansion cases 【 Expansion from three masters and three slaves to four masters and four slaves 】
The implementation is as follows docker command
```bash
docker run -d --name redis-node-7 --net host --privileged=true -v /data/redis/share/redis-node-7:/data redis:6.0.8 --cluster-enabled yes --appendonly yes --port 6387
docker run -d --name redis-node-8 --net host --privileged=true -v /data/redis/share/redis-node-8:/data redis:6.0.8 --cluster-enabled yes --appendonly yes --port 6388
```
Get into 6387 Instance internal
Will add 6387 node ( Empty slot number ) As master The node joins the original cluster
```bash
redis-cli --cluster add-node 10.255.237.120:6387 10.255.237.120:6381
```

Use the following command to check 6387 The node has joined , However, you can see that no slots are allocated
redis-cli --cluster check 10.255.237.120:6381

Reassign slot numbers
redis-cli --cluster reshard 10.255.237.120:6381
0-16383 Number selection of interval
16383/master Number of nodes , This selection is 4096
choice all
redis-cli --cluster check 10.255.237.120:6381
Perform discovery , The newly added master node is to evenly slot each node of the previous master node to the new master node , Instead of reallocating them all

Master node 6387 Assign slave nodes 6388
cluster-master-id by 6387 The number of
redis-cli --cluster add-node 10.255.237.120:6388 10.255.237.120:6387 --cluster-slave --cluster-master-id 135f091ecb2b7eade2d472c2589413fda8c6926b


thus , Expansion completed

Shrinkage capacity 【 Delete 6387-6388】
When you shrink , You should delete the slave first , Then delete the host
perform redis-cli --cluster check 10.255.237.120:6381 command , obtain 6388 node id, Here's the picture

The command to delete a node is as follows
redis-cli --cluster del-node 10.255.237.120:6388 50acca20c6240f83e81c1a5de2a0c17e3dbda523
Reassign the slot number to the cluster
redis-cli --cluster reshard 10.255.237.120:6381

take 6387 All slot numbers of are assigned to other nodes , Assigned here to 6382 了
As shown in the figure below 6387 The slot of is 0 了

Delete node
6387 The slots of have been allocated , Now you can delete 6387 The node
redis-cli --cluster del-node 10.255.237.120:6387 135f091ecb2b7eade2d472c2589413fda8c6926b
Check the cluster
redis-cli --cluster check 10.255.237.120:6381
thus ,redis Cluster creation , Capacity expansion , The volume reduction operation is finished
边栏推荐
- Apt update and apt upgrade commands - what is the difference?
- Cesium entity(entities) 实体删除方法
- Zhiniu stock project -- 05
- Jedis source code analysis (II): jediscluster module source code analysis
- 为什么网站打开速度慢?
- Simple handwritten ORM framework
- Loss function in pytorch multi classification
- 70 shell script interview questions and answers
- 【系统设计】邻近服务
- [teacher Zhao Yuqiang] MySQL flashback
猜你喜欢

深入解析kubernetes controller-runtime

Merge and migrate data from small data volume, sub database and sub table Mysql to tidb

Simple solution of small up main lottery in station B

Oauth2.0 - Introduction and use and explanation of authorization code mode

pytorch 搭建神经网络最简版

Kubernetes notes (IX) kubernetes application encapsulation and expansion

智牛股项目--04

Loss function in pytorch multi classification

Cesium 点击获取模型表面经纬度高程坐标(三维坐标)

Synthetic keyword and NBAC mechanism
随机推荐
CKA certification notes - CKA certification experience post
In depth analysis of kubernetes controller runtime
88. 合并两个有序数组
輕松上手Fluentd,結合 Rainbond 插件市場,日志收集更快捷
1. 两数之和
pytorch DataLoader实现miniBatch(未完成)
Oauth2.0 - use database to store client information and authorization code
BeanDefinitionRegistryPostProcessor
[teacher Zhao Yuqiang] the most detailed introduction to PostgreSQL architecture in history
CAD插件的安装和自动加载dll、arx
Zhiniu stock project -- 05
Understand expectations (mean / estimate) and variances
Kubernetes notes (I) kubernetes cluster architecture
CAD插件的安裝和自動加載dll、arx
Interesting research on mouse pointer interaction
轻松上手Fluentd,结合 Rainbond 插件市场,日志收集更快捷
Oauth2.0 - explanation of simplified mode, password mode and client mode
GPS坐标转百度地图坐标的方法
Disruptor learning notes: basic use, core concepts and principles
PMP notes