深入浅出Redis7 配置文件

news/2024/7/6 1:34:58

Redis configuration https://redis.io/docs/management/config/

配置示例 Redis configuration file example https://redis.io/docs/management/config-file/

常用命令

config get 
config set 
config rewrite

REDIS CLUSTER

cluster-enabled

# Normal Redis instances can't be part of a Redis Cluster; only nodes that are
# started as cluster nodes can. In order to start a Redis instance as a
# cluster node enable the cluster support uncommenting the following:
#
# cluster-enabled yes

开启集群模式取消注释

Tips:重要参数,务必配置

cluster-config-file

# Every cluster node has a cluster configuration file.
# This file is not intended to be edited by hand.
# It is created and updated by Redis nodes.
# Every Redis Cluster node requires a different cluster configuration file.
# Make sure that instances running in the same system do not have overlapping cluster configuration file names.
# cluster-config-file nodes-6379.conf

集群中的每一个节点需要一个唯一名称的配置文件,集群节点会负责创建和修改工作。

Tips:重要参数,务必配置

cluster-node-timeout

# Cluster node timeout is the amount of milliseconds a node must be unreachable for it to be considered in failure state.
# Most other internal time limits are a multiple of the node timeout.
# cluster-node-timeout 15000

当通讯超过该时间的时候,集群会认为节点不可用。

cluster-port

# The cluster port is the port that the cluster bus will listen for inbound connections on.
# When set to the default value, 0, it will be bound to the command port + 10000.
# Setting this value requires you to specify the cluster bus port when executing cluster meet.
# cluster-port 0

集群通讯端口,默认情况是命令端口+10000,也就是16379,可以指定一个固定端口。

要保证集群节点的该端口均可访问,否则会影响集群的通讯等。

not try to failover(从节点是否参与选举的公式)

# A replica of a failing master will avoid to start a failover if its data looks too old.
# There is no simple way for a replica to actually have an exact measure of its "data age", so the following two checks are performed:

多个副本去参与failover(故障转移,选举)offset 越大也就是数据最全的rank(等级)越高,更容易成主节点。
# 1) If there are multiple replicas able to failover, they exchange messages in order to try to give an advantage to the replica with the best replication offset (more data from the master processed).
#    Replicas will try to get their rank by offset, and apply to the start of the failover a delay proportional to their rank.

每一个replica(从节点,副本)会计算最后一次和主节点通讯的时间。
# 2) Every single replica computes the time of the last interaction with its master.
#	 This can be the last ping or command received (if the master is still in the "connected" state), or the time that elapsed since the disconnection with the master (if the replication link is currently down).

如果最后一次通讯间隔太长,replica不会进行故障转移。
#    If the last interaction is too old, the replica will not try to failover at all.

这一点可以用户来控制,也就是通过配置文件的形式
# The point "2" can be tuned by user.

如果上一次通讯时间间隔 大于 这个公式计算出来的时间,副本节点不会进行 failover(故障转移)
# Specifically a replica will not perform the failover if, since the last interaction with the master, the time elapsed is greater than:
# (node-timeout * cluster-replica-validity-factor) + repl-ping-replica-period

如果这三个参数分别是ABC三个值,当时间大于(A*B+C)的时候,从节点不会参与选举。
# So for example if node-timeout is 30 seconds, and the cluster-replica-validity-factor is 10, and assuming a default repl-ping-replica-period of 10 seconds, the replica will not try to failover if it was not able to talk with the master for longer than 310 seconds.

cluster-replica-validity-factor 这个参数过大会导致有很多旧数据的从节点参与故障转移。太小可能会阻止集群选举一个副本
# A large cluster-replica-validity-factor may allow replicas with too old data to failover a master, while a too small value may prevent the cluster from being able to elect a replica at all.

为了maximum availability(最大的可用性),可以将 cluster-replica-validity-factor设置为0,这意味着replicas(从节点们)会忽略与主节点通信的延迟参加选failover,也就是只要可以跟master通讯,就认为你有资格参加选举。
# For maximum availability, it is possible to set the cluster-replica-validity-factor to a value of 0, which means, that replicas will always try to failover the master regardless of the last time they interacted with the master.

# (However they'll always try to apply a delay proportional to their offset rank).

# Zero is the only value able to guarantee that when all the partitions heal the cluster will always be able to continue.
上面公式中的B,高可用推荐设置为0
# cluster-replica-validity-factor 10

repl-ping-replica-period(公式中的C)master 间隔 10 向 replicas 发送 PINGs

# Master send PINGs to its replicas in a predefined interval.
# It's possible to change this interval with the repl_ping_replica_period option.
# The default value is 10 seconds.

# repl-ping-replica-period 10
  • A,node-timeout(节点超时时间)
  • B,cluster-replica-validity-factor(倍率)
  • C,repl-ping-replica-period(主从间隔Ping包)

总结:判定一个从节点是否参加选举的公式是(A*B+C),为了高可用推荐将B设置为0,这样只要replica可以与集群通讯就认为有资格进行故障转移(选举成为主节点)。

cluster-migration-barrier

集群副本能够迁移到孤立的主机,即没有工作副本的主机。
# Cluster replicas are able to migrate to orphaned masters, that are masters that are left without working replicas.

这提高了集群抵抗故障的能力,否则,如果没有有效的副本,孤立的主节点就不能在故障发生时进行故障转移。
# This improves the cluster ability to resist to failures as otherwise an orphaned master can't be failed over in case of failure if it has no working replicas.

只有当旧主机上至少还有给定数量的其他工作副本时,副本才会迁移到孤立主机。
# Replicas migrate to orphaned masters only if there are still at least a given number of other working replicas for their old master.

这个数字称为migration barrier(迁移阻碍)
# This number is the "migration barrier".

参数为1意味着只有当主服务器至少有一个其他工作副本时,副本服务器才会迁移,依此类推。
# A migration barrier of 1 means that a replica will migrate only if there is at least 1 other working replica for its master and so forth. 

它通常反映了集群中每个主服务器所需的副本数量。
#It usually reflects the number of replicas you want for every master in your cluster.

默认是1(只有他们的主节点至少包含一个从节点的时候才会发生迁移)
# Default is 1 (replicas migrate only if their masters remain with at least one replica).

如果想要禁止迁移,可以把这个参数设为很大的值,或者将 cluster-allow-replica-migration 变为no
# To disable migration just set it to a very large value or set cluster-allow-replica-migration to 'no'.

可以在调试中设置为0,不要再生产中设置为0,这是很危险的
# A value of 0 can be set but is useful only for debugging and dangerous in production.

默认为1
# cluster-migration-barrier 1

cluster-migration-barrier 这个参数控制集群 replica 的迁移限制,如果迁移后小于 N 值,会导致 replica 迁移失败。

问题:这个过程是自动的还是手动的?

cluster-allow-replica-migration

关闭这个选项允许自动化较低的集群配置,也就是说默认自动化较高
# Turning off this option allows to use less automatic cluster configuration.

它既禁止迁移到孤立的主服务器,也禁止从空的主服务器迁移。
# It both disables migration to orphaned masters and migration from masters that became empty.

默认为 yes ,允许自动migrations(迁移)
# Default is 'yes' (allow automatic migrations).

# cluster-allow-replica-migration yes

cluster-require-full-coverage

# cluster-require-full-coverage yes
  • 默认 yes,如果存在至少一个 slot 没有被实例覆盖,集群不可用,直到全部 slot 被实例所覆盖。
  • 改为 no 以后,即使有一个以上 slot 没有被实例覆盖集群仍然提供服务。

cluster-replica-no-failover

# cluster-replica-no-failover no

默认为 no,
如果设置为 yes,代表该节点如果为replica则永远不会failover(故障转移)成为master节点,仍然可以手动进行 failover

cluster-allow-reads-when-down

# cluster-allow-reads-when-down no

cluster-allow-pubsubshard-when-down

# cluster-allow-pubsubshard-when-down yes

cluster-link-sendbuf-limit

# cluster-link-sendbuf-limit 0

cluster-announce-hostname

# cluster-announce-hostname ""

http://lihuaxi.xjx100.cn/news/951824.html

相关文章

通信算法之117:数字下变频与上变频处理流程

AD936X内部集成模拟滤波器、混频器,频率合成器,以及直流偏置校准等功能。通过正交误差校准和直流偏置校准功能解决了零中频架构的直流偏置和正交误差限制。从而使零中频应用于软件无线电,无需外置滤波器。

(五十四)大白话索引的页存储物理结构,是如何用B+树来实现的?.md

上一次我们给大家说了主键索引的目录结构,只要在一个主键索引里包含每个数据页跟他最小主键值,就可以组成一个索引目录,然后后续你查询主键值,就可以在目录里二分查找直接定位到那条数据所属的数据页,接着到数据页里二…

嵌入式ARM端测试手册——全志T3+Logos FPGA评估板(下)

前 言 本指导文档适用开发环境: Windows开发环境:Windows 7 64bit、Windows 10 64bit Linux开发环境:Ubuntu18.04.4 64bit 虚拟机:VMware15.5.5 进行本文档操作前,请先按照调试工具安装、Linux开发环境搭建相关文档,安装SecureCRT串口调试终端、VMware虚拟机等相关软件。…

PTA L1-062 幸运彩票(详解)

前言:内容包括:题目,代码实现,大致思路,代码解读 题目: 彩票的号码有 6 位数字,若一张彩票的前 3 位上的数之和等于后 3 位上的数之和,则称这张彩票是幸运的。本题就请你判断给定的…

超级分时一

1.分时主图 ZRS:CONST(DYNAINFO(3)),NODRAW; A1:3.5*(EMA(CLOSE,48)-EMA(CLOSE,104))ZRS,COLORLIMAGENTA; A2:EMA(A1,36),COLORLIBLUE; MACD:(A1-A2)2ZRS; DRAWKLINE(H,O,L,C); STICKLINE(A1>A2,ZRS,MACD ,1,0),COLORRED; STICKLINE(A1>A2 AND MACD<REF(MACD,1),ZRS,M…

获取 本周、本月、本年 的开始或结束时间

获取 本周、本月、本年 的开始或结束时间 public class DateTimeUtil{// 获取 本周、本月、本年 的开始或结束时间/// <summary>/// 获取开始时间/// </summary>/// <param name"TimeType">Week、Month、Year</param>/// <param name&quo…

条款10:优先考虑限域enum而非未限域enum

通常来说&#xff0c;在花括号中声明一个名字会限制它的作用域在花括号之内。但这对于C98风格的enum中声明的枚举名&#xff08;译注&#xff1a;enumerator&#xff0c;连同下文“枚举名”都指enumerator&#xff09;是不成立的。这些枚举名的名字&#xff08;译注&#xff1a…

3.ffmpeg命令行环境搭建、ffmpeg命令行初步了解

在上章,我们讲过: ffmpeg.exe: 主要用于转码或者剪切的应用程序, 也可以从url/现场音频/视频源抓取输入源ffplay.exe: 主要用于播放视频的应用程序,该应用程序源码是开源的,我们后面章节会去源码分析ffprobe.exe: 主要用于分析视频码流的应用程序, 可以获取媒体文件的详细信息,…