当前位置:网站首页>Set up redis highly available cluster environment

Set up redis highly available cluster environment

2022-06-11 09:21:00 Asurplus、

First, set up a stand-alone version Redis Environmental Science , Please refer to my blog :Centos7 Build in Redis Environmental Science

1、 preparation

When it's set up , In the catalog /usr/local/redis/ Next , newly build myredis Catalog

mkdir myredis

Get into myredis Directory , newly build 6 A folder , Use the port to name , for example :

mkdir redis7000

mkdir redis7005

So now we have 6 A folder

2、 Basic configuration information

We from /usr/local/redis/bin/ Under the table of contents , Copy a configuration file , Modify the configuration

#  port 
port 7000
#  Daemon mode starts 
daemonize yes
#  Externally connectable , Cloud server , Just write on the intranet 
# bind 127.0.0.1
#  Externally owned IP Address access 
protected-mode no
#  Process documents , Differentiate by port number 
pidfile /var/run/redis_7000.pid
logfile “/usr/local/redis/myredis/redis7000/redis.log”
#  Persistent file storage location 
dir /usr/local/redis/myredis/redis7000/

3、 Cluster configuration information

#  Start in a cluster 
cluster-enabled yes
#  Cluster configuration information file 
cluster-config-file nodes-7000.conf
#  Timeout time 
cluster-node-timeout 15000
cluster-replica-validity-factor 10
cluster-migration-barrier 1

preservation , sign out

4、 Copy profile

We have changed it 7000 Configuration file of port instance , We use commands , Mass replacement

sed 's/7000/7001/g' redis7000/redis.conf > redis7001/redis.conf

sed 's/7000/7005/g' redis7000/redis.conf > redis7005/redis.conf

That's right. redis7001 I got a share in it redis.conf file , The port inside is from 7000 replaced 7001, Repeat the command

5、 Boot instance

/usr/local/redis/bin/redis-server /usr/local/redis/myredis/redis7000/redis.conf

/usr/local/redis/bin/redis-server /usr/local/redis/myredis/redis7005/redis.conf


start-up 6 An example , see redis Operation of the

ps -ef | grep redis

 Insert picture description here
It can be seen that , All instances are started in a cluster mode

6、 Create clusters

/usr/local/redis/bin/redis-cli --cluster create 127.0.0.1:7000 127.0.0.1:7001 127.0.0.1:7002 127.0.0.1:7003 127.0.0.1:7004 127.0.0.1:7005 --cluster-replicas 1
  • –cluster-replicas 1 Indicates the master-slave ratio 1:1, In this way, we get a cluster environment with three masters and three slaves

7、 Sign in Redis

/usr/local/redis/bin/redis-cli -h 127.0.0.1 -p 7000

View node information

cluster nodes

 Insert picture description here
You can see Node information of three masters and three slaves

8、 Add a node

  • 1、 Add master
/usr/local/redis/bin/redis-cli --cluster add-node 127.0.0.1:7006 127.0.0.1:7000
  • add-node: Add a node
  • 127.0.0.1:7006: Added node ip:port
  • 127.0.0.1:7000: Any node of the cluster already exists ip:port
  • 2、 Add slave node
/usr/local/redis/bin/redis-cli --cluster add-node 127.0.0.1:7007 127.0.0.1:7000 --cluster-slave --cluster-master-id nodeId
  • add-node: Add a node
  • 127.0.0.1:7007: Added node ip:port
  • 127.0.0.1:7000: Any node of the cluster already exists ip:port
  • –cluster-slave: Add as slave node
  • –cluster-master-id: Master node id

9、 Capacity expansion

Our cluster has the concept of slots , left-off key After passing the algorithm , Determine which node it will eventually be stored in , The total slots are 16384 individual , from 0 - 16383.

/usr/local/redis/bin/redis-cli --cluster reshard 127.0.0.1:7000
  • reshard: Assign slots
  • 127.0.0.1:7000: Any node of the cluster already exists ip:port

Input : Allocate the size of the slot , This depends on the actual situation

Input : The distribution of nodeId

Input : From which master Nodes are allocated , There are three options :all( All , Average distribution )、nodeId( Of a specific node id)、done( The final allocation is completed )

Input :yes

10、 Shrinkage capacity

/usr/local/redis/bin/redis-cli --cluster reshard --cluster-from outNodeId--cluster-slots quantity inNode ip:port
  • outNodeId: Migrated nodes id
  • quantity: The amount moved out
  • inNode ip:port: Immigrated ip:port

Input : Received nodeId
Input :yes

11、 Delete node

/usr/local/redis/bin/redis-cli --cluster del-node 127.0.0.1:7000 nodeId
  • 127.0.0.1:7000: Any node of the cluster already exists ip:port
  • nodeId: Of the node to be deleted id

Be careful : The slave node should be deleted first , Delete the master node again

If you find deficiencies in reading , Welcome to leave a message !!!

原网站

版权声明
本文为[Asurplus、]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/03/202203020506599124.html