Linux_搭建Redis叢集哨兵模式

妙手空空發表於2017-08-07

時間:2017年08月02日星期三

說明:基於CentOS7-64bit。在單臺Linux主機上搭建Redis偽叢集哨兵模式。

步驟一:安裝Redis

1.下載Redis安裝包

Redis官網:https://redis.io/

下載地址:https://redis.io/download

2.上傳Redis安裝包

使用ftp工具,將下載好的Redis安裝包上傳到linux伺服器

步驟二:配置檔案修改

1.節點規劃

6301:主
6302:從
6303:從

26301:哨兵模式節點一
26302:哨兵模式節點二
26303:哨兵模式節點三

2.複製配置檔案

建立資料夾

mkdir redis-group

複製配置檔案

cp redis.conf ../redis-group/redis-6301.conf
cp redis.conf ../redis-group/redis-6302.conf
cp redis.conf ../redis-group/redis-6303.conf

3.修改配置檔案

修改redis-6301.conf配置檔案

vim redis-6301.conf

將引數的值改為以下

daemonize yes
pidfile /var/run/redis6301.pid
port 6301
logfile "6301.log"
dbfilename dump6301.rdb

修改redis-6302.conf和redis-6303.conf

vim redis-6302.conf
daemonize yes
pidfile /var/run/redis6302.pid
port 6302
logfile "6302.log"
dbfilename dump6302.rdb

vim redis-6303.conf
daemonize yes
pidfile /var/run/redis6303.pid
port 6303
logfile "6303.log"
dbfilename dump6303.rdb

步驟三:主從同步

1.啟動Redis

進入到redis安裝目錄的bin目錄下,分別啟動

./redis-server /home/midware/redis-group/redis-6301.conf
./redis-server /home/midware/redis-group/redis-6302.conf
./redis-server /home/midware/redis-group/redis-6303.conf

2.主從關係

進入redis客戶端

./redis-cli -p 6301
./redis-cli -p 6302
./redis-cli -p 6303

檢視當前redis主機節點資訊

info replication

在6302和6303客戶端分別執行,完成主從關係建立

SLAVEOF 127.0.0.1 6301

步驟四:哨兵模式

1.哨兵配置

建立哨兵配置檔案

touch sentinel-26301.conf
touch sentinel-26302.conf
touch sentinel-26303.conf

修改哨兵配置檔案

vim sentinel-26301.conf
vim sentinel-26302.conf
vim sentinel-26303.conf

修改為以下內容,26302和26303配置內容差不多,只需修改對應埠即可

# 使用宿主程式啟動
daemonize yes
# 啟動目錄
dir "/home/midware/redis-3.0.7/bin"
# 日期檔案路徑
logfile "/home/midware/redis-group/sentinel-26301.log"
# 監聽Redis主機地址及埠
sentinel monitor host6379 172.17.0.3 6301 1

2.哨兵啟動

分別啟動哨兵

./redis-sentinel /home/midware/redis-group/sentinel-26301.conf
./redis-sentinel /home/midware/redis-group/sentinel-26302.conf
./redis-sentinel /home/midware/redis-group/sentinel-26303.conf

檢視哨兵日誌

tail -f /home/midware/redis-group/sentinel-26301.log
tail -f /home/midware/redis-group/sentinel-26302.log
tail -f /home/midware/redis-group/sentinel-26303.log

相關文章