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! ! ================================================== ================