环境:
准备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