sudo cp /etc/redis.conf /etc/redis-6381.confsudo cp /etc/redis.conf /etc/redis-6382.conflaravel
port 6381 pidfile "/var/run/redis-6381.pid" logfile "/var/log/redis/redis-6381.log" slaveof 11.11.11.11 6381 masterauth "123456" # 主從都保持同樣的密碼,且 master 的配置也須要這一行,在執行切換 master 的時候好像不會去添加這一行
sudo cp /etc/redis-sentinel.conf /etc/redis-sentinel-26381.confsudo cp /etc/redis-sentinel.conf /etc/redis-sentinel-26382.confredis
port 26381 pidfile "/var/run/redis-sentinel-26381.pid" logfile "/var/log/redis/redis-sentinel-26381.log" sentinel monitor mymaster 11.11.11.11 6379 2 #主節點別名爲mymaster,後面是ip和端口,2表明判斷主節點失敗至少須要2個sentinel節點贊成 sentinel auth-pass mymaster 123456 sentinel down-after-milliseconds mymaster 30000 #主節點故障30秒後啓用新的主節點 sentinel parallel-syncs mymaster 1 #故障轉移時最多能夠有1個從節點同時對主節點進行數據同步,數字越大,用時越短,存在網絡和 IO 開銷 sentinel failover-timeout mymaster 180000 #故障轉移超時時間180s:a 若是轉移超時失敗,下次轉移時時間爲以前的2倍;b 從節點變主節點時,從節點執行 slaveof no one 命令一直失敗的話,當時間超過180S時,則故障轉移失敗;c 從節點複製新主節點時間超過180S轉移失敗
'default' => [ 'tcp://11.11.11.11:26379', 'tcp://11.11.11.11:26381', 'tcp://11.11.11.11:26382', //這3個都是sentinel節點的地址 'options' => [ 'replication' => 'sentinel', 'service' => env('REDIS_SENTINEL_SERVICE', 'mymaster'), //sentinel 'parameters' => [ 'password' => env('REDIS_PASSWORD', null), //redis的密碼,沒有時寫null 'database' => 0, ], ], ]