Redis local cluster structures (5 or later)

Redis local cluster structures (5 or later)

November 3, 2019 10:05:48

step

1, download and install Redis installation package

2, 5 parts of replication, a total of 6 parts Redis decompressed installations, and modify the port opening for each node and node Redis

3, modify the port Redis each node, as well as open cluster model

3, using redis-cli --cluster create ip: port assigned to the node cluster hash grooves (If you are using the master from the master node just add ip: port can)

4, using redis-cli --cluster check ip: port View node information

5、使用redis-cli --cluster add-node node-ip:node-port master-ip:master-port --cluster-slave --cluster-master-id master节点id

Implementation

1, the compiler

Redis download and install installation package

wget http://download.redis.io/releases/redis-5.0.6.tar.gz

Extracting installation package

tar zxf redis-5.0.6.tar.gz

After extracting the files into a folder

QQ screenshot 20191103144705

ps: before compilation, the server needs to be installed gcc

yum install gcc-c++

Enter the make command to compile, appear the following figure represents a successful compilation tips

QQ screenshot 20191103145058

You can also specify the location compiled

make install PREFIX=path

Compiled files

QQ screenshot 20191103145746

2, copy and modify the configuration, open

Use the copy command

cp -rf 文件夹路径 文件夹路径

effect

QQ screenshot 20191103150602

Redis.conf modify the configuration to each copy of a redis are modified to a different port, start the background

# 默认
daemonize no
port 6379
# cluster-enabled yes

#修改
daemonize yes
port 7001
cluster-enabled yes

Turn on each node (batch execution)

cd /software/redis/redis6379/bin
./redis-server ./redis.conf
cd /software/redis/redis7000/bin
./redis-server ./redis.conf
cd /software/redis/redis7001/bin
./redis-server ./redis.conf
cd /software/redis/redis7002/bin
./redis-server ./redis.conf
cd /software/redis/redis7003/bin
./redis-server ./redis.conf
cd /software/redis/redis7004/bin
./redis-server ./redis.conf

All nodes appear next figure shows the success of open

QQ screenshot 20191103151400

3, the hash slot allocation

Use the following command

redis-cli --cluster create ip:port ip:port ip:port

QQ screenshot 20191103151606

4, view the assignment information

Use the command redis-cli --cluster check ip: port to view the distribution of information

QQ screenshot 20191103152330

As can be seen, 6379 is assigned to the 0-5460,7001 5461-10922,7003 is 10923-16383.

5, the node is added

Use the command

redis-cli --cluster add-node node-ip:node-port master-ip:master-port --cluster-slave --cluster-master-id master节点id

QQ screenshot 20191103152840

After the addition is complete view node information

cluster nodes

QQ screenshot 20191103152935

As can be seen from the figure, 3 is provided from the main pattern 3 clusters.

6, test key

Connecting redis (-c indicates a trunked mode)

redis-cli -p 6379 -c

QQ screenshot 20191103153704

As can be seen, the addition of the key ports on the node 6379 by key algorithm forwards this to the port on the node 7001.

Into the node port 7001, can be found the key value.

At the same time, 7001 has received from the node port to the key value.

7, test Sentinel

Use ps aux | grep redis redis query each node port

QQ screenshot 20191103153842

This time between the master node is normal

QQ screenshot 20191103153929

Close port 7001 of node

QQ screenshot 20191103154106

QQ screenshot 20191103154040

7002 7001 port node automatically upgraded from a node to the master node.

Re-open the 7001 node, automatically demoted to slave.

QQ screenshot 20191103154314


Horizontal scaling Redis high availability cluster

The master node expansion

New port Redis nodes 7005 and 7006 and run.

QQ screenshot 20191103155441

The vessel was added 7005 nodes

redis-cli --cluster add-node 127.0.0.1:7005 127.0.0.1:6379

QQ screenshot 20191103160806

Hash slot assigned to nodes 7005

从7001节点分配1000个哈希槽给7005节点
all表示均匀分配(从每个节点取一点哈希槽出来)
done表示从当前节点取

[root@iz2zeaf5jdjve80rjlsjgnz bin]# redis-cli --cluster reshard 127.0.0.1:7001
>>> Performing Cluster Check (using node 127.0.0.1:7001)
S: 152f1f15ac36784362e8733a393c9a257f7a8ba2 127.0.0.1:7001
   slots: (0 slots) slave
   replicates f9129fca620934624742e25a31d08c545a9d583e
S: ac613c6d40e0d860662effb7403a67fe9b6029aa 127.0.0.1:7000
   slots: (0 slots) slave
   replicates 77cbdfe644fdc0e50e550cad44a3ed144c8d2499
M: f9129fca620934624742e25a31d08c545a9d583e 127.0.0.1:7002
   slots:[5962-10922] (4961 slots) master
   1 additional replica(s)
S: 09ede6784ccc5a41b82db3fe4c544b5c126f455e 127.0.0.1:7004
   slots: (0 slots) slave
   replicates bd08af40b95169524c27da654302c9f12d8a9e8c
M: bd08af40b95169524c27da654302c9f12d8a9e8c 127.0.0.1:7003
   slots:[11422-16383] (4962 slots) master
   1 additional replica(s)
M: 6c87fc578eec8bd7d588d111347dd7a7bd21dd0b 127.0.0.1:7005
   slots: (0 slots) master
M: 77cbdfe644fdc0e50e550cad44a3ed144c8d2499 127.0.0.1:6379
   slots:[0-5961],[10923-11421] (6461 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)? 1000
What is the receiving node ID? 6c87fc578eec8bd7d588d111347dd7a7bd21dd0b
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

Ready to move 1000 slots.

QQ screenshot 20191103161734

Expanded from node

Add Redis 7006 nodes in the cluster.

 redis-cli --cluster add-node 127.0.0.1:7006 127.0.0.1:7005 --cluster-slave --cluster-master-id 6c87fc578eec8bd7d588d111347dd7a7bd21dd0b

QQ screenshot 20191103162309

reference

Redis entry (for novice)

redis Cluster Setup (in great detail, suitable for beginners)

Redis5 cluster designated artificial master-slave relationship

Horizontal scaling Redis 5 high availability cluster

Guess you like

Origin www.cnblogs.com/Rlxy93/p/11811146.html