Redis哨兵模式部署
Redis哨兵模式部署
集群架构
这里我们搭建一个三节点形成的Sentinel集群,来监管Redis主从集群,架构如下:
这里在3台服务器中开启3个redis实例,信息如下:
ip | port | 角色 |
---|---|---|
172.18.1.10 | 6379/27001 | master |
172.18.1.11 | 6379/27001 | slave |
172.18.1.13 | 6379/27001 | slave |
安装 redis(三台服务器全部执行)
#创建对应目录
mkdir -p /data/redis && cd /data/redis && mkdir conf log data
# 下载源码包
wget https://download.redis.io/releases/redis-6.2.5.tar.gz
# 解压源码包
tar zxf redis-6.2.5.tar.gz
#编译安装redis
make && make install PREFIX=/data/redis
#配置文件目录
cd /data/redis/conf/
#redis配置文件如下
redis.conf
#启动redis实例
/data/redis/bin/redis-server /data/redis/conf/redis.conf
redis主从创建
#两台slave执行指定master
./bin/redis-cli -p 6381 -a "adong@2022" slaveof 172.18.1.10 6379
#master执行查看主从状态
./bin/redis-cli -p 6381 -a "adong@2022" info replication
redis哨兵启动(三台服务器全部执行)
#哨兵配置文件
redis_sentinel.conf
#启动哨兵
/data/redis/bin/redis-sentinel /data/redis/conf/redis_sentinel.conf
#查看哨兵状态
/data/redis/bin/redis-cli -p 27001 info sentinel
配置文件解析
redis_sentinel.conf
port 27001
daemonize yes
pidfile "/var/run/redis-sentinel.pid"
logfile "/data/redis/log/redis_sentinel.log"
dir "/data/redis/data"
sentinel monitor mymaster 172.18.1.10 6379 2
sentinel auth-pass mymaster adong@2022
mymaster:主节点别名
172.18.1.10:master节点IP
6379:master节点redis端口
2:quorum 需要2个哨兵节点认为master不在线,才会重新选举新节点
adong@2022:redis认证密码
redis.conf
bind 0.0.0.0
port 6379
tcp-backlog 511
timeout 0
tcp-keepalive 300
daemonize yes
supervised no
pidfile /home/admin/redis/run/redis.pid
loglevel notice
logfile "/home/admin/redis/log/redis.log"
requirepass adong@2022
masterauth adong@2022
databases 16
always-show-logo yes
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
dir /data/redis/data/
slave-serve-stale-data yes
slave-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-disable-tcp-nodelay no
slave-priority 100
lazyfree-lazy-eviction no
lazyfree-lazy-expire no
lazyfree-lazy-server-del no
slave-lazy-flush no
appendonly no
appendfilename "appendonly.aof"
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes
aof-use-rdb-preamble no
lua-time-limit 5000
slowlog-log-slower-than 10000
slowlog-max-len 128
latency-monitor-threshold 0
notify-keyspace-events ""
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-size -2
list-compress-depth 0
set-max-intset-entries 512f
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit slave 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
aof-rewrite-incremental-fsync yes
redis_sentinel.conf
port 27001
daemonize yes
pidfile "/var/run/redis-sentinel.pid"
logfile "/data/redis/log/redis_sentinel.log"
dir "/data/redis/data"
sentinel monitor mymaster 172.18.1.10 6379 2
sentinel auth-pass mymaster adong@2022