“Redis Sentinel”的版本间的差异
Jihongchang(讨论 | 贡献) (→配置文件) |
Jihongchang(讨论 | 贡献) (→配置文件) |
||
第14行: | 第14行: | ||
=== 配置文件 === | === 配置文件 === | ||
+ | ==== master.conf ==== | ||
+ | <syntaxhighlight lang="console"> | ||
+ | bind 127.0.0.1 | ||
+ | port 6379 | ||
+ | requirepass vn4sj5kbxdaG | ||
+ | </syntaxhighlight> | ||
+ | ==== slave.conf ==== | ||
+ | <syntaxhighlight lang="console"> | ||
+ | bind 127.0.0.1 | ||
+ | port 6380 | ||
+ | replicaof 127.0.0.1 6379 | ||
+ | requirepass vn4sj5kbxdaG | ||
+ | </syntaxhighlight> | ||
+ | ==== sentinel0.conf ==== | ||
+ | <syntaxhighlight lang="console"> | ||
+ | port 5000 | ||
+ | sentinel monitor mymaster 127.0.0.1 6379 2 | ||
+ | sentinel down-after-milliseconds mymaster 5000 | ||
+ | sentinel failover-timeout mymaster 60000 | ||
+ | sentinel parallel-syncs mymaster 1 | ||
+ | sentinel auth-pass mymaster vn4sj5kbxdaG | ||
+ | </syntaxhighlight> | ||
+ | ==== sentinel1.conf ==== | ||
+ | <syntaxhighlight lang="console"> | ||
+ | port 5001 | ||
+ | sentinel monitor mymaster 127.0.0.1 6379 2 | ||
+ | sentinel down-after-milliseconds mymaster 5000 | ||
+ | sentinel failover-timeout mymaster 60000 | ||
+ | sentinel parallel-syncs mymaster 1 | ||
+ | sentinel auth-pass mymaster vn4sj5kbxdaG | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | ==== sentinel2.conf ==== | ||
+ | <syntaxhighlight lang="console"> | ||
+ | port 5002 | ||
+ | sentinel monitor mymaster 127.0.0.1 6379 2 | ||
+ | sentinel down-after-milliseconds mymaster 5000 | ||
+ | sentinel failover-timeout mymaster 60000 | ||
+ | sentinel parallel-syncs mymaster 1 | ||
+ | sentinel auth-pass mymaster vn4sj5kbxdaG | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | ==== sentinel 配置项说明 ==== | ||
+ | |||
+ | ===== sentinel monitor mymaster 127.0.0.1 6379 2 ===== | ||
+ | 给 master 一个命名,2 是 quorum,是多个 Sentinel 中需要对 master 不可达(unreachable)状态达成一致意见的 Sentinel 个数 | ||
+ | |||
+ | ===== sentinel down-after-milliseconds mymaster 5000 ===== | ||
+ | The down-after-milliseconds value is 5000 milliseconds, that is 5 seconds,so masters will be detected as failing as soon as we don't receive any reply from our pings within this amount of time. | ||
+ | |||
+ | ===== sentinel failover-timeout mymaster 60000 ===== | ||
+ | <code>failover-timeout</code> 用于指定当 Sentinel 主观下线一个 Redis master 时,Sentinel 需要等待多长时间来执行故障转移(failover)操作。这个时间间隔称为“故障转移超时时间”。 | ||
+ | |||
+ | 默认情况下,<code>failover-timeout</code> 的值是 30 秒,也就是说,如果 Sentinel 检测到 master 宕机,会等待 30 秒后执行故障转移。 | ||
+ | |||
+ | 在这个时间内,Sentinel 会继续监控 master 的状态,如果它重新启动并且 Sentinel 认为它可以正常工作,那么 Sentinel 将不会执行故障转移。 | ||
+ | |||
+ | 可以通过修改 <code>failover-timeout</code> 配置项的值来改变故障转移的超时时间。 | ||
+ | |||
+ | 例如,将 <code>failover-timeout</code> 的值设置为 60 秒,可以使 Sentinel 在 master 宕机后等待更长的时间再执行故障转移,这可以降低错误的故障转移率。 | ||
+ | |||
+ | |||
+ | ===== sentinel parallel-syncs mymaster 1 ===== | ||
2023年2月19日 (日) 09:30的版本
Redis Sentinel 在不使用 Redis Cluster 时为 Redis 提供高可用性。
简单来说,Redis Sentinel 负责监控 master 和 slave,并在 master 出问题的时候从 slave 中选举一个出来作为 master 对外提供访问
注意
因为涉及到选举机制,所以 Redis Sentinel 的实例至少要有3个
配置文件
master.conf
bind 127.0.0.1
port 6379
requirepass vn4sj5kbxdaG
slave.conf
bind 127.0.0.1
port 6380
replicaof 127.0.0.1 6379
requirepass vn4sj5kbxdaG
sentinel0.conf
port 5000
sentinel monitor mymaster 127.0.0.1 6379 2
sentinel down-after-milliseconds mymaster 5000
sentinel failover-timeout mymaster 60000
sentinel parallel-syncs mymaster 1
sentinel auth-pass mymaster vn4sj5kbxdaG
sentinel1.conf
port 5001
sentinel monitor mymaster 127.0.0.1 6379 2
sentinel down-after-milliseconds mymaster 5000
sentinel failover-timeout mymaster 60000
sentinel parallel-syncs mymaster 1
sentinel auth-pass mymaster vn4sj5kbxdaG
sentinel2.conf
port 5002
sentinel monitor mymaster 127.0.0.1 6379 2
sentinel down-after-milliseconds mymaster 5000
sentinel failover-timeout mymaster 60000
sentinel parallel-syncs mymaster 1
sentinel auth-pass mymaster vn4sj5kbxdaG
sentinel 配置项说明
sentinel monitor mymaster 127.0.0.1 6379 2
给 master 一个命名,2 是 quorum,是多个 Sentinel 中需要对 master 不可达(unreachable)状态达成一致意见的 Sentinel 个数
sentinel down-after-milliseconds mymaster 5000
The down-after-milliseconds value is 5000 milliseconds, that is 5 seconds,so masters will be detected as failing as soon as we don't receive any reply from our pings within this amount of time.
sentinel failover-timeout mymaster 60000
failover-timeout
用于指定当 Sentinel 主观下线一个 Redis master 时,Sentinel 需要等待多长时间来执行故障转移(failover)操作。这个时间间隔称为“故障转移超时时间”。
默认情况下,failover-timeout
的值是 30 秒,也就是说,如果 Sentinel 检测到 master 宕机,会等待 30 秒后执行故障转移。
在这个时间内,Sentinel 会继续监控 master 的状态,如果它重新启动并且 Sentinel 认为它可以正常工作,那么 Sentinel 将不会执行故障转移。
可以通过修改 failover-timeout
配置项的值来改变故障转移的超时时间。
例如,将 failover-timeout
的值设置为 60 秒,可以使 Sentinel 在 master 宕机后等待更长的时间再执行故障转移,这可以降低错误的故障转移率。
sentinel parallel-syncs mymaster 1
启动
redis-server /path/to/sentinel.conf --sentinel
参考
https://redis.io/docs/management/sentinel/