redis three modes comparison

 

  • Mode type

(Redis3.0 later version) from the master mode (mode redis2.8 previous version), Sentinel sentinel mode (and after redis2.8 mode), redis cluster mode

  • Master-slave mode principle

From the same reason as Mysql master copy, although the speed of reading the written Redis are particularly fast, but also have read the pressure is particularly large. In order to share the pressure reading, Redis supports master-slave replication, Redis master-slave configuration may be employed in a multi-master or from the cascade structure, Redis master can be divided into the total amount of the total amount of incremental synchronization and synchronization according to whether the replication Yes. The figure below shows the cascade structure.

 

 

 

advantage:

1, solve the problem of data backup

2, separation of reading and writing, to improve server performance

Disadvantages:

1, when each client connection redis example are designated ip and a port number, if the instance is connected as redis fault down, but there is no master-slave mode to provide some additional means to notify the client connectable client address, so you need to manually change the client configuration reconnect

2, from the master mode, if the primary node is down due to a failure, then since there is no interrupt from the master node and the node synchronization, and thus require manual work failover

3, can not be achieved dynamic expansion

 

  • sentinel mode

Sentinel (Sentinel) is a high availability solutions the Redis: Sentinel Sentinel system consists of one or more instances of the master can monitor any number of servers, and all those under the master server from the server, and enters the primary server being monitored off-line mode and automatically off the assembly line under the main server upgrade from a server to a new primary server.

E.g:

 

advantage

1, Master condition monitoring

2, if Master exception, will be converted Master-slave, as a Master and a Slave in which, as the previous Master Slave 

3, the Master-Slave switch, master_redis.conf, slave_redis.conf and sentinel.conf content will change, i.e., will be more than one row slaveof master_redis.conf configuration, the monitoring target will follow exchange sentinel.conf

Disadvantages:

1, if the node is down, sentinel will not be a failover, the connection can not be obtained from the client node to a new node is available from

2、无法实现动态扩容

 

  • cluster模式

在这个图中,每一个蓝色的圈都代表着一个redis的服务器节点。它们任何两个节点之间都是相互连通的。客户端可以与任何一个节点相连接,然后就可以访问集群中的任何一个节点。对其进行存取和其他操作。

一般集群建议搭建三主三从架构,三主提供服务,三从提供备份功能。

 

每一个节点都存有这个集群所有主节点以及从节点的信息。

    它们之间通过互相的ping-pong判断是否节点可以连接上。如果有一半以上的节点去ping一个节点的时候没有回应,集群就认为这个节点宕机了,然后去连接它的备用节点。如果某个节点和所有从节点全部挂掉,我们集群就进入faill状态。还有就是如果有一半以上的主节点宕机,那么我们集群同样进入发力了状态。这就是我们的redis的投票机制,具体原理如下图所示:

(1)投票过程是集群中所有master参与,如果半数以上master节点与master节点通信超时(cluster-node-timeout),认为当前master节点挂掉.

    (2):什么时候整个集群不可用(cluster_state:fail)? 

        a:如果集群任意master挂掉,且当前master没有slave.集群进入fail状态,也可以理解成集群的slot映射[0-16383]不完整时进入fail状态. ps : redis-3.0.0.rc1加入cluster-require-full-coverage参数,默认关闭,打开集群兼容部分失败.

        b:如果集群超过半数以上master挂掉,无论是否有slave,集群进入fail状态.

 

原理:

 

 

优点:

1、有效的解决了redis在分布式方面的需求

2、遇到单机内存,并发和流量瓶颈等问题时,可采用Cluster方案达到负载均衡的目的

3、可实现动态扩容

4、P2P模式,无中心化

5、通过Gossip协议同步节点信息

6、自动故障转移、Slot迁移中数据可用

缺点:

1、架构比较新,最佳实践较少

2、为了性能提升,客户端需要缓存路由表信息

3、节点发现、reshard操作不够自动化

 

参考:主从复制原理https://www.cnblogs.com/kevingrace/p/5685332.html

redis单例、主从模式、sentinel以及集群的配置方式及优缺点对比

https://blog.csdn.net/keketrtr/article/details/78802571

Redis进阶实践之十一 Redis的Cluster集群搭建

https://www.cnblogs.com/PatrickLiu/p/8458788.html

Redis进阶实践之十二 Redis的Cluster集群动态扩容

https://www.cnblogs.com/PatrickLiu/p/8473135.html

 

有 0 个人打赏

Guess you like

Origin www.cnblogs.com/zhuyeshen/p/11732638.html