设为首页收藏本站
查看: 79|回复: 0

[PHP] Redis主从持久化测试

[复制链接]

论坛元老

Rank: 6Rank: 6

积分
34274
主题
17031
UID
1347
M币
67
贡献
17176

  • 发表于 2018-7-11 00:10:00 | 显示全部楼层 |阅读模式
    1:redis主从环境,均未开启持久化;当主实例宕机,从实例上的数据不受影响;当主恢复后,主实例上的数据将会继续同步到从实例,即原来的值将变为空值;[root@ser

    1:redis主从环境,均未开启持久化;
    当主实例宕机,从实例上的数据不受影响;
    当主恢复后,主实例上的数据将会继续同步到从实例,即原来的值将变为空值;
      [root@server11 ~]# /usr/local/redis2/bin/redis-cli -h 192.168.1.112 -a 123 info |grep -A 3 'Replication'
    # Replication
    role:master
    connected_slaves:1
    slave0:192.168.1.113,6379,online
    [root@server11 ~]# /usr/local/redis2/bin/redis-cli -h 192.168.1.112 -a 123
    redis 192.168.1.112:6379> set 1 a
    OK
    redis 192.168.1.112:6379> get 1
    "a"
    [root@server11 ~]# /usr/local/redis2/bin/redis-cli -h 192.168.1.112 -a 123 shutdown
    [root@server12 ~]# tail -f /var/log/messages
    Dec 3 15:27:34 server12 redis[32151]: Connecting to MASTER...
    Dec 3 15:27:34 server12 redis[32151]: MASTER  SLAVE sync started
    Dec 3 15:27:34 server12 redis[32151]: Error condition on socket for SYNC: Connection refused
    [root@server12 ~]# /usr/local/redis2/bin/redis-cli -h 192.168.1.113 -a 123
    redis 192.168.1.113:6379> get 1
    "a"
    [root@server11 ~]# /usr/local/redis2/bin/redis-server /usr/local/redis2/etc/redis.conf
    [root@server11 ~]# /usr/local/redis2/bin/redis-cli -h 192.168.1.112 -a 123
    redis 192.168.1.112:6379> get 1
    (nil)
    redis 192.168.1.112:6379> exit
    [root@server11 ~]# /usr/local/redis2/bin/redis-cli -h 192.168.1.113 -a 123
    redis 192.168.1.113:6379> get 1
    (nil)


    2:redis主从环境,香港服务器,从实例开启快照持久化
    当主实例宕机,从实例上的数据不受影响;
    当主恢复后,主实例上的数据将会继续同步到从实例,即原来的值将变为空值;   [root@server11 ~]# /usr/local/redis2/bin/redis-cli -h 192.168.1.112 -a 123
    redis 192.168.1.112:6379> get 1
    (nil)
    redis 192.168.1.112:6379> set 1 a
    OK
    redis 192.168.1.112:6379> set 2 b
    OK
    redis 192.168.1.112:6379> exit
    [root@server11 ~]# /usr/local/redis2/bin/redis-cli -h 192.168.1.112 -a 123 shutdown
    [root@server12 ~]# /usr/local/redis2/bin/redis-cli -h 192.168.1.113 -a 123
    redis 192.168.1.113:6379> get 1
    "a"
    redis 192.168.1.113:6379> get 2
    "b"
    redis 192.168.1.113:6379> exit
      
    [root@server11 ~]# /usr/local/redis2/bin/redis-cli -h 192.168.1.112 -a 123
    redis 192.168.1.112:6379> get 1
    (nil)
    redis 192.168.1.112:6379> get 2
    (nil)
    redis 192.168.1.112:6379> exit
      [root@server12 ~]# /usr/local/redis2/bin/redis-cli -h 192.168.1.113 -a 123
    redis 192.168.1.113:6379> get 1
    (nil)
    redis 192.168.1.113:6379> get 2
    (nil)
    redis 192.168.1.113:6379> exit
      

      
      3:推进一层,当主,从实例均宕机的情况下会如何呢?
       [root@server11 ~]# /usr/local/redis2/bin/redis-cli -h 192.168.1.112 -a 123
    redis 192.168.1.112:6379> set 1 a
    OK
    redis 192.168.1.112:6379> set 2 b
    OK
    redis 192.168.1.112:6379> set 3 c
    OK
    redis 192.168.1.112:6379> exit
    [root@server11 ~]# /usr/local/redis2/bin/redis-cli -h 192.168.1.113 -a 123
    redis 192.168.1.113:6379> get 1
    "a"
    redis 192.168.1.113:6379> get 2
    "b"
    redis 192.168.1.113:6379> get 3
    "c"
    redis 192.168.1.113:6379> exit

    这次先关闭从实例,香港服务器租用,再关闭主实例!启动则先启动从实例,测试数据;再启动主实例,美国空间,再测试数据!
    [root@server11 ~]# /usr/local/redis2/bin/redis-cli -h 192.168.1.112 -a 123 shutdown
    [root@server12 ~]# /usr/local/redis2/bin/redis-cli -h 192.168.1.113 -a 123 shutdown
    [root@server12 ~]# /usr/local/redis2/bin/redis-server /usr/local/redis2/etc/redis.conf

    [root@server11 ~]# /usr/local/redis2/bin/redis-cli -h 192.168.1.113 -a 123
    redis 192.168.1.113:6379> get 1
    "a"
    redis 192.168.1.113:6379> get 2
    "b"
    redis 192.168.1.113:6379> get 3
    "c"

    [root@server11 ~]# /usr/local/redis2/bin/redis-server /usr/local/redis2/etc/redis.conf
    [root@server11 ~]# /usr/local/redis2/bin/redis-cli -h 192.168.1.112 -a 123
    redis 192.168.1.112:6379> get 1
    (nil)
    redis 192.168.1.112:6379> get 2
    (nil)
    redis 192.168.1.112:6379> get 3
    (nil)
    redis 192.168.1.112:6379> exit

    [root@server11 ~]# /usr/local/redis2/bin/redis-cli -h 192.168.1.113 -a 123
    redis 192.168.1.113:6379> get 1
    (nil)
    redis 192.168.1.113:6379> get 2
    (nil)
    redis 192.168.1.113:6379> get 3
    (nil)
    redis 192.168.1.113:6379> exit

    实践证明,在redis主从读写分离条件下,快照持久化只有开在主实例侧才可以保证数据可以跨越实例重启!
    回复

    使用道具 举报

    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    在我站开通SVIP可同时获得17个站点VIP资源 立即登录 立即注册
    快速回复 返回顶部 返回列表