linux-Redis主从哨兵模式配置


一:单机模式

  参考:https://www.cnblogs.com/lbky/articles/11024128.html

二:配置主从模式

  修改redis.conf配置文件为 :

   主配置:redis-6379.conf

daemonize yes
protected-mode no
port 6379
pidfile /usr/local/redis/redis-5.0.5/redis_6379.pid
dir /usr/local/redis/redis-5.0.5/db/master/

masterauth 123456
requirepass 123456

  从配置:redis-6380.conf

daemonize yes
protected-mode no
port 6380
pidfile /usr/local/redis/redis-5.0.5/redis_6380.pid
dir /usr/local/redis/redis-5.0.5/db/slave_one

slaveof 127.0.0.1 6379
masterauth 123456
requirepass 123456

  从配置:redis-6381.conf

daemonize yes
protected-mode no
port 6381
pidfile /usr/local/redis/redis-5.0.5/redis_6381.pid
dir /usr/local/redis/redis-5.0.5/db/slave_two

slaveof 127.0.0.1 6379
masterauth 123456
requirepass 123456

  启动redis服务

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

  查看进程

ps -ef|grep redis

  查看redis信息

info replication

三:哨兵配置

  修改sentinel.conf为 sentinel-6379.conf

port 26379

#守护进程模式
daemonize yes

#关闭保护模式
protected-mode no

#指明日志文件名
logfile "./sentinel-6379.log"

#哨兵监控的master
sentinel monitor mymaster 127.0.0.1 6379 1

#master或slave多长时间(默认30秒)不能使用后标记为s_down状态。
sentinel down-after-milliseconds mymaster 3000

#若哨兵在配置值内未能完成故障转移操作,则任务本次故障转移失败
sentinel failover-timeout mymaster 18000

#如果redis配置了密码,那这里必须配置认证,否则不能自动切换
sentinel auth-pass mymaster 123456 

  启动哨兵

./src/redis-sentinel ./sentinel-6379.conf 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM