Using Redis replication to realize thermal migration of REDIS servers

Source: Internet
Author: User
Tags redis server

Using Redis replication to realize thermal migration of REDIS servers

At the beginning of the article I declare: the title is too tall, mainly to install force.

A month of Black night, an operation and a siege lion and a PHP program ape in a long talk, saw the PHP program ape eyes staring at the front of the screen of a lump of code-like text, suddenly asked a sentence: "This you will do?" "The tone of a procedural ape's pride and the operation of the industry's contempt. The siege lion obviously felt the air of that wisp of murderous, but in order not to give the industry to lose face, siege Lion or proud to look up, Cold said: "I look!" ”

The problem is that programmers have recently replaced a Redis server, but the replacement process is not yet down. There are two ways to do this online, one is to put the database down, then get it on the new Redis server, and then switch. Obviously, everybody's attitude to this kind of plan is two words: hehe!

Another way is to use Redis master-Slave synchronization method to let the new server in real-time synchronization of the old server, and so on after the data synchronization, in the old server will all the request while not paying attention to the time, karma! Go to the new server, from this to do a vainly disobey sense of toss server replacement, small three in a cheer in the success of the upper, oh yes!

Think of such ups and downs of the plot, Siege Lion in the night excited, male up, and then decisively boot, open the virtual machine, get up! And then...... This is a sad story, the siege lion Baidu a bunch of documents, found that Redis master-slave synchronization configuration is simply outrageous! You only need to add a line to the slave server's redis.conf configuration file:

Slaveof <masterIP> <masterport>

Such a simple configuration, siege Lion skilled operation of the virtual machine, he switched on!! He's got a IP address!! He's on the remote!! He used Yum to put up Redis!! He's starting to configure Redis!! His stout fingers in the crazy pressure of the keyboard, his mouth began to slightly raised, he is ready to meet the upcoming victory!! He doesn't feel like a man at this time! Behind him is the entire operation and maintenance industry of the attention!! Now look!! The Siege Lion started service!! He's starting to test!! Then, the test failed ...

Oh, it's a sad story!

Let's take a look at the configuration process and the problem:

Two virtual machines:

Master's IP is 192.168.31.118, no changes have been made and the Redis service is started

The IP of slave is 192.168.31.200, adding a line of configuration to the/etc/redis.conf file: slaveof 192.168.1.118 6379

The Redis service is then started.

The process of testing is on the master server, using the REDIS-CLI client to sign in to the Redis command line interface, using the FLUSHDB command to clear all keys (this process is only used for testing, you do not have to engage in a real-world command of the Heat migration), create two key-value pairs:

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/6C/74/wKioL1VJ0uXykBqlAADcEp68pjI828.jpg "title=" 1.png " alt= "Wkiol1vj0uxykbqlaadcep68pji828.jpg"/>

Then go to the slave server and use the REDIS-CLI command to log in to Redis and use the command key* to see if the data is synchronized, and the result is tragic:

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/6C/74/wKioL1VJ1a_iwW-5AABkY5G2ROw495.jpg "title=" 2.png " alt= "Wkiol1vj1a_iww-5aabky5g2row495.jpg"/>

Imagine the duang~ of the synchronized data jam, the data do not know where to go! That's what it says in the document.

Helpless, check the log bai, fortunately, Redis recorded the log, because it is slave not synchronized to the data and master did not make any other changes, then the problem is likely to be on the slave, view the Redis log on Slave, the following is the log content:

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/6C/74/wKioL1VJ1wnDM47yAAkCksV9oO4975.jpg "title=" 3.png " alt= "Wkiol1vj1wndm47yaakcksv9oo4975.jpg"/> See it? What a painful insight! Actually link was rejected?! What's the yarn??! Obviously according to the documents on the Internet Ah, and more than one document so configured Ah, for Mao so resolutely refused a single dog reasonable requirements?! The Fury Falls!!

The Siege lion is once again crushed, the program ape eye that beam light what is the matter? Clearly feel discriminated against! Night has been deep, the next day also had to prostitute the siege Lion Hanhen and sleep, sleep, siege Lion dream to his successful solution to the moment, very beautiful, very beautiful ...

Well, the story did not end, just the next day, the siege Lion finally took the time to solve the problems of other companies (the boss is OK not to read my blog, or the consequences are very serious Ah!) Siege Lion is worthy of siege Lion, he turned to the master server, it seems that master is not configured is not correct. When you watch the configuration file carefully, the Siege Lion finally shines! He sees a configuration in the configuration file that has one line:

Bind 127.0.0.1

Instant enlightened, ah, Hang Daddy Ah, this configuration is used to restrict which IP access to Redis, ah, how the online document unanimously ignore such a key configuration Ah! Can not be a little bit reproduced, writing articles when walking the brain ah Hello!! This is the pit daddy's little hooker!! Fall again!!

Then, the siege Lion put a big trick, change this configuration to: Bind 0.0.0.0 Yes, the siege Lion began to get mad Revenge of this society!! After the change to restart Redis, success, success!!! Siege lion that pair of large glasses behind the frame flashing a little bit of tears, he muttered: "Finally TM of the pass, f**k! "Master and Slave finally configured successfully!"

You think this is the end of the story? You're still too young! Is there a key configuration to match? That is in redis2.6 above, the default slave server is not allowed to perform write operations, so, this is doomed to slave from the moment of work is destined to be a spare tire! Hum, we are here to save the spare tire, so be decisive in the configuration of slave to modify the following configuration:

Slave-read-only No

Allow write operations on slave, yes, it is so capricious! As a result, the spare tire can be ready for the top, the rest of the matter to the development, so that it will be the Redis server to the new server, after the change, log on to the new server Redis and execute the command:

Slaveof no One

At this point, formally will slave from the spare tire to help the upper!

Although this is only a simple configuration, but as an operations engineer, is not relying on this little bit of accumulation, step by step slowly to the road of Daniel? OPS is not about technology, but experience! Operation is still the old spicy!!

This article is from the "Artisan" blog, please be sure to keep this source http://8838848.blog.51cto.com/8828848/1643529

Using Redis replication to realize thermal migration of REDIS servers

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.