博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Redis主从持久化测试
阅读量:5798 次
发布时间:2019-06-18

本文共 4612 字,大约阅读时间需要 15 分钟。

hot3.png

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主从读写分离条件下,快照持久化只有开在主实例侧才可以保证数据可以跨越实例重启!

[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> set 4 d
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 4
"d"
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@server11 ~]# /usr/local/redis2/bin/redis-server /usr/local/redis2/etc/redis.conf
[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.112 -a 123  get 4
"d"
[root@server11 ~]# /usr/local/redis2/bin/redis-cli -h 192.168.1.113 -a 123  get 4
"d"

转载于:https://my.oschina.net/u/945017/blog/107976

你可能感兴趣的文章
设计模式之-工厂模式、构造函数模式
查看>>
python matplotlib 中文显示参数设置
查看>>
数据库事务隔离级别
查看>>
os模块大全详情
查看>>
【ros】Create a ROS package:package dependencies报错
查看>>
从内积的观点来看线性方程组
查看>>
kali linux 更新问题
查看>>
HDU1576 A/B【扩展欧几里得算法】
查看>>
廖雪峰javascript教程学习记录
查看>>
WebApi系列~目录
查看>>
限制CheckBoxList控件只能单选
查看>>
Java访问文件夹中文件的递归遍历代码Demo
查看>>
项目笔记:测试类的编写
查看>>
如何迅速分析出系统CPU的瓶颈在哪里?
查看>>
通过容器编排和服务网格来改进Java微服务的可测性
查看>>
re:Invent解读:没想到你是这样的AWS
查看>>
PyTips 0x02 - Python 中的函数式编程
查看>>
阿里云安全肖力:安全基础建设是企业数字化转型的基石 ...
查看>>
使用《Deep Image Prior》来做图像复原
查看>>
如何用纯 CSS 为母亲节创作一颗像素画风格的爱心
查看>>