Redis Cluster high availability clustering online migration Record

Transfer from https://www.cnblogs.com/kevingrace/p/9844310.html

First, the machine environment

Pre-migration machine environment
-------------------------------------------------------------------------------
Hostname ip address of the node port
172.16.60.207 7000,7001-node01 Redis  Redis-node02 172.16.60.208 7002,7003  Redis-node03 172.16.60.209 7004,7005 migrate the machine environment ------------------- -------------------------------------------------- ---------- hostname ip address of the node port-new01 172.16.60.202 7000,7001 Redis Redis-new02 172.16.60.204 7002,7003 Redis-new03 172.16.60.205 7004,7005 Second, the migration of former high redis cluster available clusters deployment environment (herein "three leading and three from" mode) consistent with the three nodes below the machine mounting operation [the root-amdha01 Redis @ ~] # yum the install the make -Y GCC GCC ++ G-C ++ the kernel- devel autoconf automake libtool the make wget Git Vim Ruby RubyGems the unzip TCL [Redis-amdha01 the root @ ~] # /etc/init.d/ iptables STOP [Redis-amdha01 the root @ ~] # the setenforce 0 [Redis-amdha01 the root @ ~] # Vim / etc / sysconfig /SELINUX = SELinux Disabled prepared well in advance of the following operations, otherwise there will be a corresponding error log redis [root @ redis-node01 ~] # echo "512"> / proc / SYS / NET / Core / SOMAXCONN [root @ node01-redis ~] # Vim / etc / the rc.local echo "512"> / proc / SYS / NET / Core / SOMAXCONN [Redis-amdha01 the root @ ~] # echo. 1> / proc / SYS / VM / overcommit_memory [the root @ redis- ~ amdha01] = # sysctl vm.overcommit_memory. 1 vm.overcommit_memory. 1 = [the root-amdha01 Redis @ ~] # Vim / etc / the sysctl.conf vm.overcommit_memory. 1 = [the root-amdha01 Redis @ ~] # echo Never> / SYS / Kernel / mm / transparent_hugepage / Enabled [Redis-amdha01 the root @ ~] # Vim / etc / the rc.local echo Never> / SYS / Kernel / mm / transparent_hugepage / Enabled download and install the compiler redis [root @ redis-node01 ~ ] # mkdir -p / data / software / [root@redis-node01 software]# wget http://download.redis.io/releases/redis-4.0.6.tar.gz [root@redis-node01 software]# tar -zvxf redis-4.0.6.tar.gz [root@redis-node01 software]# mv redis-4.0.6 /data/ [root@redis-node01 software]# cd /data/redis-4.0.6/ [root@redis-node01 redis-4.0.6]# make ------------------------------------------------------------------------------- 分别创建和配置节点 节点1配置 [root@redis-node01 ~]# mkdir /data/redis-4.0.6/redis-cluster [root@redis-node01 ~]# cd /data/redis-4.0.6/redis-cluster [root@redis-node01 redis-cluster]# mkdir 7000 7001 [root@redis-node01 redis-cluster]# mkdir /var/log/redis [root@redis-node01 redis-cluster]# vim 7000/redis.conf port 7000 bind 172.16.60.207 daemonize yes pidfile /var/run/redis_7000.pid logfile /var/log/redis/redis_7000.log cluster-enabled yes cluster-config-file nodes_7000.conf cluster-node-timeout 10100 appendonly yes [root@redis-node01 redis-cluster]# vim 7001/redis.conf port 7001 bind 172.16.60.207 daemonize yes pidfile /var/run/redis_7001.pid logfile /var/log/redis/redis_7001.log cluster-enabled yes cluster-config-file nodes_7001.conf cluster-node-timeout 10100 appendonly yes 节点2配置 [root@redis-node02 ~]# mkdir /data/redis-4.0.6/redis-cluster [root@redis-node02 ~]# cd /data/redis-4.0.6/redis-cluster [root@redis-node02 redis-cluster]# mkdir 7002 7003 [root@redis-node02 redis-cluster]# mkdir /var/log/redis [root@redis-node02 redis-cluster]# vim 7000/redis.conf port 7002 bind 172.16.60.208 daemonize yes pidfile /var/run/redis_7002.pid logfile /var/log/redis/redis_7002.log cluster-enabled yes cluster-config-file nodes_7002.conf cluster-node-timeout 10100 appendonly yes [root@redis-node02 redis-cluster]# vim 7003/redis.conf port 7003 bind 172.16.60.208 daemonize yes pidfile /var/run/redis_7003.pid logfile /var/log/redis/redis_7003.log cluster-enabled yes cluster-config-file nodes_7003.conf cluster-node-timeout 10100 appendonly yes 节点3配置 [root@redis-node03 ~]# mkdir /data/redis-4.0.6/redis-cluster [root@redis-node03 ~]# cd /data/redis-4.0.6/redis-cluster [root@redis-node03 redis-cluster]# mkdir 7004 7005 [root@redis-node03 redis-cluster]# mkdir /var/log/redis [root@redis-node03 redis-cluster]# vim 7004/redis.conf port 7004 bind 172.16.60.209 daemonize yes pidfile /var/run/redis_7004.pid logfile /var/log/redis/redis_7004.log cluster-enabled yes cluster-config-file nodes_7004.conf cluster-node-timeout 10100 appendonly yes [root@redis-node03 redis-cluster]# vim 7005/redis.conf port 7005 bind 172.16.60.209 daemonize yes pidfile /var/run/logfile redis_7005.pid / var / log / Redis / redis_7005.log Cluster- Enabled-config- Yes Cluster File nodes_7005.conf-Node Cluster-10100 timeout appendOnly Yes ---------------- -------------------------------------------------- ------------- respectively start redis service (start here redis unified service under /data/redis-4.0.6/redis-cluster path, namely * nodes_ .conf other documents also in this path generating lower) node 1 [root @ redis-node01 redis -cluster] # for ((i = 0; i <= 1; i ++)); do /data/redis-4.0.6/src/redis-server / data / 4.0.6-Redis / Redis-Cluster / 700 $ i / redis.conf; DONE [root @ node01-Redis Redis-Cluster] # PS -ef | ? grep Redis root 1103 1 0 15:19 00:00:03 / Data / Redis-4.0.6 / the src / Redis-Server 172.16.60.207:7000 [Cluster] the root. 1 1105 0 15:19? 00:00:03 /data/redis-4.0.6/src/redis-server 172.16. 60.207: 7001 [cluster] root 1315 32360 0 16:16 pts/1 00:00:00 grep redis 节点2 [root@redis-node02 redis-cluster]# for((i=2;i<=3;i++)); do /data/redis-4.0.6/src/redis-server /data/redis-4.0.6/redis-cluster/700$i/redis.conf; done [root@redis-node02 redis-cluster]# ps -ef|grep redis root 9446 1 0 15:19 ? 00:00:03 /data/redis-4.0.6/src/redis-server 172.16.60.208:7002 [cluster] root 9448 1 0 15:19 ? 00:00:03 /data/redis-4.0.6/src/redis-server 172.16.60.208:7003 [cluster] root 9644 8540 0 16:17 pts/0 00:00:00 grep redis 节点3 [root@redis-node01 redis-cluster]# for((i=4;i<=5;i++)); do /data/redis-4.0.6/src/redis-server /data/redis-4.0.6/redis-cluster/700$i/redis.conf; done [root@redis-node03 ~]# ps -ef|Redis root 9486 1 0 grep 15:19? 00:00:03 /data/redis-4.0.6/src/redis-server 172.16.60.209:7004 [Cluster] root 9488 1 0 15:19? 00:00:03 172.16.60.209:7005 /data/redis-4.0.6/src/redis-server [Cluster] the root PTS 16:17 9686 9555 0/0 00:00:00 grep Redis ----------- -------------------------------------------------- ------------------ then installed on the node 1 Ruby (only on one of the nodes can be installed) [root @ redis-node01 ~ ] # yum -y install RPM-devel-RubyGems Ruby Ruby Build [root @ Redis-node01 ~ ] # GEM install Redis tips: implementation of the above "gem install redis" in centos6.x operation may be error, a lot of pit! The default yum install ruby version is 1.8.7Version too, need to upgrade to ruby2.2, or it will perform the installation above error! First install rvm (or directly download the certificate: https: //pan.baidu.com/s/1slTyJ7n key: after 7uan download and extract directly execute "curl -L get.rvm.io | bash -s stable " to) [root @ redis-node01 ~] # curl -L get.rvm.io | bash -s stable // may be error, you need to install prompts the following step of the operation [root @ redis-node01 ~] # curl -sSL https: / /rvm.io/mpapis.asc | gpg2 --import - // then then performed: curl -L get.rvm.io | -s the bash the stable [Redis-amdha01 the root @ ~] # Find / - name rvm.sh /etc/profile.d/ rvm.sh [Redis-amdha01 the root @ ~] # Source /etc/profile.d/ rvm.sh [Redis-amdha01 the root @ ~ ] # RVM requirements ruby then upgrade to 2.3 [Redis the root @ ~ -node01] # RVM install ruby 2.3.1 [root @ redis-node01 ~] # ruby - v ruby 2.3.1p112 (2016-04-26 Revision 54768) [x86_64 Linux] lists all the ruby version [root @ redis -node01 ~] # Rvm list to set the default version [root @ redis-node01 ~] # rvm --default use 2.3.1 update download source [root @ redis-node01 ~] # gem sources --add https: //gems.ruby- --remove https://rubygems.org https://gems.ruby-china.org/ added to china.org/ Sources Source https://rubygems.org not Present in Cache [root @ Redis-node01 ~ ] # Sources *** *** CURRENT SOURCES GEM https://rubygems.org/ https://gems.ruby-china.org/ finally be able to successfully install the [root @ Redis-node01 ~ ] # GEM install Redis successfully installed 4.0.6-Redis Parsing Redis-4.0.6 Documentation for the Done Documentation for Installing After Redis. 1 seconds The. 1 GEM Installed -------------------------- -------------------------------------------------- ---Then create redis cluster clustering (node operations on machine 1 can) manually specify the first three master nodes. master node is preferably distributed across the three machines [root @ redis-node01 ~] # /data/redis-4.0.6/src/redis-trib.rb create 172.16.60.207:7000 172.16.60.208:7002 172.16.60.209: 7004 then manually specify the master nodes each of the above three slave nodes. slave node also preferably distributed across the three machines [root @ redis-node01 ~] # /data/redis-4.0.6/src/redis-trib.rb add-node --slave 172.16.60.208:7003 172.16.60.207 : 7000 [root @ Redis-node01 ~] # /data/redis-4.0.6/src/redis-trib.rb the Add-the Node --slave 172.16.60.209:7005 172.16.60.208:7002 [root @ Redis-node01 ~ ] # /data/redis-4.0.6/src/redis-trib.rb the Add-Node --slave 172.16.60.207:7001 172.16.60.209:7004 Redis then check the status of the cluster cluster [root @ redis-node01 redis- cluster ] # /data/redis-4.0.6/src/redis-trib.rb check 172.16.60.207:7000 >>> Performing Cluster Check (using node 172.16.60.207:7000) M: 971d05cd7b9bb3634ad024e6aac3dff158c52eee 172.16.60.207:7000 slots:0-5460 (5461 slots) master 1 additional replica(s) S: e7592314869c29375599d781721ad76675645c4c 172.16.60.209:7005 slots: (0 slots) slave replicates 0060012d749167d3f72833d916e53b3445b66c62 S: 52b8d27838244657d9b01a233578f24d287979fe 172.16.60.208:7003 slots: (0 slots) slave replicates 971d05cd7b9bb3634ad024e6aac3dff158c52eee S: 213bde6296c36b5f31b958c7730ff1629125a204 172.16.60.207:7001 slots: (0 slots) slave replicates e936d5b4c95b6cae57f994e95805aef87ea4a7a5 M: e936d5b4c95b6cae57f994e95805aef87ea4a7a5 172.16.60.209:7004 slots:10923-16383 (5461 slots) master 1Replica Additional (S) M: 0060012d749167d3f72833d916e53b3445b66c62 172.16.60.208:7002 slots: 5461-10922 (5462 slots). 1 Master Additional Replica (S) [the OK] All Nodes Agree About Configuration >>> slots for the Check. Open slots ...> >> the Check slots coverages ... [the OK] All 16384 slots. Covered. It can be seen from the above, only the master before the master node occupied slots, the node is 0 slots, that is to say the numerical keys in the master node. Three primary master node divided 16384 slots. Are 0-5460,5461-10922,10923-16383 . If there are a group of master-slave hang, 16484 slots is not complete, then hung up the entire cluster service will have to wait until this group of master-slave node recovery, the entire cluster to recover. If the new primary master node is added, the default is 0 slots, grooves need reshard distribution data for the new master node (hash asks how many slots to this node to the mobile) will be mentioned later. Writing data (log data is written on the slave node found automatically skip writing the master node) [root @ redis-node01 redis -cluster] # / data on the write test data log several three master nodes -c -p 7000 -h 172.16.60.207 /redis-4.0.6/src/redis-cli 172.16.60.207:7000> the SET test1 the Test-207 the OK 172.16.60.207:7000> the SET Test11 the Test-207-207 -> Redirected slot to [13313] located block AT 172.16.60.209:7004 the OK [root @ node01-Redis Redis-Cluster] # /data/redis-4.0.6/src/redis-cli -c -p 7002 -h 172.16.60.208 172.16. 60.208: 7002> the SET test2 the Test-208 the OK 172.16.60.208:7002> the SET test22 the Test-208-208 -> Redirected to slot [4401] located block AT 172.16.60.207:7000 the OK [root @ node01-Redis Redis-Cluster] # /data/redis-4.0.6/src/redis-cli -h 172.16.60.209 -c -p 7004 172.16.60.209:7004> set test3 test-209 OK 172.16.60.209:7004> set test33 test-209-209 OK 读数据 [root@redis-node01 redis-cluster]# /data/redis-4.0.6/src/redis-cli -h 172.16.60.207 -c -p 7000 172.16.60.207:7000> get test1 "test-207" 172.16.60.207:7000> get test11 -> Redirected to slot [13313] located at 172.16.60.209:7004 "test-207-207" 172.16.60.209:7004> get test2 -> Redirected to slot [8899] located at 172.16.60.208:7002 "test-208" 172.16.60.208:7002> get test22 -> Redirected to slot [4401] located at 172.16.60.207:7000 "test-208-208" 172.16.60.207:7000> get test3 -> Redirected to slot [13026] located at 172.16.60.209:7004 "test-209" 172.16.60.209:7004> get test33 "test-209-209" 172.16.60.209:7004>Third, the online migrationThree new machines installed redis step can be omitted, and the above same. Three new machines each node configuration and pre-migration has three machines, only need to modify ip address. Port and consistent path to start three new machines redis service node in the new node redis- on new01 install Ruby, the installation process is omitted, and above all the time. The three new nodes are added to the previous cluster. ===================== first add the primary node command format "redis-trib.rb add-node <new node name> <original cluster node name>" section master port [root @ redis-new01 redis- cluster] is a new master node of the IP port, the second parameter is the IP any existing node # /data/redis-4.0.6/src/redis-trib. Node 172.16.60.202:7000 172.16.60.207:7000 the Add-RB [the root-new01 @ Redis Redis-Cluster] # /data/redis-4.0.6/src/redis-trib.rb the Add-Node 172.16.60.204:7002 172.16 .60.207: 7000 [root @ Redis Redis-new01-Cluster] # /data/redis-4.0.6/src/redis-trib.rb the Add-the Node 172.16.60.205:7004 172.16.60.207:7000 ====== =============== add new machines from node [root @ redis-new01 redis- cluster] # /data/redis-4.0.6/src/redis-trib.rb add -node --slave 172.16.60.204:7003 172.16.60.202:[root @ Redis Redis-new01-Cluster] # /data/redis-4.0.6/src/redis-trib.rb the Add-the Node --slave 172.16.60.205:7005 172.16.60.204:7002 [root @ Redis Redis-new01 -cluster] # /data/redis-4.0.6/src/redis-trib.rb add-node --slave 172.16.60.202:7001 172.16.60.205:7004 Check that the cluster state [root @ redis-new01 redis- cluster ] # /data/redis-4.0.6/src/redis-trib.rb check 172.16.60.202:7000 see the hash slot slot case [root @ redis-new01 redis- cluster cluster] # /data/redis-4.0. 6 / src / Redis-trib.rb info 172.16.60.202:7000 172.16.60.202:7000 (a0169bec ...) -> 0 Keys | slots 0 | 1 slaves 172.16.60.209:7004 (47cde5c7 ...) ->. Keys 3 | 5461 slots | 1 slaves 172.16.60.208:7002 (656fc84a ...) -> 1 Keys |. 5462 slots | 1 slaves 172.16.60.205:7004 (48cbab90 ...) -> 0 Keys |. 0 slots | 1. slaves 172.16.60.207:7000 (a8fe2d6e ...) -> 2 Keys | 5461 slots |. 1 . slaves 172.16.60.204:7002 (c6a78cfb ...) -> 0 Keys | slots 0 |. 1 . slaves [the OK]. 6 in 6 Keys Masters. 0.00 Keys oN Average per slot. the newly added slot as the default master node is 0, master primary node if no slots, then it will not be accessing data selected! data will only be stored in the master main node! Slot needs to be allocated to the master so the master node is newly added, i.e. reshard slot operation. After the slot above the display based on the last successfully added a new master node is found, the existing slot allocation for the master node: 172.16.60.207:7000 -> slots: 0-5460 (5461 slots) master 172.16.60.208:7002 - -> slots: 5461-10922 (5462 slots) master 172.16.60.209:7004 -> slots: 10923-16383 (5461 slots) assigned to the three master now master node of the newly added slot a) the 172.16.60.207:7000 all of slot allocation (5461) to 172.16.60.202:7000 [the root-new01 @ Redis Redis-Cluster] # /data/redis-4.0.6/src/redis-trib.rb reshard 172.16.60.202:7000........ How many slots do you want to move (from 1 to 16384)? How much amount allocated slot 5461 #. (Here should 172.16.60.207 : slot 7000 have been distributed nodes) What is the receiving node ID a0169becd97ccca732d905fd762b4d615674f7bd # of those above slot number is received which node?. Here to fill 172.16.60.202 :. 7000 All the Enter Please node at The Source ID the Node IDs Type 'All' to use All AS at The Source Nodes Nodes for . At The hash slots Type 'DONE' Once you entered at The Source Nodes All the Node # Source IDs. 1: 971d05cd7b9bb3634ad024e6aac3dff158c52eee # refers to the allocation of a specified number of nodes from which the top slot. Here to fill 172.16.60.207 : 7000's ID. If fill all, a specified number of said extracted slot from above until all master nodes. The Node # 2 Source : DONE ....... # fill in the Do you want to DONE the proceed with reshard at The Proposed Plan (yes / NO)? Yes # fill yes, confirm allocation =========== ================================================== =====Point may encounter problems, resharding execute the interrupt. Situation on both sides of the slot and then appear. Slot from 4396 to 172.16.60.207:7000 Moving 172.16.60.202:7000 : Moving from 172.16.60.207:7000 slot 4397 to 172.16.60.202:7000 : Moving from 172.16.60.207:7000 slot 4398 to 172.16.60.202:7000 : Moving slot 172.16.60.207:7000 to 172.16.60.202:7000 from 4399 : Moving from 172.16.60.207:7000 slot 4400 to 172.16.60.202:7000 : Moving from 172.16.60.207:7000 slot 4401 to 172.16.60.202:7000 : [ERR] Calling MIGRATE: Syntax error ERR, the try CLIENT (the LIST | KILL | getName | SETNAME | PAUSE | a REPLY) [root @ Redis Redis-new01-Cluster] # /data/redis-4.0.6/src/redis-trib.rb the Check 172.16 .60.202: 7000 >>> Performing Cluster Check ( using node 172.16.60.202:7000) M: a0169becd97ccca732d905fd762b4d615674f7bd 172.16.60.202:7000 slots: 0-4400 (4401 slots). 1 Master Additional Replica (S) M .......: 971d05cd7b9bb3634ad024e6aac3dff158c52eee 172.16.60.207:7000 slots: 4401-5460 (1060. slots) Master 1 Additional Replica (S) analysis of reasons: being given reshard reassign slot contents: Syntax error, try CLIENT (LIST | KILL | gETNAME | SETNAME | | PAUSE time REPLY) but no key-value migration of slots will be executed successfully . This shows that the problem exists or not in the key- on value! Reshard found during the execution of: the specific migration steps are found by move_slot function call (redis- trib.rb file). Open move_slot function to find specific migration code. [@ Redis the root-Cluster-new01 Redis] CP # /data/redis-4.0.6/src/redis-trib.rb / tmp / [the root-new01 @ Redis Redis-Cluster] # CAT /data/redis-4.0. 6 / src / redis-trib.rb |source.r.client.call source.r.client.call grep ([ "the migrate", target.info [: Host], target.info [: Port], "", 0, @ timeout,: Keys, * Keys ]) source.r.client.call ([ "the migrate", target.info [: Host], target.info [: Port], "", 0, @ timeout,: Replace,: Keys, * Keys]) above grep out source.r.client.call part of the script is redis-trib.rb inform customers migrate with key- end execution instruction value slot. We will find the specific call of the directive, equivalent to a "client migrate target.info [: host] , target.info [: port]," ", 0, @ timeout,: replace,: keys, * keys]" issues come, this instruction is executed in the server how it? It is the first implementation networking.c file ClientCommand (Client * c) according to the parameters eleven alignment (if conditional statement). This time will find the bug coming! ! ! clientCommand function not migrate branch. It will return an error Syntax, the try CLIENT (LIST | KILL | GETNAME | SETNAME | PAUSE | a REPLY); This error message tells you, Client only LIST | KILL | GETNAME | SETNAME | PAUSE |REPLY branch. So how to modify the true migrated with key slot it? Study the source code, cluster.c file there migrateCommand (client * c). Suddenly realized, so long as the redis- migration trib.rb file statements revised as: source.r.call ([ "migrate", target.info [: host], target.info [: port], "", 0, @ timeout, "Replace",: Keys, * Keys]) source.r.call ([ "the migrate", target.info [: Host], target.info [: Port], "", 0, @ timeout,: Replace ,: Keys, * Keys]) that is not performed clientCommand, direct execution migrateCommand. In other words, simply redis- trib.rb file the original source.r.client.call ([ "migrate", target.info [: host], target.info [: port], "", 0, @Timeout,: Keys, * Keys]) source.r.client.call ([ "the migrate", target.info [: Host], target.info [: Port], "", 0, @ timeout,: the replace, : Keys, * Keys]) instead source.r.call ([ "migrate", target.info [: host], target.info [: port], "", 0, @ timeout, "Keys]) source.r.call ([ "the migrate", target.info [: Host], target.info [: Port], "", 0, @ timeout,: the replace,: Keys, * Keys]) problem solved! [root @ Redis Redis-new01-Cluster] # CAT /data/redis-4.0.6/src/redis-trib.rb | grep source.r.call source.r.call ([ "the migrate", target.info [ : Host], target.info [: Port], "", 0, @ timeout, "the replace",: Keys, * Keys]) source.r.call ([ "the migrate", target.info [: Host], target.info [: Port], "", 0, @ timeout,: the replace,: Keys, * Keys]) because this bug is caused by different ruby of gem, the 5.0 version will abandon redis-trib.rb. Directly redis- cli client implementation of cluster management! ! ================================================== ================ after redis-trib.rb script file modification, will continue 172.16.60.207:7000 all remaining slot allocated to 172.16.60.202:7000 [root @ redis- new01 redis-cluster] # /data/redis-4.0.6/src/redis-trib.rb reshard 172.16. open slots... [WARNING] Node 172.16.60.202:7000 has slots in importing state (4401). [WARNING] Node 172.16.60.207:7000 has slots in migrating state (4401). [WARNING] The following slots are open: 4401 >>> Check slots coverage... [OK] All 16384 slots covered. *** Please fix your cluster problems before resharding 解决办法: [root@redis-new01 redis-cluster]# /data/redis-4.0.6/src/redis-cli -h 172.16.60.202 -c -p 7000 172.16.60.202:7000> cluster setslot 4401 stable OK 172.16.60.202:7000> [root@redis-new01 redis-cluster]# /data/redis-4.0.6/src/redis-cli -h 172.16.60.207 -c -p 7000 172.16.60.207:7000> cluster setslot 4401 stable OK 172.16.60.207:7000> [root@redis-new01 redis-cluster]# /data/redis-4.0.6/src/redis-trib.rb fix 172.16.60.202:7000 ....... [OK] All nodes agree about slots configuration. >>> Check for open slots... >>> Check slots coverage... [OK] All 16384 slots covered. [root@redis-new01 redis-cluster]# /data/redis-4.0.6/src/redis-trib.rb reshard 172.16.60.202:7000 ...... How many slots do you want to move (from 1 to 16384)? 1060 What is the receiving node ID? a0169becd97ccca732d905fd762b4d615674f7bd 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:971d05cd7b9bb3634ad024e6aac3dff158c52eee Source node #2: DONE ....... the proceed with the Do you want to reshard at The Proposed Plan (yes / NO)? yes then check inspection status of the cluster nodes found 5461 slot 172.16.60.207:7000 has been moved to 172.16.60.202. : 7000 on a node. [@ Redis the root-Cluster-new01 Redis] >>> # /data/redis-4.0.6/src/redis-trib.rb 172.16.60.202:7000 Performing the Cluster Check the Check (the using Node 172.16.60.202:7000 ) M: 172.16.60.202:7000 a0169becd97ccca732d905fd762b4d615674f7bd slots: 0-5460 (5461 slots) Master 2 Additional Replica (S) ........ M: 971d05cd7b9bb3634ad024e6aac3dff158c52eee 172.16.60.207:7000 slots: (0 slots) Master 0 Additional Replica (S ) b) the 172.16.60.208:7002 a slot (5462) all assigned to 172.16.60.204:7002 [the root-new01 @ Redis Redis-Cluster] # /data/redis-4.0.6/src/redis-trib.rb reshard 172.16.60.204:7002 ....... How many slots do you want to move (from 1 to 16384)? 5462 What is the receiving node ID? c6a78cfbb77804c4837963b5f589064b6111457a 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:0060012d749167d3f72833d916e53b3445b66c62 Source node #2:done ....... Do you want to proceed with the proposed reshard plan (yes/no)? yes c)将172.16.60.209:7004的slot(5461)全部分配给172.16.60.205:7004 [root@redis-new01 redis-cluster]# /data/redis-4.0.6/src/redis-trib.rb reshard 172.16.60.205:7004 ......... How many slots do you want to move (from 1 to 16384)? 5461 What is the receiving node ID?. 48cbab906141dd26241ccdbc38bee406586a8d03 Please the Enter All at The Source the Node IDs Type 'All' to use All at The Nodes AS Source Nodes for . At The hash slots Type 'DONE' Once you entered All at The Source Nodes IDs Source the Node # 1. : E936d5b4c95b6cae57f994e95805aef87ea4a7a5 Source the Node # 2 : done ......... Do you want to proceed with the proposed reshard plan (yes / no)? after yes until three new master node are complete hash slot allocation slot, again to view the state of the cluster found the three master of the slot before the migration are 0, slot corresponds to migrate to the new three master node of the [root @ redis-new01 redis- cluster] # /data/redis-4.0.6/src/ Check-trib.rb 172.16.60.202:7000 >>> Redis the Cluster Performing the Check (the using Node 172.16.60.202:7000 ) M: a0169becd97ccca732d905fd762b4d615674f7bd 172.16.60.202:7000 slots: 0-5460 (5461 slots) Master 2 additional replica(s) S: d9671ca6b4235931a2a215cc327a400ad4f9a399 172.16.60.205:7005 slots: (0 slots) slave replicates c6a78cfbb77804c4837963b5f589064b6111457a M: e936d5b4c95b6cae57f994e95805aef87ea4a7a5 172.16.60.209:7004 slots: (0 slots) master 0 additional replica(s) S: 213bde6296c36b5f31b958c7730ff1629125a204 172.16.60.207:7001 slots: (0 slots) slave replicates 48cbab906141dd26241ccdbc38bee406586a8d03 M: 0060012d749167d3f72833d916e53b3445b66c62 172.16.60.208:7002 slots: (0 slots) master 0 additional replica(s) S: 52b8d27838244657d9b01a233578f24d287979fe 172.16.60.208:7003 slots: (0 slots) slave replicates a0169becd97ccca732d905fd762b4d615674f7bd M: 48cbab906141dd26241ccdbc38bee406586a8d03 172.16.60.205:7004 slots:10923-16383 (5461 slots) master 2 additional replica(s) S: e7592314869c29375599d781721ad76675645c4c 172.16.60.209:7005 slots: (0 slots) slave replicates c6a78cfbb77804c4837963b5f589064b6111457a S: 2950f2cb6d960cd48e792f7c82d62d2cd07d20f9 172.16.60.204:7003 slots: (0 slots) slave replicates a0169becd97ccca732d905fd762b4d615674f7bd M: 971d05cd7b9bb3634ad024e6aac3dff158c52eee 172.16.60.207:7000 slots: (0 slots) master 0 additional replica(s) M: c6a78cfbb77804c4837963b5f589064b6111457a 172.16.60.204:7002 slots:5461-10922 (5462 slots) master 2 additional replica(s) S: 6e663a1bcc3d241ed4d1a9667a0cc92fbe554740 172.16.60.202:7001 slots: (0 slots) slave replicates 48cbab906141dd26241ccdbc38bee406586a8d03 [OK] All nodes agree about slots configuration. >>> Check for open slots... >>> Check slots coverage... [OK] All 16384 slots covered. 查看集群slot情况 [root@redis-new01 redis-cluster]# /data/redis-4.0.6/src/redis-trib.rb info 172.16.60.202:7000 172.16.60.202:7000 (a0169bec...) -> 2 keys | 5461 slots | 2 slaves. 172.16.60.209:7004 (47cde5c7...) -> 0 keys | 0 slots | 0 slaves. 172.16.60.208:7002 (656fc84a...) -> 0 keys | 0 slots | 0 slaves. 172.16.60.205:7004 (48cbab90...) -> 3 keys | 5461 slots | 2 slaves. 172.16.60.207:7000 (a8fe2d6e...) -> 0 keys | 0 slots | 0. slaves 172.16.60.204:7002 (c6a78cfb ...) -> 1 Keys | 5462 slots | 2 . slaves [the OK] 6 Keys in 6 . Masters 0.00 . Keys ON Average per slot under examination data, test data has also been found to migrate to the new master node of the [root @ Redis Redis-new01-Cluster] # /data/redis-4.0.6/src/redis-cli -c -p 7000 -h 172.16.60.202 172.16.60.202:7000> GET test1 "Test-207" 172.16.60.202:7000> GET test2 -> slot to the Redirected [8899] AT 172.16.60.204:7002 located block "208-Test" 172.16.60.204:7002> GET Test3 -> slot to the Redirected [13026] located block 172.16.60.205:7004 AT "209-Test" 172.16.60.205:7004> GET Test11 "Test-207-207" 172.16.60.205:7004> GET test22 -> slot to the Redirected [4401] AT 172.16.60.202:7000 located block " test-208-208 "172.16.60.202:7000> gettest33 -> Redirected to slot [12833 ] located at 172.16.60.205:7004 "test-209-209" 172.16.60.205:7004> About reshard slot reallocation hash slot, in addition to the above-interactive operation may be used as follows operation commands:. 1 # Redis-trib.rb reshard --from <Node-ID> --to <Node-ID> --slots <Number of slots> --yes <Host>: <Port> Fourth, the migration is complete after deleting the original node from the cluster a) slave before deleting from migrating from the cluster nodes [root @ redis-new01 redis- cluster] # /data/redis-4.0.6/src/redis-trib.rb del- 172.16.60.207:7001 Node 213bde6296c36b5f31b958c7730ff1629125a204 [the root-new01 @ Redis Redis-Cluster] # /data/redis-4.0.6/src/redis-trib.rb del-Node 172.16.60.208:7003 52b8d27838244657d9b01a233578f24d287979fe [the root-new01 @ Redis Redis -cluster] # /data/redis-4.0.6/src/redis-trib.rb del-node 172.16.60.209:7005e7592314869c29375599d781721ad76675645c4c b) master master node before the migration deleted from the cluster. When delete a node should pay attention to the following master primary node: - If there is a master node from the node to other nodes need to be transferred from the master node or delete a node from earlier - if a primary node with slot, remove the assigned slot, and then delete the master node. When you delete a master primary node, it must ensure that the above slot 0, which must be empty! Doing so may cause the entire cluster redis cluster does not work! To remove the master node is not empty, we need to move data to other nodes with a re-fragmentation command. Another way is to remove the master node for a manual failover, like its slave is elected as the new master, and it is then removed after it as a new slave is re-added to the cluster. Obviously, if you want to reduce the number of master cluster, this approach is not helpful. In this case you still need to re-patch to remove the data and then remove it. Because the slot has three original master of all master node smoked, that slot is now zero, and their respective slave nodes are also deleted so when the original three master master node can be removed from the cluster directly above [@ Redis the root-new01 Redis-Cluster] # /data/redis-4.0.6/src/redis-trib.rb del-Node 172.16.60.207:7000 971d05cd7b9bb3634ad024e6aac3dff158c52eee [the root-new01 @ Redis Redis-Cluster] # / Data / redis-4.0.6 / src / redis- trib.rb del-node 172.16.60.208:7002 0060012d749167d3f72833d916e53b3445b66c62 [root@redis-new01 redis-cluster]# /data/redis-4.0.6/src/redis-trib.rb del-node 172.16.60.209:7004 e936d5b4c95b6cae57f994e95805aef87ea4a7a5 最后再次查看下新的redis cluster集群状态 [root@redis-new01 redis-cluster]# /data/redis-4.0.6/src/redis-trib.rb check 172.16.60.202:7000 >>> Performing Cluster Check (using node 172.16.60.202:7000) M: a0169becd97ccca732d905fd762b4d615674f7bd 172.16.60.202:7000 slots:0-5460 (5461 slots) master 1 additional replica(s) S: d9671ca6b4235931a2a215cc327a400ad4f9a399 172.16.60.205:7005 slots: (0 slots) slave replicates c6a78cfbb77804c4837963b5f589064b6111457a M: 48cbab906141dd26241ccdbc38bee406586a8d03 172.16.60.205:7004 slots:10923-16383 (5461 slots) master 1 additional replica(s) S: 2950f2cb6d960cd48e792f7c82d62d2cd07d20f9 172.16.60.204:7003 slots: (0 slots) slave replicates a0169becd97ccca732d905fd762b4d615674f7bd M: c6a78cfbb77804c4837963b5f589064b6111457a 172.16.60.204:7002 slots:5461-10922 (5462 slots) master 1 additional replica(s) S: 6e663a1bcc3d241ed4d1a9667a0cc92fbe554740 172.16.60.202:7001 slots: (0 slots) slave replicates 48cbab906141dd26241ccdbc38bee406586a8d03 [OK] All nodes agree about slots configuration. >>> Check for open slots... >>> Check slots coverage... [OK] All 16384 slots covered. [root@redis-new01 redis-cluster]# /data/redis-4.0.6/src/redis-trib.rb info 172.16.60.202:7000 172.16.60.202:7000 (a0169bec...) -> 2 keys | 5461 slots | 1 slaves. 172.16.60.205:7004 (48cbab90...) -> 3 keys | 5461 slots | 1 slaves. 172.16.60.204:7002 (c6a78cfb...) -> 1 keys | 5462 slots | 1 slaves. [OK] 6 keys in 3 masters. 0.00 keys per slot on average. [root@redis-new01 redis-cluster]# /data/redis-4.0.6/src/redis-cli -h 172.16.60.202 -c -p 7000 172.16.60.202:7000> get test1 "test-207" 172.16.60.202:7000> get test11 -> Redirected to slot [13313] located at 172.16.60.205:7004 "test-207-207" 172.16.60.205:7004> get test2 -> Redirected to slot [8899] located at 172.16.60.204:7002 "test-208" 172.16.60.204:7002> get test22 -> Redirected to slot [4401] located at 172.16.60.202:7000 "test-208-208" 172.16.60.202:7000> getTest3 -> slot to the Redirected [13026] AT 172.16.60.205:7004 located block "209-Test" 172.16.60.205:7004> GET test33 "Test-209-209" 172.16.60.205:7004> ======== ============================================= tips: If you are slot master primary node to remove is not 0, you need to first be deleted master node slot extraction finished, that the cancellation of its slot allocation! Suppose master slot 172.16.60.207:7000 there master node 2550, the slot 2550 needs to these 172.16.60.202 pumped from 172.16.60.207:7000 : the 7000 [root @ redis-new01 redis -cluster] # / the Data / Redis-4.0.6 / src / Redis-trib.rb reshard 172.16.60.207:7000 ....... MANY slots How do you want to the Move (from 1 to 16384)? 2550 // be deleted master of All quantities slot What is the receiving node ID? a0169becd97ccca732d905fd762b4d615674f7bd // master node receives the ID of the slot 2550, ID, i.e. the 172.16.60.202:7000 Please enter all the source node IDs. Type 'all'. The slots the hash the Type 'done' Once you entered the Source IDs All Nodes The Source Node #. 1:. 971d05cd7b9bb3634ad024e6aac3dff158c52eee // ID master node is deleted, i.e. the 172.16.60.207:7000 ID Source node # 2: done // Input done ....... Do you want to proceed with the proposed reshard plan (yes / no)? yes // confirm the operation as successful abolition of slot allocation master node (ie, slot 0) after that, it can be deleted up! Tips: 1) After the new master node, also need to be reshard operation, but is for the new node. That "redis-trib.rb reshard new node" . This is the slot allocation operation! 2) before removing the master node, if there is slot, also need to be reshard operation, but is aimed at deleting nodes. That "redis-trib.rb reshard been deleted node" . This is the slot cancel! After testing, the application is not affected in any way as the migration process in redis cluster! Note, however, required in the application will connect redis redis address updated with the new address and port after migration. *************** When you discover your talents not afford to support ambitious, quiet please learn it *************** Category: Redis good text to focus on my top favorites this article flashy cleared

Guess you like

Origin www.cnblogs.com/musen/p/11139362.html