标签:disable locking 分享 height ade ror 对象 setting writable
官网介绍看这里 http://redis.io/topics/replication
主从复制:就是主机数据更新后根据配置和策略,自动同步到备机的master/slaver机制,Master以写为主,Slave以读为主
Redis replication is a very simple to use and configure master-slave replication that allows slave Redis servers to be exact copies of master servers.
特点:
一、配从(服务器)不配主(服务器)
配置三个服务器6379,6380,6381,
需要复制三份配置文件,并分别更改端口号,pid文件名字,dump.rdb名字,
Appendonly关掉;
info replication查询主从复制的信息,初始时都是master
salveof <ip> <port> 设置主仆关系,
① 并联关系:80和81都是79的slave
② 串联关系: 79是80的master,80是81的master
先来并联关系:
① 并联关系:80和81都是79的slave
1 切入点问题?slave1、slave2是从头开始复制还是从切入点开始复制?比如从k4进来,那之前的123是否也可以复制 .
2 从机是否可以写?set可否?
127.0.0.1:6380> set k8 v8
(error) READONLY You can‘t write against a 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, so that it is not possible to write to a slave because of a mistake. This does not mean that the feature is intended to expose a slave instance to the internet or more generally to a network where untrusted clients exist, because administrative commands like DEBUG
or CONFIG
are still enabled. However, security of read-only instances can be improved by disabling commands in redis.conf using the rename-command
directive.
You may wonder why it is possible to revert the read-only setting and have slave instances that can be target of write operations. While those writes will be discarded if the slave and the master resynchronize or if the slave is restarted, 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.
3 主机shutdown后情况如何?从机是上位还是原地待命
4 主机又回来了后,主机新增记录,从机还能否顺利复制?
5 其中一台从机down后情况如何?依照原有它能跟上大部队吗?
配置文件
② 串联关系: 79是80的master,80是81的master
主从复制的原理:
每次从机联通后,都会给主机发送sync指令,主机立刻进行存盘操作,发送RDB文件给从机 ,
从机收到RDB文件后,进行全盘加载,之后每次主机的写操作,都会立刻发送给从机,从机执行相同的命令
If you set up a slave, upon connection it sends a PSYNC command.
If this is a reconnection and the master has enough backlog, only the difference (what the slave missed) is sent. Otherwise what is called a full resynchronization is triggered.触发再同步
When a full resynchronization is triggered, the master starts a background saving process in order to produce an RDB file. At the same time it starts to buffer all new write commands received from the clients. When the background saving is complete, the master transfers the database file to the slave, which saves it on disk, and then loads it into memory. The master will then send all buffered commands to the slave. This is done as a stream of commands and is in the same format of the Redis protocol itself.
You can try it yourself via telnet. Connect to the Redis port while the server is doing some work and issue the SYNCcommand. You‘ll see a bulk transfer and then every command received by the master will be re-issued in the telnet session.
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.
二、哨兵模式sentinal
(1)、新建哨兵配置文件
sentinel monitor mymaster 127.0.0.1 6379 1
故障恢复
主机79shutdown
可以看到new epoch-选举leader—elect leader -----switch master 成81,
标签:disable locking 分享 height ade ror 对象 setting writable
原文地址:http://www.cnblogs.com/qianqianchen/p/6024918.html