Redis Master-Slave configuration experience and its highly available solution

Source: Internet
Author: User
Tags redis port number

Redis master-slave replication process

When slave is configured, slave establishes a connection with master and then sends the Sync command. Whether it is the first connection or reconnection, master initiates a background process, saves the DB snapshot to a file, and the master master process starts collecting new write commands and caches. After the background process finishes writing the file, master sends the file to Slave,slave to save the file to the hard disk, then loads it into memory, then master forwards the cached command to the slave, and the subsequent master sends the received write command to slave.

If master receives multiple slave simultaneous connection commands at the same time, master initiates only one process to write database mirroring and then sends it to all slave. Master synchronizes data with non-blocking and can receive read and write requests from users. However, on the slave side is blocking mode, slave is not able to respond to client queries when synchronizing master data.

You can disable data persistence in master, just comment out all the save configurations in the master configuration file and configure data persistence on slave only

The advantage of having a master-slave server (from the server is read-only, can be a main multi-slave)

1. When the primary server reads and writes, it shifts to read from, easing the server pressure

2. Hot backup master and slave can set the password, can also be inconsistent password

Enter/usr/data/redis/slave

Create Master slave1 slave2

1. Copy redis.conf to 3 directories, modify port 1000,2000,3000

2. Modify the PID path, log path

Pidfile/usr/data/redis/slave/master/redis.pid

Logfile/usr/data/redis/slave/master/redis.log

Ps-ef | grep Redis

Root 19000 1 0 08:27? 00:00:00 Redis-server 192.168.1.1:1000

Root 19012 1 0 08:27? 00:00:00 Redis-server 192.168.1.1:2000

Root 19016 1 0 08:27? 00:00:00 Redis-server 192.168.1.1:3000

Connecting clients

[root@iz23pv5rps8z ~]# redis-cli-h 192.168.1.1-p 3000

View Permissions

192.168.1.1:3000> Info

3 Servers are # Replication Role:master

Set from server mode

1. Command mode

# Replication

Role:master

Connected_slaves:2

Slave0:ip=192.168.1.1,port=2000,state=online,offset=113,lag=0

Slave1:ip=192.168.1.1,port=3000,state=online,offset=113,lag=0

master_repl_offset:113

# Replication

Role:slave

master_host:192.168.1.1

master_port:1000

Master_link_status:up

Server stopped, master and slave will not work

2. Configuration files

# slaveof

Slaveof 192.168.1.1 1000

Server stopped, master and slave still working

Master-Slave synchronization, 2 passwords can be inconsistent

192.168.1.1:1000> Set lyg945 Liuyonggang

192.168.1.1:1000> Get lyg945

"Liuyonggang"

192.168.1.1:2000> Get lyg945

"Liuyonggang"

192.168.1.1:3000> Get lyg945

"Liuyonggang"

Redis Master-Slave architecture, if master found fault, also have to manually switch slave to master continue service, manual way prone to error, resulting in data loss, that Redis has a mechanism can be monitored in master and slave, And when the master sends the fault, can automatically switch the slave to master. Yes, that's the sentry.

The role of Sentinel:

1. Monitor Redis status, including master and slave

2, when master down machine, can automatically switch slave to master

The following configuration Sentinel monitoring Redis process, if we have configured the master and slave, detailed configuration parameters

Manually Switch Master

Master slaveof NO One

Slave slaveof 192.168.1.1 3000

Create Sentinel

Touch sentinel.conf content as follows

Sentinel monitor hostname host IP host port number of votes n votes redundant n slave machine as host

Sentinel Monitor MyMaster 192.168.1.1 1000 1

Start Sentinel

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.