25.redis of the master-slave replication

1. What is the master-slave replication

  Master-slave replication can Redis scalability, and more stable performance than the stand-alone version of Redis, Redis master-slave-master replication and relational databases from almost copied. Accurate information from the master copy from the function.

1.1 advantages, from the master copy

  1. The separation of read and write
  2. Reduce the pressure in the master
  3 for data backup

1.2, master-slave relationship in FIG.

 

1.3 instance configuration

  Redis example three, ip address allocated as follows:

  

1. Create a profile

  The copy redis.conf profile parts 3, named for convenience to distinguish:

2. Modify were three profiles

  6379 to modify the configuration file, the following modification to 6379, without changing the default of 6379

Similarly the information related to the other two documents were revised to 6380 and 6381

3. Start example

  Examples redis start by three commands of three

4. Display example

  By entering commands are three examples

  There we successfully configured the three instances, but these three examples of this is independent of each other.

5. Configure the master-slave relationship

  Examples of set 6371 master, is a slave, so only at the point 6380 and 6381, respectively 6380 and 6381 can be ordered as follows

  To build this master-slave relationship better.

6. Review the master-slave relationship

  In the master view, execute the following command.

  You can see the role of a master, there are two slave node address port information we have to see (info replication on the implementation of 6381) on the slave.

  We can see the role as a slave, master information corresponding also have.

7. Test

  Add a message on the master, viewing on the slave.

  主从复制需要注意的地方
  1.如果master已经运行了一段时间,slave才连上来,此时slave会对master的所有数据进行同步,而不是从连接上的时间点同步!
  2.master节点可读可写,但是slave节点只读不可写(如果非要写可以修改redis.conf文件中的slave-read-only的值来实现)
  3.在当前的这个主从结构中,如果master挂点,重启后依然还是master,主从操作依然可用。

2、复制原理

2.1、全量复制

  Redis全量复制一般发生在Slave初始化阶段,这时Slave需要将Master上的所有数据都复制一份。具体步骤如下:

  

  完成上面几个步骤后就完成了从服务器数据初始化的所有操作,从服务器此时可以接收来自用户的读请求。

2.2、增量复制

  Redis增量复制是指Slave初始化后开始正常工作时主服务器发生的写操作同步到从服务器的过程。 增量复制的过程主要是主服务器每执行一个写命令就会向从服务器发送相同的写命令,从服务器接收并执行收到的写命令。

  复制偏移量:执行复制的双方——主服务器和从服务器会分别维护一个复制偏移量

  

  注意只要是slave重新连接master都会自动执行一个全量复制。

 

Guess you like

Origin www.cnblogs.com/wangdh666/p/11265149.html