Day23 Redis架构实战-Sentinel组态档设定

sentinel.conf

# 高可用配置搭配Sentinel机制
                           --->   Redis (Replica)
client ---> Redis (Master)
                           --->   Redis (Replica)
-------------------------------------------------
                sentinel
  • 依照以上的配置,Master与Replica间会自动同步资料,Sentinel则为持续的监控Master是否正常,当Master挂掉时,会把Replica切换为Master提供用户端服务.

sentinel组态

  • protected-mode

基本上sentinel不允许localhost以外的连线,如果需要外部连入则除了关闭保护模式外,也需要额外配置bind或是防火墙,避免安全性风险.

https://ithelp.ithome.com.tw/upload/images/20211008/20111658ivs8IZFKVP.png

# 预设
# protected-mode yes

# 关闭保护模式
protected-mode no
bind 192.138.10.1 ...
  • port

sentinel 的实体端口.

https://ithelp.ithome.com.tw/upload/images/20211008/20111658YLiIeH4rqT.png

# 预设
port 26379
  • daemonize

是否设定sentinel跑在背景还是前景模式.

https://ithelp.ithome.com.tw/upload/images/20211008/2011165899rMrtfOIg.png

# 预设
daemonize no

# 背景模式
daemonize yes
  • pidfile

搭配上面daemon启动方式使用,会在启动时写入指定路径档案,关闭服务时则删除.

https://ithelp.ithome.com.tw/upload/images/20211008/20111658q3LuWcnJyo.png

# 预设
pidfile /var/run/redis-sentinel.pid
  • logfile

设定sentinel的日志资料.

https://ithelp.ithome.com.tw/upload/images/20211008/20111658ckvCKscSRH.png

# 预设
logfile ""

# 加入档案路径
logfile "/tmp/redis-sentinel_26379.log"
  • sentinel announce-ip
  • sentinel announce-port

设定NAT网路环境中的IP与Port.

https://ithelp.ithome.com.tw/upload/images/20211008/20111658cFWRTlxvV7.png

# 预设
# sentinel announce-ip 1.2.3.4
# sentinel announce-port 26379
  • dir

设定暂放资料夹.

https://ithelp.ithome.com.tw/upload/images/20211008/20111658WfNogVak3u.png

# 预设
dir /tmp
  • sentinel monitor

设定监控目前的Master与当Master发生异常时需要几个sentinel确认才可以切换.

https://ithelp.ithome.com.tw/upload/images/20211008/20111658fVNGXVrxDf.png

# 预设
# Redis mymaster ip=127.0.0.1 port 6379,当异常发生时需要有2台sentinel认可才可以切换
sentinel monitor mymaster 127.0.0.1 6379 2

# sentinel切换成一台
sentinel monitor mymaster 127.0.0.1 6379 1
  • sentinel auth-pass

设定for sentinel连线到Redis Master时所需要的密码.

https://ithelp.ithome.com.tw/upload/images/20211008/20111658euR0fVwhOg.png

# 预设
# sentinel auth-pass mymaster MySUPER--secret-0123passw0rd
  • sentinel auth-user

设定for sentinel连线到Redis Master时所需要的使用者.

https://ithelp.ithome.com.tw/upload/images/20211008/201116589ohllusIO0.png

sentinel auth-user <master-name> <username>
  • sentinel down-after-milliseconds

设定当Replica与Master资料同步停止超过多少秒则不能成为Master.

https://ithelp.ithome.com.tw/upload/images/20211008/20111658q5BNUcTLxa.png

# 预设
# 资料同步停止不可以超过30秒
sentinel down-after-milliseconds mymaster 30000
  • user

从Redis 6.2 版本支援使用者相关权限设定.

https://ithelp.ithome.com.tw/upload/images/20211008/201116583TkR1t2l5p.png

# 预设
# user worker +@admin +@connection ~* on >ffa9203c493aa99
  • acllog-max-len

设定acl记录中的项目上限.

https://ithelp.ithome.com.tw/upload/images/20211008/20111658x5kCys4P0S.png

# 预设
acllog-max-len 128
  • aclfile

透过档案设定acl.需注意如果sentinel.config已经设定acl,则会拒绝档案acl设定.

https://ithelp.ithome.com.tw/upload/images/20211008/20111658MqIG4vgcfy.png

# 预设
# aclfile /etc/redis/sentinel-users.acl
  • requirepass

设定sentinel密码

https://ithelp.ithome.com.tw/upload/images/20211008/20111658ojNpgJN3ZQ.png

# 预设
# requirepass <password>
  • sentinel sentinel-user

设定sentinel与其他sentinel间连线的使用者.

https://ithelp.ithome.com.tw/upload/images/20211008/20111658auiUTTJhNQ.png

# 预设
sentinel sentinel-user <username>
  • sentinel sentinel-pass

设定sentinel与其他sentinel间的连线密码.

https://ithelp.ithome.com.tw/upload/images/20211008/20111658ZWFDJKLFTS.png

# 预设
sentinel sentinel-pass <password>
  • sentinel parallel-syncs

设定与Master平行同步资料。

https://ithelp.ithome.com.tw/upload/images/20211008/20111658Cv7LvpENxb.png

# 预设
sentinel parallel-syncs mymaster 1
  • sentinel failover-timeout

在failover切换时需要多少时间内完成,否则失败.

https://ithelp.ithome.com.tw/upload/images/20211008/20111658B7aCFm9vzI.png

# 预设 3分钟
sentinel failover-timeout mymaster 180000

SCRIPTS EXECUTION

sentinel notification-script 和 sentinel reconfig-script 脚本依序被执行时,执行结果回应1时则会重试10次,回应2时则不会重试,中断脚本进行则会收到回应1,脚本执行时间最长不可以超过60秒.

https://ithelp.ithome.com.tw/upload/images/20211008/20111658oLP8xWLbRq.png

NOTIFICATION SCRIPT

通过脚本设定当sentinel有事件发生时,发送讯息或是电子邮件通知相关人员.

https://ithelp.ithome.com.tw/upload/images/20211008/20111658uLWihXh5K8.png

# 预设
# sentinel notification-script mymaster /var/redis/notify.sh

CLIENTS RECONFIGURATION SCRIPT

通过脚本设定Master的组态档.

https://ithelp.ithome.com.tw/upload/images/20211008/201116587JbCjtPXfD.png

# 预设
# sentinel client-reconfig-script mymaster /var/redis/reconfig.sh

SECURITY

设定是否不可以在sentinel运行中修改CLIENTS RECONFIGURATION SCRIPT脚本.

https://ithelp.ithome.com.tw/upload/images/20211008/20111658HjXtrJS47G.png

# 预设
sentinel deny-scripts-reconfig yes

REDIS COMMANDS RENAMING

透过指定将Master的组态档更名.

https://ithelp.ithome.com.tw/upload/images/20211008/20111658E3MvoWn06m.png

HOSTNAMES SUPPORT

  • SENTINEL resolve-hostnames

设定是否以Server主机名代替连线IP.

https://ithelp.ithome.com.tw/upload/images/20211008/20111658F5mbOSBYlB.png

# 预设
SENTINEL resolve-hostnames no
  • SENTINEL announce-hostnames

当设定以Server主机名代替连线IP时,主机名称是否要唯一.

https://ithelp.ithome.com.tw/upload/images/20211008/20111658PgP35yT9Gw.png

# 预设
SENTINEL announce-hostnames no

<<:  DAY23 - 我的网站要分析!网站分析工具的选择和态度(1)

>>:  Day25:【技术篇】JavaScript 套件 - classnames

Day1 前言

各位朋友好,欢迎大家观看此篇文章,这次暑假因为疫情的关系而开始远距教学,刚好也趁此机会让我好好学习,...

[Day 21] 策略(Strategy)

一、策略 在1880年代,科学家提倡使用占星术预测未来是很流行的,但到了现代科学,尤其是做交易,我们...

寻找mail server

各位大大好, 第一次发文, 想请教有无推荐的mail server,公司用,约100使用者, 有看过...

【在 iOS 开发路上的大小事-Day04】透过 Segue 来传值

前情提要 一般我们在做传值动作的时候,会有好几种方式可以做,像是用 Segue、Closure、De...

D4 - 加盐不加价 严格模式开启

前言 JavaScript 相较是个自由的语言,在学习语法时会发现,咦 明明规则是这样,怎麽那样也可...