1禁止aof:

vim  redis.conf 将 appendonly yes 改为 appendonly no。
(其中daemonize yes这是设置redis,后台启动。)

2.创建多个redis主、从配置文件:

vim redis-6379.conf
内容:

include /root/myredis/redis.conf   #redis使用的文件夹。(因为配置环境变量后,只有复制redis.conf就可以在不同文件下创建redis)

pidfile /var/run/redis_6379.pid
port 6379  #端口号,不同端口号视为不同redis服务。
dbfilename dump6379.rdb # rdb文件名,即6379这个redis的数据文件。

vim redis-6380.conf
内容:

include /root/myredis/redis.conf  #redis使用的文件夹。(因为配置环境变量后,只有复制redis.conf就可以在不同文件下创建redis)

pidfile /var/run/redis_6380.pid
port 6380  #端口号,不同端口号视为不同redis服务。
dbfilename dump6380.rdb # rdb文件名,即6380这个redis的数据文件。

vim redis-6381.conf
内容:

include /root/myredis/redis.conf    #redis使用的文件夹。(因为配置环境变量后,只有复制redis.conf就可以在不同文件下创建redis)

pidfile /var/run/redis_6381.pid
port 6381  #端口号,不同端口号视为不同redis服务。
dbfilename dump6381.rdb # rdb文件名,即6381这个redis的数据文件。

············

3.开启服务:

redis-server redis-6379.conf
redis-server redis-6380.conf
redis-server redis-6381.conf

4.为哨兵模式准备配置文件:

        4-1在redis使用目录下新建sentinel.conf 配置文件中放入如下内容

sentinel monitor xxxx 127.0.0.1 6379 1   #xxx为哨兵名字   IP地址   redis服务端口号 哨兵个数(一个文件一个哨兵)

5.启动哨兵

        5-1在redis使用目录下使用哨兵

redis-sentinel sentinel.conf

6.这样就完成哨兵,在主从模式下主机down机会自动在子机中选出新主机。待旧主机复活后成为子机。其中 在主从配置中添加replica-priority 10意思为0-100 哨兵模式下,选举的时候,有用!谁的值小谁优先级高!谁当主机 !!(可以不设置)

更多推荐