環境規劃部署
ip地址 |
規劃節點 |
192.168.31.177 |
Master redis-sentinel |
192.168.31.178 |
Slave1 redis-sentinel |
192.168.31.179 |
Slave2 redis-sentinel |
部署redis 配置主從
我這裏是安裝一鍵部署的
wget -c http://mirrors.linuxeye.com/oneinstack-full.tar.gz
配置主從(192.168.31.178和192.168.31.179配置)
192.168.31.178 配置
bind 127.0.0.1 192.168.31.178 #修改
slaveof 192.168.31.177 6379 #新增
masterauth # #這裏填寫客戶端設置的密碼 requirepass 我這裏沒有設置密碼
192.168.31.179 配置
bind 127.0.0.1 192.168.31.179 #修改
slaveof 192.168.31.177 6379 #新增
masterauth #這裏填寫客戶端設置的密碼 requirepass 我這裏沒有設置密碼
重啓各自的redis-server便可
部署redis-sentinel環境(192.168.31.177)
[root@server1 etc]# cat sentinel.conf
# 端口
port 26379
# 日誌文件
logfile "/usr/local/redis/var/sentinel.log"
#放後臺啓動
daemonize yes
# 哨兵監控主節點的IP和端口 2表示至少一個節點認爲主節點down了,纔開始選舉新節點
sentinel monitor hanye 192.168.31.177 6379 2
# 多少毫秒沒有接收到主節點的反饋,認爲主節點down
sentinel down-after-milliseconds hanye 15000
#數據存放位置
dir "/usr/local/redis/etc"
protected-mode no
# failover過時時間
sentinel failover-timeout hanye 120000
# 配置哨兵鏈接主節點的認證密碼。(主節點配置的requirepass)
#sentinel auth-pass hanye null
而後把此配置文件複製其餘server
[root@server1 etc]# scp /usr/local/redis/etc/sentinel.conf 192.168.31.178:/usr/local/redis/etc/
[root@server1 etc]# scp /usr/local/redis/etc/sentinel.conf 192.168.31.179:/usr/local/redis/etc/
啓動redis-sentinel(所有主機)
/usr/local/redis/bin/redis-sentinel /usr/local/redis/etc/sentinel.conf
啓動完畢 redis-sentine 會在各自的配置文件添加數據
[root@server2 ~]# cat /usr/local/redis/etc/sentinel.conf
# 端口
port 26379
# 日誌文件
logfile "/usr/local/redis/var/sentinel.log"
daemonize yes
sentinel myid 0e45194a89320d71313365f6163b691f1c9af021
sentinel deny-scripts-reconfig yes
sentinel monitor hanye 192.168.31.178 6379 2
sentinel down-after-milliseconds hanye 15000
# Generated by CONFIG REWRITE
dir "/usr/local/redis/etc"
protected-mode no
sentinel failover-timeout hanye 120000
sentinel config-epoch hanye 3
sentinel leader-epoch hanye 3
sentinel known-replica hanye 192.168.31.179 6379
sentinel known-replica hanye 192.168.31.177 6379
sentinel known-sentinel hanye 192.168.31.179 26379 1129fde41103b653b80efa8aeab519b36860f5b6
sentinel known-sentinel hanye 192.168.31.177 26379 ee5750ab52459c60b9f9ccb6d11f5ecf219f9ffe
sentinel current-epoch 3
檢測redis-sentinel結果
中止192.168.1.177的redis
[root@server1 etc]# kilall redis-server
![redis5.0.9哨兵模式redis-sentinel](http://static.javashuo.com/static/loading.gif)
中止178 redis-server
![redis5.0.9哨兵模式redis-sentinel](http://static.javashuo.com/static/loading.gif)