redis-sentinel的配置文件

redis-sentinel的配置文件

   张吉吉     2020年1月2日 01:24     2077    

# Example sentinel.conf

# *** IMPORTANT ***
# protected-mode no
bind 192.168.60.150
是否启动保护模式,是否禁止外部链接,除了绑定的IP地址。

# port <sentinel-port>
# The port that this sentinel instance will run on
port 26379
sentinel启动时监听的端口

daemonize yes
守护进程模式启动(后台启动),默认的是前台启动方式。
当启动后其PID文件将创建到/var/run/redis-sentinel.pid,和下边的pidfile参数相关。

pidfile "/var/run/redis-sentinel.pid"
当以后台启动的时候,其PID文件写入的位置。

logfile "/var/log/redis-sentinel.log"
sentinel的日志文件的位置。

# sentinel announce-ip <ip>
# sentinel announce-port <port>
# sentinel announce-ip 1.2.3.4


# dir <working-directory>
dir "/tmp/redis"
每一个长时间运行的进程都应该有一个已经定义好的工作目录。
最简单的方式就是在/tmp目录中进行创建,保持默认即可。


# sentinel monitor <master-name> <ip> <redis-port> <quorum>
sentinel monitor mymaster 192.168.60.150 6379 2
这里是固定格式,这个master-name是自定义。
ip就是配置redis master的ip地址
redis-port就配置redis的监听端口。
quorum这个需要根据实际情况进行配置,一般只要配置一半以上就行了。
比如3个就配置2,5个就配置3,就可以。
这里当redis roles发生切换的时候,配置文件将会被自动重写。


# sentinel auth-pass <master-name> <password>
# sentinel auth-pass mymaster MySUPER--secret-0123passw0rd
如果这里配置上了密码,只需要将密码加上即可。

# sentinel down-after-milliseconds <master-name> <milliseconds>
大概多长时间如果不可达,sentinel就会主观认为redis已经停止(S_DOWN),就会去进行角色切换。
默认的时间是30s。
sentinel myid b5a90bc0cbe706a4eb44b22fe83997bc7e983792

# sentinel parallel-syncs <master-name> <numreplicas>
在故障转移期间,我们可以重新配置多少个副本来同时指向新的副本。
如果使用副本来进行服务查询,就只配置一个比较小的值,避免在进行数据同步的时候,导致redis都不能进行访问,从而造成服务的断连。


# sentinel failover-timeout <master-name> <milliseconds>
故障转移的超时时间 failover-timeout 可以用在以下这些方面:
1. 同一个sentinel对同一个master两次failover之间的间隔时间。
2. 当一个slave从一个错误的master那里同步数据开始计算时间。直到slave被纠正为向正确的master那里同步数据时。
3.当想要取消一个正在进行的failover所需要的时间。  
4.当进行failover时,配置所有slaves指向新的master所需的最大时间。不过,即使过了这个超时,slaves依然会被正确配置为指向master,但是就不按parallel-syncs所配置的规则来了
 默认三分钟


# SCRIPTS EXECUTION
配置当某一事件发生时所需要执行的脚本,可以通过脚本来通知管理员,例如当系统运行不正常时发邮件通知相关人员。  
对于脚本的运行结果有以下规则:  
若脚本执行后返回1,那么该脚本稍后将会被再次执行,重复次数目前默认为10  
若脚本执行后返回2,或者比2更高的一个返回值,脚本将不会重复执行。
如果脚本在执行过程中由于收到系统中断信号被终止了,则同返回值为1时的行为相同。
一个脚本的最大执行时间为60s,如果超过这个时间,脚本将会被一个SIGKILL信号终止,之后重新执行。

# NOTIFICATION SCRIPT
# sentinel notification-script <master-name> <script-path>
# sentinel notification-script mymaster /var/redis/notify.sh
通知型脚本:当sentinel有任何警告级别的事件发生时(比如说redis实例的主观失效和客观失效等等),将会去调用这个脚本,
这时这个脚本应该通过邮件,SMS等方式去通知系统管理员关于系统不正常运行的信息。调用该脚本时,将传给脚本两个参数,
一个是事件的类型,
一个是事件的描述。
如果sentinel.conf配置文件中配置了这个脚本路径,那么必须保证这个脚本存在于这个路径,并且是可执行的,否则sentinel无法正常启动成功。
#通知脚本


# CLIENTS RECONFIGURATION SCRIPT
# sentinel client-reconfig-script <master-name> <script-path>
sentinel client-reconfig-script mymaster /usr/local/redis/scripts/changeVip.sh
# 客户端重新配置主节点参数脚本
# 当一个master由于failover而发生改变时,这个脚本将会被调用,通知相关的客户端关于master地址已经发生改变的信息。
# 以下参数将会在调用脚本时传给脚本:
# <master-name> <role> <state> <from-ip> <from-port> <to-ip> <to-port>
# 目前<state>总是“failover”,
# <role>是“leader”或者“observer”中的一个。
# 参数 from-ip, from-port, to-ip, to-port是用来和旧的master和新的master(即旧的slave)通信的
# 这个脚本应该是通用的,能被多次调用,不是针对性的。


# SECURITY
sentinel deny-scripts-reconfig yes

sentinel config-epoch mymaster 4

# REDIS COMMANDS RENAMING
#
# Sometimes the Redis server has certain commands, that are needed for Sentinel
# to work correctly, renamed to unguessable strings. This is often the case
# of CONFIG and SLAVEOF in the context of providers that provide Redis as
# a service, and don't want the customers to reconfigure the instances outside
# of the administration console.
#
# In such case it is possible to tell Sentinel to use different command names
# instead of the normal ones. For example if the master "mymaster", and the
# associated replicas, have "CONFIG" all renamed to "GUESSME", I could use:
#
# SENTINEL rename-command mymaster CONFIG GUESSME
#
# After such configuration is set, every time Sentinel would use CONFIG it will
# use GUESSME instead. Note that there is no actual need to respect the command
# case, so writing "config guessme" is the same in the example above.
#
# SENTINEL SET can also be used in order to perform this configuration at runtime.
#
# In order to set a command back to its original name (undo the renaming), it
# is possible to just rename a command to itsef:
#
# SENTINEL rename-command mymaster CONFIG CONFIG
# Generated by CONFIG REWRITE
sentinel leader-epoch mymaster 4
sentinel known-replica mymaster 192.168.60.151 6379
sentinel known-replica mymaster 192.168.60.150 6379
sentinel known-sentinel mymaster 192.168.60.151 26379 89825e4f65cab2651d44c330cad8b6851e2e8aee
sentinel known-sentinel mymaster 192.168.60.152 26379 9ac23ba6d6094c333e0cc7e01fa039804404e8b3
sentinel current-epoch 4

文章评论

0

其他文章