Redis Sentinel 哨兵集群搭建

环境:

准备3台虚拟机,关闭防火墙,保证网络端口通畅
机器1:192.168.204.101
机器2:192.168.204.102
机器3:192.168.204.103

Sentinel 集群搭建:

一.目标

搭建一个1 主 2 从 3 哨兵的集群

二.步骤

1.下载地址

https://download.redis.io/releases/redis-6.2.14.tar.gz

2.上传到每台虚拟机 /opt
3.解压编译
cd /opt
tar -zxf redis-6.2.14.tar.gz
cd redis-6.2.14/
make
4.修改每台机器上的 redis.conf
cd /opt/redis-6.2.14/
vim redis.conf

机器1:master

bind 0.0.0.0
protected-mode no

机器2:slave

bind 0.0.0.0
protected-mode no
replicaof 192.168.204.101 6379

机器3:slave

bind 0.0.0.0
protected-mode no
replicaof 192.168.204.101 6379
5.修改每台机器的 sentinel.conf
cd /opt/redis-6.2.14/
vim sentinel.conf

机器1:这里的 2 表示选举新的 master 需要票数

sentinel monitor mymaster 192.168.204.103 6379 2
sentinel announce-ip "192.168.204.101"
sentinel announce-port 26379

机器2:

sentinel monitor mymaster 192.168.204.101 6379 2
sentinel announce-ip "192.168.204.102"
sentinel announce-port 26379

机器3:

sentinel monitor mymaster 192.168.204.101 6379 2
sentinel announce-ip "192.168.204.103"
sentinel announce-port 26379
6.启动集群

可以开启6个终端用来启动3台机器的 redis 和 sentinel,便于观察,先启动 1 个主 redis,再启动 2 个从 redis:

cd /opt/redis-6.2.14
./src/redis-server redis.conf

启动 3 个 sentinel

cd /opt/redis-6.2.14
./src/redis-sentinel sentinel.conf 

  • 7
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值