Redis Master-Slave configuration-related scripts

Source: Internet
Author: User
Tags redis time interval



  < c15>1 redis Master service configuration 1.1 Overview

Redis's master-slave replication feature is very powerful, a master can have multiple slave, and a slave can have more than slave, so continue to form a powerful multi-level server cluster architecture. Master-Slave synchronization, with the following benefits:

To realize the backup of data, reduce the loss of single point of failure, and facilitate load balancing. Originally a server responsible for all the data read and write, and through the master-slave synchronization, you can have more than the server is responsible for data read, and the main server is responsible for the data write, reduce the single point of pressure.

1.2 Implementation Mechanism

(1) The slave server is connected to the master server.

(2) The slave server sends the SYCN command.

(3) The master server backs up the database to an. rdb file.

(4) The master server transmits the. rdb file to the slave server.

(5) The slave server imports the. rdb file data into the database.

The above 5 steps are the first phase of synchronization, and then each command called on the master server is synchronized to the slave server using Replicationfeedslaves (). and Replicationfeedslaves () The main task is to send the user executed commands to all slave servers, let the slave server execute. This allows the synchronization function to be implemented.

1.3 Related Configurations

Case:

Main service: 172.168.10.254 6379

From service: 172.168.10.254 6380

Modify the redis.conf configuration file with the following main configuration:

1) Configure the appropriate IP and port

Main:

bind172.168.10.254 #绑定主机IP, (must be modified to network card IP address)

Port 6379 #监听端口, default is 6379

From:

bind172.168.10.254 #绑定主机IP, (must be modified to network card IP address)

Port 6380 #监听端口, default is 6379

2) Modify the configuration from the service redis.conf:

slaveof172.168.10.254 6379 #设置主服务的IP及端口

Slave-read-only Yes #配置从机是否只读

Masterauthpwd123 #设置主服务的连接密码

Slave-serve-stale-datayes #在master服务器挂掉或者同步失败时 Whether the service continues to be available from the server.

#repl-PING-SLAVE-PERIOD10 #master端ping The time interval at the slave end to detect the effective slave connection at all times
#repl-TIMEOUT60 # Replication connection time-out

#slave-priority100 #slave的权重, used in Redis Sentinel mode, if Masterdown, the large weight slave takes over master

Slave-priority100 #slave级别, the smaller the number level (in master hangs, slave upgrade to use)

1.4 Test Verification

After the master-slave service configuration is complete, start the corresponding service;

1) from the service log information will be displayed to synchronize data from the Masger Master service:



2) The primary service log information will display slave from the synchronization data successfully:

 

 

3) Connect with REDIS-CLI respectively:

[root@centosredis]# redis-cli-h 172.168.10.254-p 6379

172.168.10.254:6379>

[root@centosredis]# redis-cli-h 172.168.10.254-p 6380

172.168.10.254:6380>

4) Test:

Set the corresponding key data in the main service:

 



The corresponding synchronization data can be viewed from the service:

You can see the corresponding log files for the master and slave services at this time:

Main services:


From the service:


 

What you can see is that when the primary service data changes, it synchronizes to the slave service in real time.

The Redis Master Service data Synchronization configuration is complete.

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.