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

[经验分享] redis replication

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2015-12-23 10:27:17 | 显示全部楼层 |阅读模式
redis 下载地址:http://download.redis.io/releases/redis-3.0.0.tar.gz  
  redis安装
  [size=1em]$ wget http://download.redis.io/releases/redis-3.0.0.tar.gz
  [size=1em]$ tar xzf redis-3.0.0.tar.gz
  [size=1em]$ cd redis-3.0.0
  [size=1em]$ make
  $ src/redis-server[size=1em]
  
  redis 主从复制
  以下是关于 Redis 复制功能的几个重要方面:
1. 一个Master可以有多个Slave。
2. Redis使用异步复制。从2.8开始,Slave periodically acknowledge the amount of data processed from the replication stream.
3. 不仅主服务器可以有从服务器, 从服务器也可以有自己的从服务器, 多个从服务器之间可以构成一个图状结构;
4. 复制在Master端是非阻塞模式的,这意味着即便是多个Slave执行首次同步时,Master依然可以提供查询服务;
5. 复制在Slave端也是非阻塞模式的:如果你在redis.conf做了设置,Slave在执行首次同步的时候仍可以使用旧数据集提供查询;你也可以配置为当Master与Slave失去联系时,让Slave返回客户端一个错误提示;
6. 当Slave要删掉旧的数据集,并重新加载新版数据时,Slave会阻塞连接请求(一般发生在与Master断开重连后的恢复阶段);
7. 复制功能可以单纯地用于数据冗余(data redundancy),也可以通过让多个从服务器处理只读命令请求来提升扩展性(scalability): 比如说, 繁重的 SORT 命令可以交给附属节点去运行。
8.It is possible to use replication to avoid the cost of having the master write the full dataset to disk: just configure your master redis.conf to avoid saving (just comment all the "save" directives), then connect a slave configured to save from time to time. However in this setup make sure masters don't restart automatically (please read the next section for more information).
  
  9.In setups where Redis replication is used,it is strongly advised to have persistence turned on in the master, or when this is not possible, for example because of latency concerns, instances should be configured to avoid restarting .
  
10,在master上一定要开启持久化,否则很危险。  Redis复制工作原理
1. 如果设置了一个Slave,无论是第一次连接还是重连到Master,它都会发出一个SYNC命令;
2. 当Master收到SYNC命令之后,会做两件事:
a) Master starts background saving,即在后台保存数据到磁盘(rdb快照文件);
b)  buffer all new commands received that will modify the dataset.(非查询类);
3. 当Master在后台把数据保存到快照文件完成之后,Master会把这个快照文件传送给Slave,而Slave则把内存清空后,加载该文件到内存中;
4. 而Master也会把此前收集到缓冲区中的命令,通过Reids命令协议形式转发给Slave,Slave执行这些命令,实现和Master的同步;
  5.Slaves are able to automatically reconnect when the master  slave link goes down for some reason. If the master receives multiple concurrent(并发) slave synchronization requests, it performs a single background save in order to serve all of them.
5. Master/Slave此后会不断通过异步方式进行命令的同步,达到最终数据的同步一致;
6. 需要注意的是Master和Slave之间一旦发生重连都会引发全量同步操作。但在2.8及之后版本,也可能是部分同步操作。
  
  
部分复制
  2.8开始,当Master和Slave之间的连接断开之后,他们之间可以采用持续复制处理方式代替采用全量同步。
  This works by creating an in-memory backlog of the replication stream on the master side.
  The master and all the slaves agree on a replication offset and a master run>
   
  when the link goes down, the slave will reconnect and ask the master to continue the replication. Assuming the master run>, and that the offset specified is available in the replication backlog, replication will resume from the point where it left off. 
  
  If either of these conditions are unmet, a full resynchronization is performed
As the run> a full resynchronization is needed when the slave restarts.
  
Diskless replication  
Normally a full resynchronization requires to create an RDB file on disk, then>
With slow disks this can be a very stressing operation for the master. Redis version 2.8.18 will be the first version to have experimental support for diskless replication. In this setup the child process directly sends the RDB over the wire to slaves, without using the disk as intermediate storage.
The feature is currently considered experimental.
Read-only slave
Since Redis 2.6, slaves support a read-only mode that is enabled by default. This behavior is controlled by the slave-read-only option in the redis.conf file, and can be enabled and disabled at runtime using CONFIG SET.
Read-only slaves will reject all write commands,  there are a few legitimate use case for storing ephemeral data in writable slaves. However in the future it is possible that this feature will be dropped.
  Redis主从实施
  ip         192.168.28.18     192.168.28.28
  port         6379 6380        6379 
  
  192.168.28.18
  cd redis-3.0.0/
  mv redis.conf  redis-master6379.conf
  mv redis.conf  redis-master6380.conf
  
  master 配置192.168.28.18 6379
  vi redis-master6379.conf
  1、打开master持久化操作。AOF和RDB持久化比较??
  appendonly yes
  appendfsync everysec
  
  2、设置redis 连接密码
  requirepass April
  
  192.168.28.18 6379 的slave 配置:192.168.28.18 6380 192.168.28.28 6379 
  port 6380  --一太机器上redis的端口不要冲突
  REPLICATION下配置:
  slaveof 192.168.28.18 6379  master的ip和port
  masterauth April
  
  run
  192.168.28.18:
  src/redis-server redis-master6379.conf
  src/redis-server redis-slave6380.conf  &
  192.168.28.28
  src/redis-server redis.conf
  
  test
  src/redis-cli -h 192.168.28.18 -p 6379 -a April
  192.168.28.18:6379> set name biggerl
  
  192.168.28.18:6380> get name
  "biggerl"
  
  [redis@datanode-1 redis-3.0.0]$ src/redis-cli -h 192.168.28.28 -p 6379 -a April
  192.168.28.28:6379> get name
  "biggerl"
  
  默认slave都是readonly,写会返回error
  192.168.28.28:6379> set file speed7
  (error) READONLY You can't write against a read only slave.
  
  
  
  FYI:http://www.cnblogs.com/Xrinehart/p/3501372.html

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-155145-1-1.html 上篇帖子: redis AOF落地策略rewrite导致阻塞问题 下篇帖子: Redis安装及初步使用
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表