carlosfu
作者carlosfu·2022-03-03 14:34
软件开发工程师·快手

Redis 7配置解析

字数 5669阅读 3200评论 0赞 1

一、简述

Redis7 有很多新的功能、bug修改、特性优化,因此也伴随着很多新配置和变化,本文进行逐一说明

注:相关推荐配置只代表个人观点,实际要具体情况具体分析,没有万能配置。

二、配置详解

1.1 appenddirname (#9788)

默认:appendonlydir,动态修改:no
(1) 配置说明:

定义存储aof文件的目录名,它和配置dir组成绝对目录。

(2) 推荐配置:

和部署目录相关:决定是端口号或者默认值。

1.2 aof-timestamp-enabled (#9788)

默认:no,动态修改:yes
(1) 配置说明:

aof是否支持时间戳,如设置会变成:

TS:1646275867

*3
$3
set
$5
hello
$5
world

(2) 推荐配置:

结合现有体系决定。

注:有关新的aof,会有单独文章说明。

2.shutdown-timeout (#9872)

默认值:10,动态修改:true
(1) 配置说明:

当执行shutdown命令时,为slave节点复制剩余offset的最大等待时间,一定程度上提高一致性。

如果该配置为0,则该功能失效。

在Redis cron内如果发现shutdown-timeout不等于0,则会等待相关slave节点复制完毕。相关函数过长如感兴趣自行阅读。

server.c cron

if (isShutdownInitiated()) {

if (server.mstime >= server.shutdown_mstime || isReadyToShutdown()) {  
    if (finishShutdown() == C_OK) exit(0);  
}  

}

(2) 推荐配置:

可根据自身写入、网络等等情况进行配置,个人认为默认值基本OK。

3. maxmemory-clients (#8687)

默认值:0,动态修改:true
(1) 前情回顾(7.0之前)

(a) 对单个客户端输出缓冲区限制:

client-output-buffer-limit normal|slave|pubsub hardlimit sortlimit secends

(b) 对单个客户端的输入缓冲区,之前固定为1gb,在4.0之后改为可配置

client-query-buffer-limit 1gb
(2) 配置说明:

给所有clients加了最大内存的限制,当超过该限制后,Redis将会按照一定策略杀掉问题客户端,称为client eviction。

有两种配置方式:

(a) 具体值

maxmemory-clients 1g

(b) 百分比:为maxmemory配置的XX%

maxmemory-clients 10%
(3) 推荐配置:

如果整机部署密度较高,建议配置一定百分比,但会有客户端被干掉的风险。

4. repl-diskless-sync-max-replicas (#10092)

默认:0,动态修改:yes
(1) 配置说明:

无盘复制下,repl-diskless-sync-delay保证串行,repl-diskless-sync-max-replicas是在repl-diskless-sync-delay内的并行个数。

(2) 推荐配置:

可根据从节点个数,机器部署密度等情况设置。ps: 通常都是一主一从,不需要该配置。

5. list-max-listpack-_, hash-max-listpack-_, zset-max-listpack-* (#8887, #9366, #9740)

hash-max-listpack-entries 512
hash-max-listpack-value 64
list-max-listpack-size -2
zset-max-listpack-entries 128
zset-max-listpack-value 64

动态修改:yes

(1) 配置说明:

Redis 7中ziplist被listpack替代,所以相关配置都变为listpack,有关listpack会有单独文章说明。

(2) 推荐配置:

建议结合单核cpu使用量、数据量等综合评估成本收益、性能、可用性。

6. busy-reply-threshold (#9963)

默认:5000,动态修改:yes,设置为0关闭该功能
(1) 配置说明:

lua-time-limit的别名,分别服务于lua、function、module的一些特殊命令

(2) 推荐配置:

谨慎设置,超时后Redis只允许一些特殊命令(如下),其他命令均返回a BUSY error.

SCRIPT KILL, FUNCTION KILL, SHUTDOWN NOSAVE and possibly some module specific 'allow-busy' commands

7.1 latency-tracking (#9462)

默认:yes,动态修改:yes
(1) 配置说明:

是否开启命令latency追踪

(2) 推荐配置:

开启

7.2 latency-tracking-info-percentiles (#9462)

默认:50 99 99.9,动态修改:yes
(1) 配置说明:

对应p50(中位数)、p99、p99.9每个命令的耗时,例如:

info latencystats

latency_percentiles_usec_scan:p50=270.335,p99=7110.655,p99.9=10682.367
latency_percentiles_usec_slowlog|get:p50=6.015,p99=30.079,p99.9=34.047
latency_percentiles_usec_role:p50=9.023,p99=9.023,p99.9=9.023
latency_percentiles_usec_set:p50=1.003,p99=3.007,p99.9=7.007
latency_percentiles_usec_psync:p50=274.431,p99=274.431,p99.9=274.431
latency_percentiles_usec_strlen:p50=7.007,p99=7.007,p99.9=7.007
latency_percentiles_usec_config|get:p50=12.031,p99=72.191,p99.9=83.455
latency_percentiles_usec_config|set:p50=1769.471,p99=1769.471,p99.9=1769.471
latency_percentiles_usec_config|rewrite:p50=1015.807,p99=1015.807,p99.9=1015.807
latency_percentiles_usec_subscribe:p50=3.007,p99=4.015,p99.9=4.015
latency_percentiles_usec_replconf:p50=1.003,p99=2.007,p99.9=4.015
latency_percentiles_usec_get:p50=0.001,p99=3.007,p99.9=3.007
latency_percentiles_usec_info:p50=59.135,p99=1277.951,p99.9=1925.119
latency_percentiles_usec_command:p50=1310.719,p99=1310.719,p99.9=1310.719
latency_percentiles_usec_publish:p50=7.007,p99=11.007,p99.9=15.039
latency_percentiles_usec_del:p50=1.003,p99=5.023,p99.9=18.047
latency_percentiles_usec_client|setname:p50=0.001,p99=2.007,p99.9=2.007
latency_percentiles_usec_expire:p50=1.003,p99=6.015,p99.9=20.095
latency_percentiles_usec_mget:p50=2.007,p99=4.015,p99.9=7.007
latency_percentiles_usec_ping:p50=1.003,p99=2.007,p99.9=4.015
latency_percentiles_usec_type:p50=1.003,p99=5.023,p99.9=5.023
latency_percentiles_usec_dbsize:p50=1.003,p99=2.007,p99.9=3.007

(2) 推荐配置:

可以自行调配

8. cluster-port (#9389)

默认:0,动态修改:no,范围0~65535
(1) 配置说明:

redis cluster默认的通信(bus)端口 = port + 10000,该值可以动态设置指定端口,例如

port=6379 cluster-port=0 bus-port=16379
port=6380 cluster-port=5000 bus-port=5000
port=6381 cluster-port=15000 bus-port=15000

(2) 推荐配置:

如不是强烈需要,否则不要设置,会增加复杂性。

9. bind-source-addr (#9142)

默认:"",动态修改:yes
(1) 配置说明:

指定了redis作为客户端时,建立连接时指定源ip地址。包括:

  • 主从链接中,从节点链接到主节点建立连接时的源ip地址
  • sentinel链接所有实例时,建立连接时的源ip地址
  • cluster模式中,建立到其他节点的通信连接时的源ip地址
(2) 推荐配置:

如果有多个ip地址,并且有将正常请求和redis内部请求分开的需求时,可以使用此配置;

否则,不建议设置。

10.1 cluster-preferred-endpoint-type (#9530)

默认:ip,动态修改:yes, 有三个值:ip、hostname、unknown-endpoint
(1) 配置说明:

7.0后redis cluster除了支持ip,还支持了hostname。

(2) 推荐配置:

有强需求可以使用。

10.2 cluster-announce-hostname (#9530)

默认:空,动态修改:yes
(1) 配置说明:

如果cluster-preferred-endpoint-type设置为hostname,那cluster-announce-hostname就是具体的值。

(2) 推荐配置:

有强需求可以使用。

11. cluster-allow-pubsubshard-when-down (#8621)

默认:yes,动态修改:yes
(1) 配置说明:

当redis cluster处于down state时,是否可以继续使用shard pubsub。

(2) 推荐配置:

保持默认值,但是不建议在集群版用这个功能,单独部署一个redis sentinel做pubsub会更好。

12. cluster-link-sendbuf-limit (#9774)

默认:0(表示无穷大),动态修改:yes
(1) 配置说明:

针对redis cluster中每一个cluster bus link's send buffer容量进行限制,超过这个限制会被“干掉”。

相关查看命令:cluster links

相关统计 info memory中的mem_cluster_links是link的总内存

(2) 推荐配置:

建议配置一个合理值,因为正常情况下每个link的内存量不会很大。

13. enable-protected-configs (#9920)

默认:no,动态修改:no
(1) 配置说明:

设置是否允许对保护的配置进行动态配置;目前主要包括:

  • dbfilename
  • dir
(2) 推荐配置:

推荐默认设置即可。

14. enable-debug-command (#9920)

默认:no,动态修改:no
(1) 配置说明:

为了安全考虑,禁止掉debug命令,且不能动态修改

(2) 推荐配置:

debug命令在一些场景很有帮助,但对安全性有一些影响,需要综合评价,一定注意此配置不可以动态修改。

15. enable-module-command (#9920)

默认:no,动态修改:no
(1) 配置说明:

为了安全考虑,禁止掉module命令,且不能动态修改

(2) 推荐配置:

是否需要module来决定

16. loading-process-events-interval-bytes

默认:2MB,动态修改:yes
(1) 配置说明:

maximum single read or write chunk size

(2) 推荐配置:

如无特殊,默认即可。

三、默认值变化

  1. module 和 debug因为安全考虑,默认被禁止,且不能动态修改,这个一定注意。(#9920)
  2. 无盘复制作为默认选项,这个一定注意。(#10092)

四、总结

随着一些新功能的加入,Redis也添加了很多新配置,例如appenddirname、maxmemory-clients、latency-*,listpack相关等,同时有一些默认值也发生变化(默认禁止module和debug、默认开启无盘复制)

如果觉得我的文章对您有用,请点赞。您的支持将鼓励我继续创作!

1

添加新评论0 条评论

Ctrl+Enter 发表

作者其他文章

相关文章

相关问题

相关资料

X社区推广