# 基本环境

# 启动 3 台 redis
  • redis-1:172.17.0.2:6379
  • redis-2:172.17.0.3:6379
  • redis-3:172.17.0.4:6379

# 配置主从复制

  • 分别进入 3 台 redis, 使用 info replication 查看信息

  • 可以看到当前 3 台 redis 都是 master 角色,使用 redis-cli 命令修改 redis-6380、redis-6381 的主机为 172.17.0.2:6379

1
SLAVEOF host port // SLAVEOF 172.17.0.2 6379
  • 进入 172.17.0.2 使用 info replication 查看信息,看到两个从机说明配置成功。

# 配置哨兵模式

  • 分别进入台 redis , 进行以下操作

  • 进入根目录创建 sentinel.conf 文件

1
2
cd / && touch sentinel.conf

  • 修改文件内容为:
1
sentinel monitor mymaster 172.17.0.2 6379 1
1
使用 redis-sentinel /sentinel.conf 启动Redis哨兵监控