Redis的哨兵集群

1、Sentinel 哨兵

    Sentinel(哨兵)是Redis 的高可用性解决方案:由一个或多个Sentinel 实例 组成的Sentinel 系统可以监视任意多个主服务器,以及这些主服务器属下的所有从服务器,并在被监视的主服务器进入下线状态时,自动将下线主服务器属下的某个从服务器升级为新的主服务器。

    例如:

66f05ab642ee721965ba88f92b087467.png

    

    在Server1 掉线后:

78afd682034a20b6b1fa748eaa7aecdb.png

    升级Server2 为新的主服务器:

  

f570f10de1b58efbe20865aa6db98899.png

2、Redis 主从分离

 在讲解Sentinel 哨兵集群之前,我们先来搭建一个简单的主从分离(读写分离)。

首先,我们默认大家都已经安装了redis,然后我们将 redis.conf 拷贝多份,并且创建多个目录,用于区分多个redis 服务:

   

2814fd65b32d6652ad7dcf84a74e63f7.png

 这里面,每个目录中都有自己的redis.conf 配置文件,接下来,我们先设置主服务器的配置文件。

一、配置Master

1、修改端口

  1. # Accept connections on the specified port, default is 6379 (IANA #815344).
  2. # If port 0 is specified Redis will not listen on a TCP socket.
  3. port 6380

  redis 的默认端口是6379,这里我们把主服务器的端口设置为6380

 2、修改pidfile

  1. # If a pid file is specified, Redis writes it where specified at startup
  2. # and removes it at exit.
  3. #
  4. # When the server runs non daemonized, no pid file is created if none is
  5. # specified in the configuration. When the server is daemonized, the pid file
  6. # is used even if not specified, defaulting to "/var/run/redis.pid".
  7. #
  8. # Creating a pid file is best effort: if Redis is not able to create it
  9. # nothing bad happens, the server will start and run normally.
  10. pidfile /var/run/redis_6380.pid

  pidfile 是我们启动redis 的时候,linux 为我们分配的一个pid 进程号,如果这里不作修改,会影响后面redis服务的启动

3、启动 redis

0f139f87af752ddc73ea4dc6d943d4df.png

  启动redis,我们可以看到,redis已经占领了6380 端口

  进入客户端

  1. redis

发表评论

表情:
评论列表 (有 0 条评论,23人围观)

还没有评论,来说两句吧...

相关阅读

    相关 Redis-哨兵

    哨兵: 哨兵(sentinel),是一个分布式系统,用于对主从结构中的每一台服务器进行监控,当出现故障时通过投票机制选择新的master并将所有slave连接到新的mas

    相关 Redis哨兵

    上一篇讲解了主从架构,同时也说到了该架构只适用于读多写少的情形,主要原因是因为从节点只允许读,一旦主节点崩溃了或者网络故障,那么主节点就不能对外提供写的操作。因此Redis在主