Redis Configuration Master-slave architecture for read-write separation

Source: Internet
Author: User
Tags redis

The master-slave architecture of Redis enables us to read more and write less, so it's easy to configure the Redis architecture below.

Prepare for the Environment VMware + rhel-server-7.0 (101,102,103) +redis-3.2.0

1, installed in 192.168.137.101 redis3.2.0, I installed the directory as follows

Redis Installation Reference http://blog.csdn.net/yingxiake/article/details/51469364

2. Copy the Redis folder to Linux 102 and 103 via SSH

SCP-RF Redis/root@192.168.137.102:/home/redis
SCP-RF Redis/root@192.168.137.103:/home/redis

The 102,103 Redis directory is as follows, indicating that copy succeeded

3, configure master and slave relationship, there are two ways

A) Set slaveof in redis.conf, permanently

Slaveof <masterip> <masterport>

b) using the REDIS-CLI client to set up the Redis service, temporarily, the Redis restart fails

Slaveof <masterip> <masterport>

The conf/redis.conf configuration file in 102 and 103 is configured with a slave relationship of 101

Master's password can be configured directly inside the configuration file

4, check the settings, use the following command

Info replication

101 of the master-slave relationship, you can see slaves the number of connections and IP address, port

102,103 master-Slave relationship, you can see the IP address, port

If you find that the configuration is not a problem, but Master_link_status has been down,connected_slaves has been 0, look under, is not three IP can not be spelled, if you can spell, to see if the lower port can be spelled through, You can use Telnet on Windows

Telnet 192.168.137.101 6379

If you find that you are unable to spell, modify the configuration file to

Bind 127.0.0.1

Comment out, restart the service, try again, refer to the next http://blog.csdn.net/yingxiake/article/details/51472810

5, test whether data synchronization

Set a key and value in master

Get Data on 101 and 102 respectively

The data synchronization is successful, then the 102down is dropped, then restarted, and then the Get data

The data recovery is successful, it is also indicated in the master-slave structure, slave cannot write the data

Steps for Master-slave replication:

1. When you start linking the primary server from the server, a SYNC command is sent to the primary server
2, after the main service receives the command, executes the BGSAVE, asynchronously saves the write command in a buffer
3. After the primary server finishes executing Bgsave, the. rdb file (the BOF persistence file) is sent to the slave server, recovering data from the file to memory from the server
4, the master server will also be in the format of the Redis command protocol, the write command buffer accumulation of all the content is sent to the slave server, from the server through the execution of commands to restore data into memory

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.