A master-slave replication

Setting the master-slave relationship

By info replication command to view the node set master-slave relationship slaveof main library main library port ID as: slaveof 127.0.0.1 6379 
after the main library down, want from the library stop synchronization with other databases, turn into the main library, slaceof on one, other data path it wants to connect, but also to set the main library commands executed, whether the person will always be waiting for the old main library 

common way, a main two servants, Passing the torch

 

Passing the torch with a main two servant

# A two master slave 
    only one branch, many 



# Passing the torch 
    middle slave will be the Master of the next slave, and a slave can also receive a connection request to synchronize other slaves, then as the next slave in the chain master can effectively alleviate the pressure of the master writing 
the middle of the slave remains a slave role 

    midway change turn, clears the data prior to re-establish the latest copy

 

common problem

# 1, regardless of when the machine is set up, all the important settings from the copy machine, will host again (before the machine will be set up from) 

# 2, separate read and write, read-only permission from the machine, from machine the write operation is not permitted 


# 3, the host is down, the machine from the role will not change, such as the host after recovery, business as usual 

# 4, disconnected from the machine will be disconnected, the next need to connect unless the configuration file

 

 

 

 

 

Exercise

Modify the configuration file

 First redis.conf configuration file three copies, by modifying the three-port analog Redis server respectively.

  

  Then we were three redis.conf these files to be modified.

 ①, modify daemonize yes

  

  Expressed in the manner specified Redis start daemon (background boot)

  ②, PID configuration file path pidfile

  

  Redis indicate when running as a daemon, it will default pid file is written inside /var/redis/run/redis_6379.pid

  ③, port configuration port

  

  ④, the configuration log file name

  

  ⑤, the configuration file name rdb

  

  Turn 6380redis.conf, 6381redis.conf a configuration, the configuration is completed.

  Next we were starting all three services.

  

  Redis command to see whether the start:

  

  Next, enter the following command to each of the three Redis client:

redis-cli -p 6379 
repeat -cli -p 6380 
repeat -cli -p 6381

 

 

Setting the master-slave relationship

 ①, see the node via info replication command

      

  

  We found three nodes are playing the role of Master. So how will 6380 and 6381 node becomes the Slave role?

  ②, select the 6380 port and 6381 port, execute the command: SLAVEOF 127.0.0.1 6379

      

  We look at 6379 node information:

  

  Here to set the command master-slave relationship, once the service is restarted, then the role of the relationship will cease to exist. Want to permanently save this relationship can be configured by redis.conf configuration file.

Guess you like

Origin www.cnblogs.com/pdun/p/11285156.html