標籤:redis
本文使用的是redis2.8.24的版本;
1.測試環境
master: 192.168.136.130 6379slave1: 192.168.136.130 6479slave2: 192.168.136.130 6579master-sentinel: 192.168.136.130 26379slave1-sentinel: 192.168.136.130 26479slave2-sentinel: 192.168.136.130 26579
2.下載安裝
地址:http://www.redis.io
#安裝tar zxf redis-2.8.24.tar.gzcd redis-2.8.24make && make install#安裝之前可能需要安裝別的底層軟體; yum install -y gcc makc
3.配置測試環境
cd /usr/localmkdir redis_clustermkdir redis_cluster/master_6379mkdir redis_cluster/slave_6479mkdir redis_cluster/slave_6579
配置redis
1) master
cp -f /usr/local/src/redis-2.8.24/redis.conf /usr/local/redis_cluster/master_6379/redis.confcp -f /usr/local/src/redis-2.8.24/sentinel.conf /usr/local/redis_cluster/master_6379/6379_sentinel.conf
master_6379/redis.conf 修改為如下:
daemonize yes port 6379 requirepass 123456 masterauth 123456 appendonly no save "" slave-read-only yes
6379_sentinel.conf 修改如下:
port 26379 sentinel monitor mymaster 192.168.136.130 6379 2 sentinel auth-pass mymaster 123456 sentinel down-after-milliseconds mymaster 30000 sentinel parallel-syncs mymaster 1 sentinel failover-timeout mymaster 900000
2)slave1
cp -f /usr/local/src/redis-2.8.24/redis.conf /usr/local/redis_cluster/slave_6479/redis.confcp -f /usr/local/src/redis-2.8.24/sentinel.conf /usr/local/redis_cluster/slave_6479/6479_sentinel.conf
slave_6479/redis.conf 修改如下:
daemonize yes port 6479 requirepass 123456 masterauth 123456 appendonly no save "" slave-read-only yes slaveof 192.168.136.130 6379
6479_sentinel.conf 修改如下:
port 26479 sentinel monitor mymaster 192.168.136.130 6379 2 sentinel auth-pass mymaster 123456 sentinel down-after-milliseconds mymaster 30000 sentinel parallel-syncs mymaster 1 sentinel failover-timeout mymaster 900000
3)slave2
cp -f /usr/local/src/redis-2.8.24/redis.conf /usr/local/redis_cluster/slave_6579/redis.confcp -f /usr/local/src/redis-2.8.24/sentinel.conf /usr/local/redis_cluster/slave_6579/6579_sentinel.conf
slave_6579/redis.conf 修改如下:
daemonize yes port 6579 requirepass 123456 masterauth 123456 appendonly no save "" slave-read-only yes slaveof 192.168.136.130 6379
6479_sentinel.conf 修改如下:
port 26579 sentinel monitor mymaster 192.168.136.130 6379 2 sentinel auth-pass mymaster 123456 sentinel down-after-milliseconds mymaster 30000 sentinel parallel-syncs mymaster 1 sentinel failover-timeout mymaster 900000
4.啟動叢集
注意:首次構建sentinel環境時,必須首先啟動master。
#啟動master和master-sentinel: redis-server /usr/local/redis_cluster/master_6379/redis.conf redis-sentinel /usr/local/redis_cluster/master_6379/6379_sentinel.conf
複製會話,啟動slave1和slave1-sentinel:
redis-server /usr/local/redis_cluster/slave_6479/redis.conf redis-sentinel /usr/local/redis_cluster/slave_6479/6479_sentinel.conf
複製會話,啟動slave2和slave2_sentinel:
redis-server /usr/local/redis_cluster/slave_6579/redis.conf redis-sentinel /usr/local/redis_cluster/slave_6579/6579_sentinel.conf
查看master的狀態:
redis-cli -h 192.168.136.130 -p 6379 #查看叢集狀態info replication
5.測試
1)master 宕機
結果:master宕機後,sentinel叢集會在slave叢集中選取一台當做master繼續提供服務;
2)master 恢複
結果:當之前的master恢複正常後,加入redis叢集,被階級為slave;
3) slave 宕機
結果:slave當機對master無影響;
本文參考 http://blog.csdn.net/wtyvhreal/article/details/46517483
本文出自 “淺淺的淡淡” 部落格,請務必保留此出處http://cuixiang.blog.51cto.com/8204722/1770521
redis sentinel叢集配置