Redis Sentinel集群部署

单机 Redis Sentinel 架构

Redis Sentinel集群部署_第1张图片
Redis Sentinel集群部署_第2张图片
Redis Sentinel集群部署_第3张图片

部署规划

主机地址 作用
127.0.0.:7000 主节点
127.0.0.:7001 从节点
127.0.0.:7002 从节点

安装redis

wget http://download.redis.io/releases/redis-5.0.7.tar.gz
tar xzf redis-5.0.7.tar.gz
cd redis-5.0.7
make

主节点配置

port 7000
daemonize yes
pidfile /var/run/redis-7000.pid
logfile "7000.log"
dir "/opt/soft/redis/redis/data/"

从节点配置

port 7001
daemonize yes
pidfile /var/run/redis-7001.pid
logfile "7001.log"
dir "/opt/soft/redis/redis/data/"
replicaof 127.0.0.1 7000

测试主从是否正常

#没有sudo的话权限不足无法连接成功
sudo src/redis-server redis-7000.conf
sudo src/redis-server redis-7001.conf
sudo src/redis-server redis-7002.conf
src/redis-cli -p 7000 info replication

# Replication
role:master
connected_slaves:2
slave0:ip=127.0.0.1,port=7001,state=online,offset=1626,lag=0
slave1:ip=127.0.0.1,port=7002,state=online,offset=1626,lag=0
master_replid:012214d5b946ae6a83a809a328497b52ca19ae6e
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:1626
second_repl_offset:-1
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:1
repl_backlog_histlen:1626
[vagrant@Master redis-5.0.7]$

Sentinel 配置

#去除注释
cat sentinel.conf  | grep -v "#" | grep -v "^$" > redis-sentinel-26379.conf
vim redis-sentinel-26379.conf
#-------------文件内容---------------------
port 26379
daemonize yes
pidfile "/var/run/redis-sentinel.pid"
logfile "26379.log"
dir "/tmp"
#------------------------------------------
#快速配置
sed "s/26379/26380/g" redis-sentinel-26379.conf > redis-sentinel-26380.conf
sed "s/26379/26381/g" redis-sentinel-26379.conf > redis-sentinel-26381.conf
#启动Sentinel
src/redis-sentinel  redis-sentinel-26379.conf
src/redis-sentinel  redis-sentinel-26380.conf
src/redis-sentinel  redis-sentinel-26381.conf

Redis Sentinel集群部署_第4张图片

与SpingBoot整合

spring:
  #redis配置
  redis:
    database: 11
    password: xxxx
    jedis:
      pool:
        max-active: 50
        max-wait: -1
        max-idle: 100
        min-idle: 0
    timeout: 10000
    sentinel:
      nodes: 198.18.2.2:5000,198.18.2.3:5000,198.18.2.4:5000
      master: mymaster

你可能感兴趣的:(Redis Sentinel集群部署)