1、环境

服务器名称 IP地址 备注
sentinel-161-130 10.32.161.130 Sentinel
redis-161-131 10.32.161.131 redis主节点
redis-161-132 10.32.161.132 redis副本节点
redis-161-133 10.32.161.133 redis副本节点

2、安装Redis 6.2(四个节点,一主两副本、一哨兵)

# 所有节点都安装
dnf -y install redis

3、修改主节点配置

# 修改部分的配置文件
# vim /etc/redis/redis.conf
...
bind 0.0.0.0
timeout 600
daemonize yes
min-replicas-to-write 1
min-replicas-max-lag 10
requirepass password
maxmemory 4G
maxmemory-policy volatile-lru
appendonly yes
...

4、修改两个副本节点配置

# 修改部分的配置文件
# vim /etc/redis/redis.conf
...
bind 0.0.0.0
timeout 600
daemonize yes
replicaof 10.32.161.130 6379
masterauth password
requirepass password
maxmemory 4G
maxmemory-policy volatile-lru
appendonly yes
...

5、修改哨兵节点配置

# 修改部分的配置文件
# vim /etc/redis/sentinel.conf
...
bind 0.0.0.0
daemonize yes
sentinel monitor mymaster 10.32.161.130 6379 1
sentinel auth-pass mymaster password
sentinel down-after-milliseconds mymaster 30000
sentinel parallel-syncs mymaster 1
...

6、启动服务

# 启动主副本节点服务
systemctl enable --now redis

# 启动哨兵节点服务
systemctl enable --now redis-sentinel

7、在哨兵节点上验证

redis-cli -h 127.0.0.1 -p 26379 sentinel get-master-addr-by-name mymaster

redis-cli -h 127.0.0.1 -p 26379 sentinel master mymaster

redis-cli -h 127.0.0.1 -p 26379 sentinel slaves mymaster

 

posted on 2023-02-28 18:02  a120608yby  阅读(87)  评论(0编辑  收藏  举报