Redis的哨兵集群

1、Sentinel 哨兵

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

    例如:

     

    在Server1 掉线后:

    升级Server2 为新的主服务器:

  

2、Redis 主从分离

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

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

   

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

一、配置Master

   1、修改端口

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

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

 2、修改pidfile

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

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

   3、启动 redis

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

  进入客户端

redis
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值