redis Lord's recovery and persistent sense from replication failures

redis Lord's recovery and persistent sense from replication failures
Server configuration: (centos7)

IP server Installation Components node Remark
192.168.27.210 repeat-5.0.5 master A two master-slave architecture
192.168.26.112 repeat-5.0.5 slave
192.168.26.206 repeat-5.0.5 slave

Download the latest version to each node: Wget http://download.redis.io/releases/redis-5.0.5.tar.gz
redis Lord's recovery and persistent sense from replication failures
extracting archive and configuration:
redis Lord's recovery and persistent sense from replication failures
redis Lord's recovery and persistent sense from replication failures
switch user (user ROOT less production operation)
[Jerry Data the @Master] $ the sudo chown -R & lt jerry.root Redis-5.0.5
redis Lord's recovery and persistent sense from replication failures
of Cd /data/redis-5.0.5/src
the make
192.168.27.210 profile: vim /data/redis-5.0.5/redis-m-7000 .conf
the bind 0.0.0.0
Port 7000
logfile "7000.log"
dbfilename "dump-7000.rdb"
daemonize yes
rdbcompression yes

192.168.26.112 configuration:
Cd /data/redis-5.0.5/src
the make

[jerry@BDDB redis-5.0.5]$ vim /data/redis-5.0.5/redis-s-7000.conf
redis Lord's recovery and persistent sense from replication failures
bind 0.0.0.0
port 7000
logfile "7000.log"
dbfilename "dump-7000.rdb"
daemonize yes
rdbcompression yes
slaveof 192.168.27.210 7000

192.168.26.206配置:
Cd /data/redis-5.0.5/src
make
redis Lord's recovery and persistent sense from replication failures
bind 0.0.0.0
port 7000
logfile "7000.log"
dbfilename "dump-7000.rdb"
daemonize yes
rdbcompression yes
slaveof 192.168.27.210 7000
分别启动各结点:
[jerry@master src]$ ./redis-server ../redis-m-7000.conf
redis Lord's recovery and persistent sense from replication failures
[jerry@BDDB src]$ sudo ln -s /data/redis-5.0.5/src/redis-server /usr/bin/redis-server
[jerry@BDDB src]$ redis-server ../redis-s-7000.conf
redis Lord's recovery and persistent sense from replication failures
[jerry@DGIDC src]$ sudo ln -s /data/redis-5.0.5/src/redis-server /usr/bin/redis-server
[jerry@DGIDC src]$ redis-server ../redis-s-7000.conf
[jerry@DGIDC src]$ ss -tnl
redis Lord's recovery and persistent sense from replication failures
看下三台服务器主从状态信息:
redis Lord's recovery and persistent sense from replication failures
接着我们创建键值,测试主从是否同步:
三个结点我们都创建一个链接,方便我们使用。
[jerry@master src]$ sudo ln -s /data/redis-5.0.5/src/redis-cli /usr/bin/redis-cli
[jerry@BDDB src]$ sudo ln -s /data/redis-5.0.5/src/redis-cli /usr/bin/redis-cli
[jerry@DGIDC src]$ sudo ln -s /data/redis-5.0.5/src/redis-cli /usr/bin/redis-cli
观察主从信息状态:
redis Lord's recovery and persistent sense from replication failures
info
redis Lord's recovery and persistent sense from replication failures
redis Lord's recovery and persistent sense from replication failures
重启主后服务器观察发现未保存的数据将丢失:
redis Lord's recovery and persistent sense from replication failures
redis Lord's recovery and persistent sense from replication failures
结论:
使用主从模式时应注意master节点的持久化操作,matser节点在未使用持久化的情况详情下如果宕机,并自动重新拉起服务,从服务器会出现丢失数据的情况。数据丢失的原因:因为master服务挂了之后,重启服务后,slave节点会与master节点进行一次完整的重同步操作,所以由于master节点没有持久化,就导致slave节点上的数据也会丢失掉。所以在配置了Redis的主从模式的时候,应该打开主服务器的持久化功能。
测试使用哨兵模式,自动监视Master节点,当前挂掉后,自动将Slaver节点变为Master节点:
redis Lord's recovery and persistent sense from replication failures
然后手动切换从(26.206):
redis Lord's recovery and persistent sense from replication failures
127.0.0.1:7000> slaveof 192.168.26.112 7000
redis Lord's recovery and persistent sense from replication failures
127.0.0.1:7000> set name tom
redis Lord's recovery and persistent sense from replication failures
小结:

  1. Master可读可写,Slaver只能读,不能写
  2. Master可以对应多个Slaver,但是数量越多压力越大,延迟就可能越严重
  3. Master return immediately after writing, writes substantially simultaneously synchronized to each asynchronous Slaver, so basically negligible delay
  4. Slaver can be upgraded by slaveof no one command as Master (Master hang up when the manual will become a Slaver Master)
  5. Can be monitored by sentinel sentry mode Master, hang up automatically when the Master Slaver election becomes Master, Slaver other automatic reconnection new Master (automatic unsuccessful sometimes need to manually cut the main, temporarily not find the specific reasons)

Guess you like

Origin blog.51cto.com/jdonghong/2443476