redis hand fragment

table of Contents

A, redis environment

Two, redis hand slicing step

1. Configure cascading replication

2. Remove the old sentinel surveillance

3. Copy the new stop instances from the old instance

4. Add a new sentinel surveillance

5. Restart the new Sentinel       

6. Add the old sentinel surveillance

7. Restart the old Sentinel

Third, pay attention


        With the increasing amount of data, it may require a redis example to form a plurality of divided data pieces. At this time you may generally operate in two ways: First, the cluster mode is automatically enabled data pieces; two hand fragments, i.e. partial configuration requires a copy sheet redis example, modify the application in a certain way (e.g., modulus, etc.) redis access to different instances. cluster configuration mode may refer to " beginner practice redis: Migration Redis 5.0.3 single instance of data to the Cluster ." This article describes the specific steps of the second embodiment.

A, redis environment

        Existing physical machines 192.168.1.36,192.168.1.37,192.168.1.38 assuming three, are arranged a redis to the two main, accessible through the Sentinel. 192.168.1.36 primary instance, port 20007, master name is redis7. Start a sentry process on three machines were, port 30001. View from the sentry copy information is as follows:

[root~]#sudo -u redis /home/redis/redis-5.0.3/src/redis-cli -h  192.168.1.36 -p 30001 info | grep redis7
master1:name=redis7,status=ok,address= 192.168.1.36:20007,slaves=2,sentinels=3
[root~]#sudo -u redis /home/redis/redis-5.0.3/src/redis-cli -h  192.168.1.37 -p 30001 info | grep redis7
master1:name=redis7,status=ok,address= 192.168.1.36:20007,slaves=2,sentinels=3
[root~]#sudo -u redis /home/redis/redis-5.0.3/src/redis-cli -h  192.168.1.38 -p 30001 info | grep redis7
master1:name=redis7,status=ok,address= 192.168.1.36:20007,slaves=2,sentinels=3

        The goal is a set of existing Redis (two from a master) split into four groups (two from each group as a master), data partitioning strategy by the application. The new three instances where redis 192.168.1.39,192.168.1.40,192.168.1.41 physical machine, and start the process were a sentinel on three machines, is still accessible through the sentry.

Two, redis hand slicing step

1. Configure cascading replication

(1) arranged on a standard three 192.168.1.39,192.168.1.40,192.168.1.41 two master copy from redis, 39 mainly are 20001,20002,20003 port.

sudo -u redis /home/redis/redis-5.0.3/src/redis-cli -h  192.168.1.40 -p 20001 -a 123456 slaveof 192.168.1.39 20001
sudo -u redis /home/redis/redis-5.0.3/src/redis-cli -h  192.168.1.40 -p 20002 -a 123456 slaveof 192.168.1.39 20002
sudo -u redis /home/redis/redis-5.0.3/src/redis-cli -h  192.168.1.40 -p 20003 -a 123456 slaveof 192.168.1.39 20003

sudo -u redis /home/redis/redis-5.0.3/src/redis-cli -h  192.168.1.41 -p 20001 -a 123456 slaveof 192.168.1.39 20001
sudo -u redis /home/redis/redis-5.0.3/src/redis-cli -h  192.168.1.41 -p 20002 -a 123456 slaveof 192.168.1.39 20002
sudo -u redis /home/redis/redis-5.0.3/src/redis-cli -h  192.168.1.41 -p 20003 -a 123456 slaveof 192.168.1.39 20003

(2) is configured as a slave the old instance, data replication

sudo -u redis /home/redis/redis-5.0.3/src/redis-cli -h  192.168.1.39 -p 20001 -a 123456 slaveof 192.168.1.36 20007
sudo -u redis /home/redis/redis-5.0.3/src/redis-cli -h  192.168.1.39 -p 20002 -a 123456 slaveof 192.168.1.36 20007
sudo -u redis /home/redis/redis-5.0.3/src/redis-cli -h  192.168.1.39 -p 20003 -a 123456 slaveof 192.168.1.36 20007

        After completion of this step forming a cascading replication, 192.168.1.36: 20007 has five slave, namely 192.168.1.37:20007,192.168.1.38:20007,192.168.1.39:20001,192.168.1.39:20002,192.168.1.39: 20003. Example redis 192.168.1.39 and the upper three (20001,20002,20003) and each having two Slave 192.168.1.40,192.168.1.42 (ports with 192.168.1.39). You can use the following command to view the number of keys on each instance:

# 查看key数量,在192.168.1.39执行
sudo -u redis /home/redis/redis-5.0.3/src/redis-cli -h  192.168.1.36 -p 20007 -a 123456 info | grep db0:keys=
sudo -u redis /home/redis/redis-5.0.3/src/redis-cli -h  192.168.1.37 -p 20007 -a 123456 info | grep db0:keys=
sudo -u redis /home/redis/redis-5.0.3/src/redis-cli -h  192.168.1.38 -p 20007 -a 123456 info | grep db0:keys=

sudo -u redis /home/redis/redis-5.0.3/src/redis-cli -h  192.168.1.39 -p 20001 -a 123456 info | grep db0:keys=
sudo -u redis /home/redis/redis-5.0.3/src/redis-cli -h  192.168.1.39 -p 20002 -a 123456 info | grep db0:keys=
sudo -u redis /home/redis/redis-5.0.3/src/redis-cli -h  192.168.1.39 -p 20003 -a 123456 info | grep db0:keys=

sudo -u redis /home/redis/redis-5.0.3/src/redis-cli -h  192.168.1.40 -p 20001 -a 123456 info | grep db0:keys=
sudo -u redis /home/redis/redis-5.0.3/src/redis-cli -h  192.168.1.40 -p 20002 -a 123456 info | grep db0:keys=
sudo -u redis /home/redis/redis-5.0.3/src/redis-cli -h  192.168.1.40 -p 20003 -a 123456 info | grep db0:keys=

sudo -u redis /home/redis/redis-5.0.3/src/redis-cli -h  192.168.1.41 -p 20001 -a 123456 info | grep db0:keys=
sudo -u redis /home/redis/redis-5.0.3/src/redis-cli -h  192.168.1.41 -p 20002 -a 123456 info | grep db0:keys=
sudo -u redis /home/redis/redis-5.0.3/src/redis-cli -h  192.168.1.41 -p 20003 -a 123456 info | grep db0:keys=

2. Remove the old sentinel surveillance

# 在192.168.1.36执行
sudo -u redis /home/redis/redis-5.0.3/src/redis-cli -h  192.168.1.36 -p 30001 sentinel remove redis7
sudo -u redis /home/redis/redis-5.0.3/src/redis-cli -h  192.168.1.37 -p 30001 sentinel remove redis7
sudo -u redis /home/redis/redis-5.0.3/src/redis-cli -h  192.168.1.38 -p 30001 sentinel remove redis7

sudo -u redis /home/redis/redis-5.0.3/src/redis-cli -h  192.168.1.36 -p 30001 info | grep redis7
sudo -u redis /home/redis/redis-5.0.3/src/redis-cli -h  192.168.1.37 -p 30001 info | grep redis7
sudo -u redis /home/redis/redis-5.0.3/src/redis-cli -h  192.168.1.38 -p 30001 info | grep redis7

3. Copy the new stop instances from the old instance

#  在192.168.1.39执行
cat ~/remove_repl.txt | sudo -u redis /home/redis/redis-5.0.3/src/redis-cli -h  192.168.1.41 -p 20003 -a 123456
cat ~/remove_repl.txt | sudo -u redis /home/redis/redis-5.0.3/src/redis-cli -h  192.168.1.41 -p 20004 -a 123456
cat ~/remove_repl.txt | sudo -u redis /home/redis/redis-5.0.3/src/redis-cli -h  192.168.1.41 -p 20005 -a 123456

sudo -u redis /home/redis/redis-5.0.3/src/redis-cli -h  192.168.1.39 -p 20003 -a 123456 info replication
sudo -u redis /home/redis/redis-5.0.3/src/redis-cli -h  192.168.1.39 -p 20004 -a 123456 info replication
sudo -u redis /home/redis/redis-5.0.3/src/redis-cli -h  192.168.1.39 -p 20005 -a 123456 info replication

~ / Remove_repl.txt contents of the file:

slaveof no one
config rewrite
info replication

4. Add a new sentinel surveillance

# 在192.168.1.39执行
cat /home/redis/tmp_sentinel_monitor | sudo -u redis /home/redis/redis-5.0.3/src/redis-cli -h  192.168.1.39 -p 30001
cat /home/redis/tmp_sentinel_monitor | sudo -u redis /home/redis/redis-5.0.3/src/redis-cli -h  192.168.1.40 -p 30001
cat /home/redis/tmp_sentinel_monitor | sudo -u redis /home/redis/redis-5.0.3/src/redis-cli -h  192.168.1.41 -p 30001

sudo -u redis /home/redis/redis-5.0.3/src/redis-cli -h  192.168.1.39 -p 30001 info | grep master
sudo -u redis /home/redis/redis-5.0.3/src/redis-cli -h  192.168.1.40 -p 30001 info | grep master
sudo -u redis /home/redis/redis-5.0.3/src/redis-cli -h  192.168.1.41 -p 30001 info | grep master

/ Home / redis / tmp_sentinel_monitor contents of the file:

sentinel monitor redis1  192.168.1.39 20001 2
sentinel set redis3 auth-pass 123456
sentinel set redis3 down-after-milliseconds 5000
sentinel set redis3 failover-timeout 10000

sentinel monitor redis2  192.168.1.39 20002 2
sentinel set redis4 auth-pass 123456
sentinel set redis4 down-after-milliseconds 5000
sentinel set redis4 failover-timeout 10000

sentinel monitor redis3  192.168.1.39 20003 2
sentinel set redis5 auth-pass 123456
sentinel set redis5 down-after-milliseconds 5000
sentinel set redis5 failover-timeout 10000

5. Restart the new Sentinel       

# 分别在192.168.1.41、192.168.1.40、192.168.1.39执行
sudo -u redis /home/redis/redis-5.0.3/src/redis-cli -p 30001 shutdown
sudo -u redis /home/redis/redis-5.0.3/src/redis-sentinel /home/redis/sentinel/sentinel.conf > /home/redis/sentinel/sentinel.log 2>&1 &
sudo -u redis /home/redis/redis-5.0.3/src/redis-cli -p 30001 info | grep master

6. Add the old sentinel surveillance

# 在192.168.1.36执行
cat /home/redis/tmp_sentinel_monitor | sudo -u redis /home/redis/redis-5.0.3/src/redis-cli -h  192.168.1.36 -p 30001
cat /home/redis/tmp_sentinel_monitor | sudo -u redis /home/redis/redis-5.0.3/src/redis-cli -h  192.168.1.37 -p 30001
cat /home/redis/tmp_sentinel_monitor | sudo -u redis /home/redis/redis-5.0.3/src/redis-cli -h  192.168.1.38 -p 30001

sudo -u redis /home/redis/redis-5.0.3/src/redis-cli -h  192.168.1.36 -p 30001 info | grep redis7
sudo -u redis /home/redis/redis-5.0.3/src/redis-cli -h  192.168.1.37 -p 30001 info | grep redis7
sudo -u redis /home/redis/redis-5.0.3/src/redis-cli -h  192.168.1.38 -p 30001 info | grep redis7

/ Home / redis / tmp_sentinel_monitor contents of the file:

sentinel monitor redis7  192.168.1.36 20007 2
sentinel set redis7 auth-pass 123456
sentinel set redis7 down-after-milliseconds 5000
sentinel set redis7 failover-timeout 10000

7. Restart the old Sentinel

# 在192.168.1.38、192.168.1.37、192.168.1.36执行
sudo -u redis /home/redis/redis-5.0.3/src/redis-cli -p 30001 shutdown
sudo -u redis /home/redis/redis-5.0.3/src/redis-sentinel /home/redis/sentinel/sentinel.conf > /home/redis/sentinel/sentinel.log 2>&1 &
sudo -u redis /home/redis/redis-5.0.3/src/redis-cli -p 30001 info

Third, pay attention

  • Sentinel instance itself is not encrypted, otherwise the application can not connect properly.
  • Do not add sentinel surveillance on the intermediate layer master cascading replication, otherwise Sentinel access to the top-level master through go wrong.
  • When removing the intermediate layer master copy on top, you need to remove the sentinel surveillance on the top floor of the master, otherwise the slaveof no one even in the middle layer master instance, will still be the main top-level master and the middle layer of the master-slave relationship.
  • To ensure the sentry work, + sdown avoid problems, need to restart the process after changing Sentinel Sentinel configuration.
Published 370 original articles · won praise 599 · Views 2.18 million +

Guess you like

Origin blog.csdn.net/wzy0623/article/details/105086262