Java配置13-配置redis高可用(sentinel監控)

日期 操作 備註
2018-10-18 create  
2019-05-13 update 增加sentinel
     
     

 

目錄

 

1.服務器環境

2.Redis服務器概況

3.Redis高可用

1)複製配置文件

2)修改redis.conf

3)修改sentinel.conf文件

4)啓動redis和sentinel

5)配置redis信息



1.服務器環境

系統版本:Red Hat Enterprise Linux Server release 6.8

2.Redis服務器概況

服務器上已安裝了Redis,但是沒有配置高可用。

redis_6379-6382目錄是本機4個redis的安裝目錄,這4個現在都是master,software是redis的解壓目錄。

3.Redis高可用

本機準備做1主3從模式的高可用。但由於redis目前只支持主從複製備份(不支持主主複製),當主redis掛了,從redis只能提供讀服務,無法提供寫服務。所以,還需要自動故障轉移,redis sentinel帶有這個功能,當一個主redis不能提供服務時,redis sentinel可以將一個從redis升級爲主redis,並對其他從redis進行配置,讓它們使用新的主redis進行復製備份。

1)複製配置文件

切至Redis的解壓目錄

cd software/redis-3.2.8

複製redis.conf、sentinel.conf至各個安裝目錄的conf目錄下

在此只寫一個樣例

cp sentinel.conf /home/redis/redis_6379/conf

cp redis.conf /home/redis/redis_6379/conf

修改之前備份

cd /home/redis/redis_6379/conf

cp redis.conf redis.conf.20180804.bak

2)修改redis.conf

vim redis.conf
將bind 127.0.0.1改爲bind 0.0.0.0

將protected-mode yes改爲protected-mode no(保護模式)

將daemonize no改爲daemonize yes (後臺模式)

將logfile ""改爲logfile "/var/log/redis.log"(按需修改)

從機上多添加一行

slaveof      主機ip        6379

3)修改sentinel.conf文件

vim sentinel.conf

將sentinel monitor mymaster 127.0.0.1 6379 2

修改爲sentinel monitor mymaster 主機ip 6379 2 (主redis的IP和端口)

添加以下幾行:

daemonize yes

protected-mode no

logfile "/var/log/sentinel.log"(按需修改)

4)啓動redis和sentinel

進入Redis安裝目錄的bin目錄,執行命令:

./redis-server ../conf/redis.conf

./redis-sentinel ../conf/sentinel.conf

./redis-cli

分別啓動redis6379/6380/6381/6382

退出redis-cli,命令:

quit

切換端口

./redis-cli -p 6381(根據實際端口填寫)

 

在啓動redis-cli後,輸入命令:

info replication

查看Redis信息,包括角色、連接的從機等信息

 

5)配置redis信息

應用啓動時可指定yml文件,yml文件中關於redis的配置爲

spring:
#  cache:
#    type: redis
#  redis:
#    host: xx
#    port: 6379
  redis:
    sentinel:
      master: mymaster
      nodes: xx:26379,xx:26380,xx:26381

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章