Redis6 配置文件详解
1257字约4分钟
2024-08-10
Units 单位
配置内存大小单位,文件开头定义了一些基本的度量单位,只支持 bytes,不支持 bit,大小写不敏感
# Note on units: when memory size is needed, it is possible to specify
# it in the usual form of 1k 5GB 4M and so forth:
#
# 1k => 1000 bytes
# 1kb => 1024 bytes
# 1m => 1000000 bytes
# 1mb => 1024*1024 bytes
# 1g => 1000000000 bytes
# 1gb => 1024*1024*1024 bytes
#
# 不区分大小写
# units are case insensitive so 1GB 1Gb 1gB are all the same.
INCLUDES 包含
多个配置文件整合
################################## INCLUDES ###################################
# Include one or more other config files here. This is useful if you
# have a standard template that goes to all Redis servers but also need
# to customize a few per-server settings. Include files can include
# other files, so use this wisely.
#
# Note that option "include" won't be rewritten by command "CONFIG REWRITE"
# from admin or Redis Sentinel. Since Redis always uses the last processed
# line as value of a configuration directive, you'd better put includes
# at the beginning of this file to avoid overwriting config change at runtime.
#
# If instead you are interested in using includes to override configuration
# options, it is better to use include as the last line.
#
# include /path/to/local.conf
# include /path/to/other.conf
NETWORK
################################## NETWORK #####################################
#
# 只支持本地连接,如果要支持远程连接,直接注释这行就行
#
bind 127.0.0.1 -::1
#
# 保护模式:如果配置里没有指定bind和密码,开启后 redis 只会本机进行访问,拒绝外部访问。最好设置为 no
#
protected-mode yes
#
# 默认端口号
#
port 6379
#
# 设置 tcp 的 backlog,backlog 其实是一个连接队列,backlog 队列总和 = 未完成三次握手队列 + 已经完成三次握手队列
# 高并发环境下你需要一个高 backlog 值来避免慢客户端链接问题
#
tcp-backlog 511
#
# 设置客户端空闲超过timeout,服务端会断开连接,为0则服务端不会主动断开连接,不能小于0。单位:秒。
#
timeout 0
#
# 检查心跳时间。使用keepalive有两个好处:检测挂掉的对端。降低中间设备出问题而导致网络看似连接却已经与对端端口的问题。
#
tcp-keepalive 300
GENERAL
################################# GENERAL #####################################
#
# 是否在后台执行,yes:后台运行;no:不是后台运行(老版本默认)
#
daemonize yes
#
# redis的进程文件,每个实例会产生一个不同的 pid 文件
#
pidfile /var/run/redis_6379.pid
#
# Specify the server verbosity level.
# This can be one of:
# debug (a lot of information, useful for development/testing)
# verbose (many rarely useful info, but not a mess like the debug level)
# notice (moderately verbose, what you want in production probably)
# warning (only very important / critical messages are logged)
# 日志级别,有上面这几种
loglevel notice
#
# 日志文件的输出路径,默认为空
#
logfile ""
#
# 数据库的数量,默认使用的数据库是DB 0。可以通过”SELECT “命令选择一个db
#
databases 16
SECURITY
################################## SECURITY ###################################
# The requirepass is not compatable with aclfile option and the ACL LOAD
# command, these will cause requirepass to be ignored.
#
# 访问密码的查看、设置和取消。在命令中设置密码只是临时的,重启 redis 服务器,密码就还原了。永久设置修改配置文件
#
# requirepass foobared
SNAPSHOTTING
################################ SNAPSHOTTING ################################
# 持久化间隔配置,改变的 key 越多,写到磁盘的时间间隔越短
# Save the DB to disk.
#
# save <seconds> <changes>
#
# Redis will save the DB if both the given number of seconds and the given
# number of write operations against the DB occurred.
#
# Snapshotting can be completely disabled with a single empty string argument
# as in following example:
#
# 设置手动还是自动备份
#
# save ""
#
# Unless specified otherwise, by default Redis will save the DB:
# * After 3600 seconds (an hour) if at least 1 key changed
# * After 300 seconds (5 minutes) if at least 100 keys changed
# * After 60 seconds if at least 10000 keys changed
#
# You can set these explicitly by uncommenting the three following lines.
#
# save 3600 1
# save 300 100
# save 60 10000
#
# 默认 RDB 文件的名称
#
dbfilename dump.rdb
#
# RDB 文件目录,默认以启动的目录存放
#
dir ./
#
# 当 Redis 无法写入磁盘的话,直接关掉 Redis 的写操作,推荐 yes
#
stop-writes-on-bgsave-error yes
#
# 对于存储在磁盘中的快照,可以设置是否进行压缩存储。如果是的话,redis 会采用 LZF 算法进行压缩
# 如果不想消耗 CPU 资源来进行压缩的话,可以设置为关闭次功能,推荐 yes
#
rdbcompression yes
#
# 检查完整性,在存储快照后,还可以让 redis 使用 CRC64 算法来进行数据校验
# 但是这样做会增加大约 10% 的性能消耗,如果希望获取到最大的性能提升,可以关闭此功能
#
rdbchecksum yes
CLIENTS
################################### CLIENTS ####################################
#
# 客户端最大连接数
# maxclients 10000
APPEND ONLY MODE
############################## APPEND ONLY MODE ###############################
# By default Redis asynchronously dumps the dataset on disk. This mode is
# good enough in many applications, but an issue with the Redis process or
# a power outage may result into a few minutes of writes lost (depending on
# the configured save points).
#
# The Append Only File is an alternative persistence mode that provides
# much better durability. For instance using the default data fsync policy
# (see later in the config file) Redis can lose just one second of writes in a
# dramatic event like a server power outage, or a single write if something
# wrong with the Redis process itself happens, but the operating system is
# still running correctly.
#
# AOF and RDB persistence can be enabled at the same time without problems.
# If the AOF is enabled on startup Redis will load the AOF, that is the file
# with the better durability guarantees.
#
# Please check https://redis.io/topics/persistence for more information.
# aof 默认不开启
appendonly no
#
# 开启后的默认文件命名是 appendonly.aof
#
appendfilename "appendonly.aof"