一:單機模式
參考: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