Redis 自動容錯移轉sentinel

來源:互聯網
上載者:User

最近看了Redis自動容錯移轉Sentinel(哨兵),故將筆記記在次處
注意,實際環境中是,多台機器,本文只是測試,所以在一台機器上配置多個Redis執行個體,以達到實驗的目的

Redis Sentinel(哨兵)

7000設定檔


port 7000 
daemonize yes 
pidfile /var/run/redis-7000.pid 
logfile "7000.log" 
dbfilename "dump-7000.rdb" 
appendonly yes 
appendfilename "appendonly-7000.aof" 
dir "/data/redis"
 
設定檔編寫


sed 's/7000/7001/g' redis-7000.conf >>redis-7001.conf
sed 's/7000/7002/g' redis-7000.conf >>redis-7002.conf
cat redis-7001.conf
cat redis-7002.conf
cat redis-7000.conf
 
設定主從關係


echo "slaveof 192.168.1.108 7000" >>redis-7001.conf
echo "slaveof 192.168.1.108 7000" >>redis-7002.conf
 
啟動三台redis server


redis-server /etc/redis/redis-7000.conf
redis-server /etc/redis/redis-7002.conf
redis-server /etc/redis/redis-7001.conf
ps -ef | grep redis
 
查看redis 7000連接埠的複製資訊

PHP


127.0.0.1:7000> info replication
# Replication
role:master
connected_slaves:2
slave0:ip=192.168.1.108,port=7001,state=online,offset=43,lag=1
slave1:ip=192.168.1.108,port=7002,state=online,offset=43,lag=1
master_repl_offset:43
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:2
repl_backlog_histlen:42
 
配置sentinel

vim redis-sentinel-26379.conf

port 26379 
daemonize yes 
pidfile /var/run/redis-26379.pid
logfile "26379.log"
dir /data/redis
sentinel monitor mymaster 192.168.1.108 7000 2
sentinel down-after-milliseconds mymaster 30000
sentinel parallel-syncs mymaster 1
sentinel failover-timeout mymaster 180000
 
組建組態檔案

sed 's/26379/26380/g' redis-sentinel-26379.conf >> redis-sentinel-26380.conf
sed 's/26379/26381/g' redis-sentinel-26379.conf >> redis-sentinel-26381.conf
 
啟動哨兵

PHP


[root@CentOS redis]# redis-sentinel redis-sentinel-26379.conf
[root@CentOS redis]# redis-sentinel redis-sentinel-26380.conf
[root@CentOS redis]# redis-sentinel redis-sentinel-26381.conf
 
[root@CentOS redis]# ps -ef | grep redis-sentinel| grep -v 'grep'
root      2677     1  0 02:36 ?        00:00:00 redis-sentinel *:26379 [sentinel]
root      2681     1  0 02:36 ?        00:00:00 redis-sentinel *:26380 [sentinel]
root      2685     1  0 02:36 ?        00:00:00 redis-sentinel *:26381 [sentinel]
 
接下來可以測試哨兵的功能了,代碼太多就不粘貼上來了,至此Redis自動容錯移轉簡單模型已經完成

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.