【Redis】Redis 5.0 哨兵模式安装部署以及主备切换验证

无意中发现了一个巨牛的人工智能教程,忍不住分享一下给大家。教程不仅是零基础,通俗易懂,而且非常风趣幽默,像看小说一样!觉得太牛了,所以分享给大家。点这里可以跳转到教程。

 

安装

redis 5.0 安装

https://redis.io/download

官网下载安装包

 

解压

 

安装

sudo yum install gcc gcc-c++ -y

make

make install PREFIX=/apprun/redis

 

哨兵集群搭建

节点分布

集群机器如下:

172.28.72.104

master 8379

slave 8380

sentinel 28379

172.28.72.124

slave 8381

sentinel 28380

sentinel 28381

 

master配置

port 8379

protected-mode no

tcp-backlog 511

timeout 0

tcp-keepalive 300

pidfile /apprun/redis/redis_8379.pid

loglevel notice

logfile "/apprun/redis/redis_8379.log"

databases 16

always-show-logo yes

#save 900 1

#save 300 10

#save 60 10000

stop-writes-on-bgsave-error yes

rdbcompression yes

rdbchecksum yes

dbfilename dump.rdb

appendonly no

appendfilename "appendonly.aof"

no-appendfsync-on-rewrite no

auto-aof-rewrite-percentage 100

auto-aof-rewrite-min-size 64mb

aof-load-truncated yes

aof-use-rdb-preamble yes

hz 10

dynamic-hz yes

#slave config

masterauth cmcc2019

requirepass cmcc2019

slave配置

同上

启动完slave之后,执行命令slaveof masterip masterport

 

sentinel配置

sentinel monitor mymaster 172.28.72.104 8379 2

#注意配置的位置

sentinel auth-pass mymaster cmcc2019

sentinel down-after-milliseconds mymaster 10000

sentinel failover-timeout mymaster 30000

sentinel parallel-syncs mymaster 2

切记sentinel配置不要手贱复制粘贴上面master的配置过来改改,requirepass这个配置一定不能要,否则jedis sentinel客户端连不上。

启动sentinel,两种方式

./src/redis-sentinel redis_sentinel.conf &

./src/redis-server redis_sentinel_28380.conf --sentinel &

 

启动完之后配置被复写了

#sentinel

sentinel myid 6a2d34d9d0955483b2f973da329c9360cd5c5080

sentinel deny-scripts-reconfig yes

sentinel monitor mymaster 172.28.72.104 8379 2

sentinel down-after-milliseconds mymaster 10000

sentinel failover-timeout mymaster 30000

# Generated by CONFIG REWRITE

dir "/apprun/redis/redis-5.0.7"

sentinel parallel-syncs mymaster 2

sentinel auth-pass mymaster cmcc2019

sentinel config-epoch mymaster 0

sentinel leader-epoch mymaster 0

sentinel known-replica mymaster 172.28.72.124 8381

sentinel known-replica mymaster 172.28.72.104 8380

sentinel known-sentinel mymaster 172.28.72.104 28379 f9e93ad4558f8e36fba261c76f402e32a7d89f57

sentinel known-sentinel mymaster 172.28.72.124 28381 13450651a45b99ecb23e93309dfa1395b80f236d

sentinel current-epoch 0

 

哨兵模式验证

杀掉master进程

 

 

从日志及集群信息可以看出来,master已经切换了

原来的master重新启动后观察,主备信息已经变更了

 

 

 

©️2020 CSDN 皮肤主题: 酷酷鲨 设计师:CSDN官方博客 返回首页