Linux_搭建Redis集羣哨兵模式

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

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

步驟一:安裝Redis

1.下載Redis安裝包

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

下載地址:https://redis.io/download服務器

2.上傳Redis安裝包

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

步驟二:配置文件修改

1.節點規劃

6301:主
6302:從
6303:從日誌

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

2.複製配置文件

建立文件夾server

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配置文件get

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
相關文章
相關標籤/搜索