and the master copy from redis Sentinel Model

What is Redis master-slave replication?

Jargon: what we call the master-slave replication, host data is updated according to configuration and policy,

Automatically synchronized to the standby machine master / slaver mechanisms, Master to write the main, Slave read-mostly

 

Redis master-slave replication can be doing?

(1) separate read and write

(2) disaster recovery

 

Redis configuration from the master copy (from the main 2)

Knowledge Note:

(1) with the (library) unworthy master (library)

(2) from the library configuration: slaveof main library IP host port library

(3) info Replication view the current redis node information (or from the main etc.)

 

2 from the master configuration 1 redis

Start the configuration:

Here do presentations is installed on a machine, to facilitate learning (production environment is installed on different machines)

We are not here to install three redis, but a copy has three configuration files to distinguish.

Namely: redis6379.conf, redis6380.conf, redis6381.conf

 

 

Modify the configuration file content :( modification here is to distinguish between different machines, 6379 is the port number )

yes daemonize : turn back to start

the p- the above mentioned id  /var/run/redis6379.pid pid file with the port number to distinguish

P ort 6379 designated port

logfile "redis6379.log" specified log file name

dump6379.rd dbfilename b used here is rdb persistent way, then modify the snapshot file name rdb

(Each profile needs to be modified)

 

After modifying the configuration files, respectively redis start three processes:

../bin/redis-server redis6379.conf

../bin/redis-server redis6380.conf

../bin/redis-server redis6381.conf

 

See if started successfully:

We can see redis three processes are in 6380,6381,6379 three port numbers started.

 

These three are connected redis process, redis view the current status:

6379 Port:

 

6380 Port:

 

 

6381 Port:

 

Now you can see, three redis process status is master, no slave.

 

Start master-slave replication configurations:

A master, two slave.

Definition: 6379 when the master, 6380 and 6381 are as slave

You can see where we only pay attention: with the (library) do not deserve master (library)

Okay, respectively redis in 6380 and 6381 related to the redis 6379's:

slaveof 127.0.0.1 6379

(Note: We are here to associate the Lord's command mode, the current redis closed shall lapse if you want to restart but also the associated master, you need to configure the configuration file.)

 

Then we'll see the status of the 6380 and 6381 ports redis:

We can see two hosts have been changed to the slave, but also information identifying the master.

If you have appeared above picture shows, the 2 representatives from the main configuration successful.

 

Test 2 from primary redis 1

 

(1) slave1, slave2 from scratch or copy from the starting point to begin copying? Currently have on the host device k1 k2 k3, and only association come from the machine, then the machine can get from k1 k2 k3 it?

test:

The primary server to write key

 

To go from the service associated with the primary server, pick up key

The answer is yes! ! ! Analysis, should be associated with the host device from the machine, will host device are all key to copy from a machine

 

(2) from the machine if you can write? You can set? If the primary server can read it? Can get

test:

In writing from the machine: redis will prompt you're just a slave can only be read but not write.

 

Read on the host: can be read, read and write host

 

 

(3) What about the host shutdown? From the host machine is still on standby

test:

Host shutdown:

View slave status:

It can be seen from the machine status did not change from the machine is in standby place

 

(4) After the host is back, add a host record, also can successfully copied from the machine?

test:

From the start the host, write a k5

In obtaining from the machine k5:

K5 get success from the machine.

get conclusion:

Host came back and add recorded successfully copied from the function data on the host.

 

 

( 5 ) one of them from the machine down how the situation? In accordance with the original large forces can keep up with it?

test:

Closed from the machine, restarted the slave.

Host writes k6, k6 get from the machine, you will find is not enough.

why? When the installation has been said:

(Note: We are here to associate the Lord's command mode, the current redis closed shall lapse if you want to restart but also the associated master, you need to configure the configuration file.)

If you do not believe you can go to the next state from the current machine, it has become a master.

Here not posted a screenshot.

 

Passing the torch

What is passing the torch?

A S Lave may be a slave of the next m ASTER, S Lave can also receive other

slaves and synchronous connection request, then the slave as a chain of a next master,

Can effectively reduce the pressure to write the master .

 

note:

Turn midway change: Data will be cleared before re-establish the latest copy

 

Passing the torch set

slaveof new main library IP port the new primary database

 

I was here with a good 6379,6380,6381 do take the case before.

Host: 6379

Slave: 6380,6381

 

The 6381 point to 6380 ,. 6380 or 6379 points (unchanged).

6381 Port redis information:

 

6380 Port redis information:

You can see port 6380 redis or slave, but underneath it there is a slave, it is 6381, and now we have good configuration succeeded.

 

Test: Modify the value in 6379, the 6380 must be taken to see if the 6381 can take to

 

ok, you can also get the 6381 value, then passing the torch success! ! ! !

 

Become masters

What is to become masters?

When the host goes down, then we can manually stop the slave and master synchronization of the slave to turn into the main machine. Other then this current slave master synchronization data, as a separate system.

 

Commands:

slaveof no one that the current database is synchronized with other databases to stop, turn into a main database .

 

Become masters Case:

If the host is now hung up: here it is manually turned off, the analog hang

View slave status:

 

Here you can find the status of the master is down, it will now be redis port 80 is set to host 81 port redis do slave port 80:

slaveof no one that the current database is synchronized with other databases to stop, turn into a main database .

Info replication see the current information about a redis can be found already a master of the current

 

Then 81 related to the 80, and then view the information on the 81 currently, we can see the association of the master is redis 80.

slaveof 127.0.0.1 6380

The test is successful master-slave replication:

 

testing successfully! ! Write data on the 80, 81 can be read on to.

 

Redis master-slave replication principle

Full volume copying:

It sends a sync command to start successfully connected to the master slave

m ASTER save process start command to the background, while collecting all the received command for modifying the data set,

After the background process is finished, master transfers the entire data file to the slave, to complete a full synchronization

The slave database service after receiving the data file, save it and load it into memory.

 

Incremental Copy:

m ASTER continue to collect all the new modification commands sequentially passed Slave , complete synchronization .

 

note:

( But as long as is reconnected Master , back to automatically perform a full synchronization (full volume copy) )

 

Sentry mode (sentinel)

What is the sentry mode?

To become masters of the automatic version, the background can monitor whether the host fault, if fault according to the number of votes from the library automatically converted to a master database .

 

Sentinel realization mode

We still use the machine to demonstrate 6379,6380,6381.

(First 2 from the main recall situation here is not to demonstrate.)

Host: 6379

Slave: 6380,6381

(1) create a file named in the / usr / local / Redis / conf sentinel.conf file and write the contents

sentinel monitor monitored database name (from their own name ) 127.0.0.1 6379 1

The last number above 1 indicates the host let hang salve vote to see who takes over as host, votes more than the redis become host

Note: This is the host to be monitored

 

(2) Start Sentinel

This is my catalog:

Here are some of bin redis startup script.

I copy the config is out redis profile and just created sentinel.conf

Config directory to execute the command to start the Sentinel:

../bin/redis-sentinel sentinel.conf

( Note: The command here is based on different redis install directory also will not be the same. )

Well, if you see more than print out the map that was started successfully. Monitoring can be seen already in 6379, and it also found a 6379 machine from 6380 and 6381.

 

 Sentinel Test

(1) the original master hung up , what will happen?

Well, we test, we manually let hang 6379, will look at how to deal with Sentinel.

 

:( let down manually simulate 6379 6379 shoot down)

 

Wait a minute, see Sentinel Log:

Here has been detected 6379 host goes down, they will vote for a host, where you can see the selected host is 6380.

 

We look to the information of 6380 and 6381

6380:

 

6381:

Screenshot above you can see already, 6380 has become the host, and 6381 has changed the host association, elected into the 6380.

Summed up: If the host hung up, then the host will be out in the voting machine from the election, and modify the remaining bodies from the Union to the new host.

 

( 2 ) If the previous master restart to come back, it will double master conflict?

Testing Starts:

Restart the 6379 port redis, view its information, take a look at what the situation is:

 

See 6379 become a slave, the host is 6380.

 

And starting 6379, the Sentinel print out a log:

 

Meaning: from 6379 related to the 6380 machine.

 

Summary: After the restart before the master, and not conflict, will come from the identity of the associated host machine.

Note: a group of sentinel can simultaneously monitor multiple Master

The disadvantage of copying

Replication latency:

Since all write operations are the first in m operations on aster, then synchronize to update s on lave, so from m ASTER synchronized to s Lave machine has a certain delay, when the system is busy, delay problem will become more serious, s lave machine will also increase the number of the problem is more serious.

 

 Ok. From here to complete the master copy and the Sentinel mode! ! !

Guess you like

Origin www.cnblogs.com/lice-blog/p/11616362.html