Redis Cluster Synchronous Migration Method (i): Implemented through Redis replication

Source: Internet
Author: User
Tags redis cluster

When it comes to redis migration, it is common to use an RDB or aof to do an automatic reload to the target library method in the main library. However, the problem of this method is that there is no guarantee that the source node data and the target node data are consistent, the general line environment does not allow the source library to stop, so after the migration process to achieve synchronization to achieve data consistency. The company's online environment uses Redis's own cluster, with multiple RDB and aof files per node, and it's no doubt that using the original method is difficult. This paper mainly discusses two methods to realize the migration of Source Library (Redis cluster) to target library (cluster or single instance) under the premise of non-stop Source library:
    • Implemented with Redis replication
    • Use open source to synchronize open source tools
Method One: Through the Redis replication mechanism, the target node as the source node from the node, and then close the source node, the master-slave automatic fail over, and then close and delete the source node instance 1. Operating Environment:SOURCE Node instance: 127.0.0.1:12000/127.0.0.1:12001/127.0.0.1:12002[[email protected]_86_30_37_10.86.30.37 mycluster_export1]# Redis-cli-p 12000 cluster Nodese5ce695f7c5745ca81b4239fb5666b6a71fbb4ea 127.0.0.1:12000 myself,master-0 0 1 Connected 0 -5000f63f0d52372ad8b5c414c47e9318717b6aa113cc 127.0.0.1:12001 master-0 1463025774035 2 connected 5001-10000fdeb68f696290a91f08a5da3b8a3c585aaa35856 127.0.0.1:12002 master-0 1463025775037 0 connected 10001-16383 Migrating target node instances: 127.0.0.1:13000/127.0.0.1:13001/127.0.0.1:13002 2. Migration Process
    • Launches three target nodes, with instances of Redis cluster mode configured
redis-Server redis13000.conf redis-server redis13001.conf redis-server redis13002.conf
    • Slave the three nodes into the existing cluster instance
Redis-cli-p13000Cluster meet127.0.0.1 12000Redis-cli-p13000Cluster replicate E5ce695f7c5745ca81b4239fb5666b6a71fbb4earedis-cli-p13001Cluster meet127.0.0.1 12001Redis-cli-p13001Cluster replicate F63f0d52372ad8b5c414c47e9318717b6aa113ccredis-cli-p13002Cluster meet127.0.0.1 12002Redis-cli-p13002Cluster replicate fdeb68f696290a91f08a5da3b8a3c585aaa35856
    • View cluster Status:
Redis-cli-p13002Cluster Slots1)1) (integer)5001   2) (integer)10000   3)1)"127.0.0.1"      2) (integer)12001   4)1)"127.0.0.1"      2) (integer)130012)1) (integer)10001   2) (integer)16383   3)1)"127.0.0.1"      2) (integer)12002   4)1)"127.0.0.1"      2) (integer)130023)1) (integer)0   2) (integer) the   3)1)"127.0.0.1"      2) (integer)12000   4)1)"127.0.0.1"      2) (integer)13000
    • Put one of the main nodes offline, after 10s observation:
Redis-cli-p12000Shutdownredis-cli-p13000Cluster nodesfdeb68f696290a91f08a5da3b8a3c585aaa35856127.0.0.1:12002Master-0 1463042318423 0Connected10001-16383f63f0d52372ad8b5c414c47e9318717b6aa113cc127.0.0.1:12001Master-0 1463042319426 2Connected5001-10000e39a73c30dfff3139242e66f8e0a41178b39e280127.0.0.1:13000Myself,master-0 0 6Connected0- the1F552BDEA453CAEAA64B4B33A05E4EEDEB3F3DD2127.0.0.1:13001Slave f63f0d52372ad8b5c414c47e9318717b6aa113cc0 1463042317421 4connected6a70a82c6f07dc4e61a97b6aee7a2994365642cc127.0.0.1:13002Slave fdeb68f696290a91f08a5da3b8a3c585aaa358560 1463042320429 5Connectede5ce695f7c5745ca81b4239fb5666b6a71fbb4ea127.0.0.1:12000Master,fail-1463042217663 1463042214056 1Disconnected
    • Delete the main node that has been downline, one operation, operation Intermediate Check whether the operation is successful, because the message agreement and failover need a period of time
Redis-cli-p13000cluster Forget E5ce695f7c5745ca81b4239fb5666b6a71fbb4earedis-cli-p13001cluster Forget E5ce695f7c5745ca81b4239fb5666b6a71fbb4earedis-cli-p13002cluster Forget E5ce695f7c5745ca81b4239fb5666b6a71fbb4earedis-cli-p13000Cluster nodesfdeb68f696290a91f08a5da3b8a3c585aaa35856127.0.0.1:12002Master-0 1463043284365 0Connected10001-16383f63f0d52372ad8b5c414c47e9318717b6aa113cc127.0.0.1:12001Master-0 1463043283364 2Connected5001-10000e39a73c30dfff3139242e66f8e0a41178b39e280127.0.0.1:13000Myself,master-0 0 6Connected0- the1F552BDEA453CAEAA64B4B33A05E4EEDEB3F3DD2127.0.0.1:13001Slave f63f0d52372ad8b5c414c47e9318717b6aa113cc0 1463043286369 4connected6a70a82c6f07dc4e61a97b6aee7a2994365642cc127.0.0.1:13002Slave fdeb68f696290a91f08a5da3b8a3c585aaa358560 1463043285368 5ConnectedRedis-cli-p13000cluster Nodes e39a73c30dfff3139242e66f8e0a41178b39e280127.0.0.1:13000Myself,master-0 0 6Connected0- the1F552BDEA453CAEAA64B4B33A05E4EEDEB3F3DD2127.0.0.1:13001Slave-0 1463043457854 4connected6a70a82c6f07dc4e61a97b6aee7a2994365642cc127.0.0.1:13002Slave-0 1463043458857 5Connected
3. Key details:
    • Delete the master node, if restarted, he will reload the cluster configuration file, causing cluster confusion, it is recommended that if you want to restart the instance, delete the cluster configuration file, to reconfigure.
    • You must close the master node before you delete it. You cannot shut down all instances at once, or it will cause the entire cluster to be down
    • To execute cluster forget command on all other nodes when deleting the forget node, it seems that this command will not propagate to all nodes through the message protocol

Redis Cluster Synchronous Migration Method (i): Implemented through Redis replication

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.