1、准备redis目录以及文件
创建一个空目录redis,然后复制redis文件为三份,如下图:

每个目录中,都是独立的redis服务的文件,我这里用的redis 3.2的版本,具体如下:

2、为主服务器创建redis.conf配置文件
我这里是用6371、6372、6373这三个端口作为redis的服务端口,切记:配置文件的端口不能相同。
port 6371
3、为从服务器创建redis.conf配置文件
- 第一个从的redis.conf
port 6372
slaveof 127.0.0.1 6371
- 第二个从的redis.conf
port 6373
slaveof 127.0.0.1 6371
4、启动redis服务器
分别进入三个目录,依次运行(先运行主服务,再运行从服务器)
redis-server.exe redis.conf

5、连接三台服务器,查看主从信息
# 1、连接主服务器
redis-cli.exe -h 127.0.0.1 -p 6371
# 2、连接从服务器
redis-cli.exe -h 127.0.0.1 -p 6372
# 3、连接从服务器
redis-cli.exe -h 127.0.0.1 -p 6373

6、创建哨兵配置文件

配置文件内容如下:
- 主服务器 sentinel.conf
port 26371
sentinel monitor redis6371 127.0.0.1 6371 1
- 从服务器1 sentinel.conf
port 26372
sentinel monitor redis6372 127.0.0.1 6372 1
- 从服务器2 sentinel.conf
port 26373
sentinel monitor redis6373 127.0.0.1 6373 1
7、运行三个哨兵进程
进入三个目录,分别运行如下命令
# 启动哨兵
redis-server.exe sentinel.conf --sentinel

8、测试哨兵模式
关闭主服务器,然后观察两个从服务器的情况

配置主从时需要使用的命令:
# 1、启动redis服务器
redis-server.exe redis.conf
# 2、连接redis服务器
redis-cli.exe -h 127.0.0.1 -p 6371
# 3、查看节点信息
info replication
# 4、主服务器改编为从服务器
slaveof 127.0.0.1 6371
# 5、从服务器变为主服务器
slaveof no one
# 6、启动哨兵进程
redis-server.exe sentinel.conf --sentinel