1.從docker倉庫拉取redis鏡像
docker?pull?redis
2.在/home下分別創建redis-6379-data,redis-6380-data,redis-6381-data
3.拷貝/etc/redis/redis.conf 到 /home下
4.復制redis.conf為redis-6379.conf, redis-6380.conf,redis.6381.con并且分別修改其中的配置, logfile指定不同的文件
port?6380 ? logfile?"redis-6380.log" ?dir?/data ? appendonly?yes ? appendfilename?appendonly.aof ? slaveof?127.0.0.1?6379
5.docker啟動3個redis
docker?run?-tdi?-v?/home/data:/data?/home/redis-6379.conf:/usr/local/ect/redis/redis.conf?-p?6379:6379?redis
docker?run?-tdi?-v?/home/data:/data?/home/redis-6380.conf:/usr/local/ect/redis/redis.conf?-p?6380:6380?redis
docker?run?-tdi?-v?/home/data:/data?/home/redis-6381.conf:/usr/local/ect/redis/redis.conf?-p?6381:6381?redis
6.通過redis-cli分別連入創建好的redis服務器,測試主從是否配好
7.配置redis-sentinelm,創建三個sentinel文件,內容如下
port?26379 ? dir?"/data" ?logfile?"sentinel-26379.log" ?sentinel?monitor?mymaster?127.0.0.1?6379?2 ? sentinel?down-after-milliseconds?mymaster?10000 ? sentinel?failover-timeout?mymaster?60000
只修改日志的文件名即可
8.通過docker啟動三個sentinel
docker?run?-dit?-v?/home/sentinel-26379.conf:/usr/local/etc/redis/sentinel.conf?-p?26379:26379?redis??redis-sentinel?/usr/local/etc/redis/sentinel.conf
docker?run?-dit?-v?/home/sentinel-26380.conf:/usr/local/etc/redis/sentinel.conf?-p?26380:26380?redis??redis-sentinel?/usr/local/etc/redis/sentinel.conf
docker?run?-dit?-v?/home/sentinel-26381.conf:/usr/local/etc/redis/sentinel.conf?-p?26381:26381?redis??redis-sentinel?/usr/local/etc/redis/sentinel.conf
9.停止redis的master節點
docker stop master節點的containerid
10.連入從節點,查看主從狀態
redis-cli?-p?6380 info?replication
11.稍等幾十秒,從節點就會自動變成主節點
哨兵模式的原理采用了心跳機制和投票裁決機制。
更多文章、技術交流、商務合作、聯系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號聯系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元
