Redis master-slave Replication

Source: Internet
Author: User

I. redis master-slave replication features:
1. Master can have multiple slave (slave)
2. Multiple Server Load balancer instances can be connected to the same master or other Server Load balancer instances.
3. Master-slave replication does not block the master node. During data synchronization, the master node can continue to process client requests.
4. Improve system scalability
5. You can disable data persistence on the master and comment out all save configurations in the master configuration file. You only need to configure data persistence on the slave.

 
# If one of the keys data is changed, it will be refreshed to disk once every 900 seconds # Save 900 1 # When 10 keys data is changed, refresh to disk once in 300 seconds # Save 300 10 # When 10000 pieces of keys data are changed, refresh to disk once in 60 seconds # Save 60

Ii. redis master-slave replication process:
After configuring slave, slave establishes a connection with the master and then sends the sync command. Whether it is the first connection or re-connection, the master will start a background process, save the database snapshot to the file, and the master process will start to collect new write commands and cache. After the background process writes a file, the master sends the file to slave. slave saves the file to the hard disk and loads it into the memory. Then the master forwards the cached command to slave, in the future, the master will send the write command received to the slave. If the master node receives synchronous connection commands from multiple slave instances at the same time, the master node starts only one process to write database images and sends them to all slave instances.

Iii. Configuration

Redis's master-slave mechanism is very powerful. One master node can have multiple slave instances, while one slave can have multiple slave instances. In this way, a powerful multi-level server cluster architecture is formed. The following shows how to perform redis data master-slave replication on multiple servers. Here I assume there are two servers, one is the Linux operating system (LAN IP: 192.168.3.159), the other is the Linux operating system (LAN IP: 192.168.3.169), and redis is installed on both operating systems, for details about the installation process, see http://blog.csdn.net/ajun_studio/article/details/6698147.

At this point we want to use Linux, here we use centos5.4, redis using redis-2.0.4.

Here I use one master and one slave (master is in a Linux environment and one slave is in a Linux environment. The basic process is as follows:

Client ----- whrite ----- >>> [Linux (Master 192.168.3159: 6379)] <------------------ slave ---- [Linux (slave 192.168.3.169: 6381)] <------ read --------- Client

1. Modify redis. conf on the master

 
Bind 192.168.3.159

2. Modify redis. conf on slave

 
Port 6381 (separate service port numbers) bind 192.168.3.169slaveof 192.168.3.159 6379 (set the host and port of the master)

3. Start the service

Start master first

 
Redis-server redis. conf

Then start slave

 
Redis-server redis. conf

View the log

 
* Connecting to master... [5374] 23 Aug 03:33:20 * flushing ing 5479067 bytes data dump from Master [5374] 23 Aug 03:33:21 * master <-> slave sync succeeded

Congratulations, Master/Slave replication is successful.

Perform a client test.

Connect to the master to add data

 
#./Redis-cli-H 192.168.3.159-P 6379 redis> Set Name ajunok

Connect to slave to retrieve data

 
#./Redis-cli-H 192.168.3.169-P 6381 redis> get name 'ajun'

So far, your redis master-slave replication has been a complete success !!!

Experiment now !!!

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.