Redis学习(六)-----------Redis配置文件(redis.conf)常用配置详细介绍

一、units单元

1、配置大小单位,开头定义了一些基本的度量单位,只支持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 5GB 4M的形式出现,以此类推:
#
# 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.
#单位不区分大小写,因此1GB 1Gb 1gB都是相同的

二、INCLUDES 包含

和我们的Struts2配置文件类似,可以通过includes包含,redis.conf可以作为总闸,包含其他


################################## 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
#有一个标准模板,可以转到所有的Redis服务器,但他也需要
#自定义一些服务器配置。包含的文件可以包含
# other files, so use this wisely.
#一些其他的文件,所以要谨慎的使用它。
#
# Notice 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.
#注意“include”选项不能被admin或Redis哨兵的
#“CONFIG REWRITE”命令重写。
#因为Redis总是使用最后解析的配置行作为配置指令的值,
#你最好在这个文件的开头配置include来避免它在运行时重写配置
#
# If instead you are interested in using includes to override configuration
# options, it is better to use include as the last line.
#如果相反你正好有兴趣使用includes去覆盖原来的配置,你最好在
#该文件的最后使用include
#
# include /path/to/local.conf
# include /path/to/other.conf


三、GENERAL通用

daemonize:设置为yes表示指定Redis以守护进程的方式启动(后台启动)。默认值为 no

pidfile:配置PID文件路径,当redis作为守护进程运行的时候,它会把 pid 默认写到 /var/redis/run/redis_6379.pid 文件里面

loglevel :定义日志级别。默认值为notice,有如下4种取值:
          debug(记录大量日志信息,适用于开发、测试阶段)
          verbose(较多日志信息)
          notice(适量日志信息,使用于生产环境)
          warning(仅有部分重要、关键信息才会被记录)

logfile :配置log文件地址,默认打印在命令行终端的窗口上

databases:设置数据库的数目。默认的数据库是DB 0 ,可以在每个连接上使用select 命令选择一个不同的数据库,dbid是一个介于0到databases - 1 之间的数值。默认值是 16,也就是说默认Redis有16个数据库。

################################# GENERAL #####################################

# 《1》指定是否开启守护进程
# By default Redis does not run as a daemon. Use 'yes' if you need it.
# Note that Redis will write a pid file in /var/run/redis.pid when daemonized.
daemonize yes
#默认Redis不会作为守护进程运行。如果你需要的话将配置改为yes.
#当以守护进程运行时,默认Redis会将进程号写
#入/var/run/redis.pid文件

#《2》指定监控
# If you run Redis from upstart or systemd, Redis can interact with your
# supervision tree. Options:
#如果以upstart或systemd方式运行Redis,Redis可以和监督树进行交互。选项:
#   supervised no      - no supervision interaction
#   supervised no      - 没有监督互动
#   supervised upstart - signal upstart by putting Redis into SIGSTOP mode
#   supervised upstart - 通过将Redis置于SIGSTOP模式来启动信号
#   supervised systemd - signal systemd by writing READY=1 to $NOTIFY_SOCKET
#   supervised systemd - signal systemd将READY = 1写入$ NOTIFY_SOCKET
#   supervised auto    - detect upstart or systemd method based on
#                        UPSTART_JOB or NOTIFY_SOCKET environment variables
#   supervised auto    - 检测upstart或systemd方法基于 UPSTART_JOB或NOTIFY_SOCKET环境变量
# Note: these supervision methods only signal "process is ready."
#  这些监督方法只能表明“过程已经准备好了”
#       They do not enable continuous liveness pings back to your supervisor.
#他们不会将持续的活跃状态返回给你的监督器
supervised no

#《3》以守护进程方式运行时,默认Redis写入进程id的文件路径
# If a pid file is specified, Redis writes it where specified at startup
# and removes it at exit.
#如果指定了pid文件,Redis将在启动时将其写入到指定的位置并在退出时将其删除
#
# When the server runs non daemonized, no pid file is created if none is
# specified in the configuration. When the server is daemonized, the pid file
# is used even if not specified, defaulting to "/var/run/redis.pid".
#当服务器以非守护进程方式运行时,即使在配置文件中指定了也不会去创建pid文件,当服务器以守护进程方式启动时,即使未被指定也会创建pid文件,默认路径“/var/run/redis.pid”。
#
# Creating a pid file is best effort: if Redis is not able to create it
# nothing bad happens, the server will start and run normally.
#创建一个pid文件是最好的工作:如果redis无法创建它,并不会有什么不好的事情发生,服务将会
#正常的启动和运行
pidfile /var/run/redis_6379.pid

#《4》设置日志级别
# Specify the server verbosity level.
#指定服务器详细的级别。
# This can be one of:
#可以是以下其中之一:
# debug (a lot of information, useful for development/testing)
# debug (很多信息,对开发/测试很有用)
# verbose (many rarely useful info, but not a mess like the debug level)
# verbose (很多精简的有用信息,但是不像debug等级那么多)
# notice (moderately verbose, what you want in production probably)
# notice (适量的信息,基本上是你生产环境中需要的程度)
# warning (only very important / critical messages are logged)
# warning (只有很重要/严重的信息会记录下来)
loglevel notice

#《5》指定日志文件名
# Specify the log file name. Also the empty string can be used to force
# Redis to log on the standard output. Note that if you use standard
# output for logging but daemonize, logs will be sent to /dev/null
#指定日志文件名。空的字符串也可以用于强制Redis登录标准输出。请注意,如果你使用标准的日志输出且
#是守护进程方式,logs将被发送到/dev/null
logfile ""

#《6》是否使用系统日志记录器
# To enable logging to the system logger, just set 'syslog-enabled' to yes,
# and optionally update the other syslog parameters to suit your needs.
#要启用系统日志记录器,只需将'syslog-enabled'设置为yes,
#并且可以选择更新其他syslog参数以满足你的需求。
# syslog-enabled no


# 《7》指明syslog身份
# Specify the syslog identity.
#指定syslog标识
# syslog-ident redis

#《8》指明syslog的设备
# Specify the syslog facility. Must be USER or between LOCAL0-LOCAL7.
#指明syslog设备。必须是USER或LOCAL0-LOCAL7之间
# syslog-facility local0

#《9》设置数据库个数
# Set the number of databases. The default database is DB 0, you can select
# a different one on a per-connection basis using SELECT <dbid> where
# dbid is a number between 0 and 'databases'-1
#设置数据库的数量。默认的是数据库是DB 0,你可以通过使用SELECT <dbid>命令选择
#在连接基础上的数据库,dbid是介于0和'databases'-1之间的数字
databases 16

# By default Redis shows an ASCII art logo only when started to log to the
# standard output and if the standard output is a TTY. Basically this means
# that normally a logo is displayed only in interactive sessions.
#默认情况下,Redis仅在开始登录时显示ASCII艺术徽标
#为标准输出,如果标准输出是TTY。基本上这意味着
#通常只在交互式会话中显示徽标。
#
# However it is possible to force the pre-4.0 behavior and always show a
# ASCII art logo in startup logs by setting the following option to yes.
#通过将以下选项设置为yes可以强制执行4.0之前的特性并始终显示
#启动日志中的ASCII 艺术徽标
always-show-logo yes

四、SNAPSHOTTING 快照

主要用来做持久化操作

save:这里是用来配置触发 Redis的持久化条件,也就是什么时候将内存中的数据保存到硬盘。默认如下配置:
save 900 1:表示900 秒内如果至少有 1 个 key 的值变化,则保存
save 300 10:表示300 秒内如果至少有 10 个 key 的值变化,则保存
save 60 10000:表示60 秒内如果至少有 10000 个 key 的值变化,则保存
当然如果你只是用Redis的缓存功能,不需要持久化,那么你可以注释掉所有的 save 行来停用保存功能。可以直接一个空字符串来实现停用:save “”

stop-writes-on-bgsave-error :默认值为yes。当启用了RDB且最后一次后台保存数据失败,Redis是否停止接收数据。这会让用户意识到数据没有正确持久化到磁盘上,否则没有人会注意到灾难(disaster)发生了。如果Redis重启了,那么又可以重新开始接收数据了

rdbcompression ;默认值是yes。对于存储到磁盘中的快照,可以设置是否进行压缩存储。如果是的话,redis会采用LZF算法进行压缩。如果你不想消耗CPU来进行压缩的话,可以设置为关闭此功能,但是存储在磁盘上的快照会比较大。

rdbchecksum :默认值是yes。在存储快照后,我们还可以让redis使用CRC64算法来进行数据校验,但是这样做会增加大约10%的性能消耗,如果希望获取到最大的性能提升,可以关闭此功能。>dbfilename :设置快照的文件名,默认是 dump.rdb

dir:设置快照文件的存放路径,这个配置项一定是个目录,而不能是文件名。使用上面的 dbfilename 作为保存的文件名。


#
# Save the DB on disk:
# 将数据库存储在磁盘上
#
#   save <seconds> <changes>
#
#   Will save the DB if both the given number of seconds and the given
#   number of write operations against the DB occurred.
#   会在指定的秒数和数据量变化次数之后将数据写在磁盘上
#
#   In the example below the behaviour will be to save:
#   after 900 sec (15 min) if at least 1 key changed
#   after 300 sec (5 min) if at least 10 keys changed
#   after 60 sec if at least 10000 keys changed
#   下面的例子将会进行把数据写入磁盘的操作: 
#   900秒(15分钟)之后,且至少1次变更 
#   300秒(5分钟)之后,且至少10次变更 
#   60秒之后,且至少10000次变更 
#
#   Note: you can disable saving completely by commenting out all "save" lines.
#   注意:你可以通过注释掉所有“save”来禁用保存
#
#   It is also possible to remove all the previously configured save
#   points by adding a save directive with a single empty string argument
#   like in the following example:
#   就像下面的例子,也可以删除之前所有保存的配置,通过添加单个空字符串的方式来指向:
#
#   save ""

save 900 1
save 300 10
save 60 10000

# By default Redis will stop accepting writes if RDB snapshots are enabled
# (at least one save point) and the latest background save failed.
#  默认如果开启了RDB快照(至少一个save指令),Redis将会停止接受写入操作且
#  最新的后台保存将会失败。
# This will make the user aware (in a hard way) that data is not persisting
# on disk properly, otherwise chances are that no one will notice and some
# disaster will happen.
# 这必须要让用户意识到(一种困难的方式)数据没有持久化到硬盘上,否则改变将不会有人注意到
# 并且一些灾难将会发生。
#
# If the background saving process will start working again Redis will
# automatically allow writes again.
# 如果后台保存进程能重新开始工作,Redis将自动再次允许写操作。
#
# However if you have setup your proper monitoring of the Redis server
# and persistence, you may want to disable this feature so that Redis will
# continue to work as usual even if there are problems with disk,
# permissions, and so forth.
# 然而,如果你已经对Redis服务器和持久化进行了适当的设置,你可能想要禁止这个功能
# 以便于即使Redis的磁盘出现了问题也可以向平时一样正常的继续工作,等等。
#
stop-writes-on-bgsave-error yes

# Compress string objects using LZF when dump .rdb databases?
# 导出.rdb数据库时使用LZF压缩字符串对象?
# For default that's set to 'yes' as it's almost always a win.
# 默认设置为“yes”因为这几乎总是正确的。
# If you want to save some CPU in the saving child set it to 'no' but
# the dataset will likely be bigger if you have compressible values or keys.
# 如果在保存子节点时你想节省一点CPU的话可以把这个值设为“no”,但是如果你有可压缩的key或者
# value的话那么数据文件可能会更大。
rdbcompression yes

# Since version 5 of RDB a CRC64 checksum is placed at the end of the file.
# 自RDB版本5以后,CRC64校验和被放在了文件的最后。
# This makes the format more resistant to corruption but there is a performance
# hit to pay (around 10%) when saving and loading RDB files, so you can disable it 
# for maximum performances.
# 这使得文件格式更加可靠,但是在生产和加载RDB文件时有一个性能消耗(大约百分之十),
# 所以你可以关掉它来获得更好的性能。
#
# RDB files created with checksum disabled have a checksum of zero that will
# tell the loading code to skip the check.
# 禁用校验和创建的RDB文件校验和为0,这将告诉代码加载时跳过检查
rdbchecksum yes

# The filename where to dump the DB
# 转储数据库文件名
dbfilename dump.rdb

# The working directory.
# 工作目录
#
# The DB will be written inside this directory, with the filename specified
# above using the 'dbfilename' configuration directive.
# 数据库会被写到这个目录下,文件名就是上面的“dbfilename”配置的值
#
# The Append Only File will also be created inside this directory.
# 累加的文件也会放在这个目录下面。
#
# Note that you must specify a directory here, not a file name.
# 注意这里你指定的必须是目录而不是文件名
dir ./


五、REPLICATION 复制

replicaof 当设置本机为从服务器时,设置master服务的IP地址及端口,在Redis启动时,它会自动从master进行数据同步

masterauth 当master服务设置了密码保护时,从服务器连接master的密码

replica-serve-stale-data yes 当主从连接中断,或者主从复制建立期间,是否允许从服务器对外提供服务。默认为yes,即允许对外提供服务,但有可能读到脏数据。

replica-read-only yes 将从服务器设置为只读模式。需要注意,只读模式针对的只是客户端的写操作,对管理命令无效。

repl-diskless-sync no 是否使用无盘复制。为了降低主节点磁盘开销,Redis支持无盘复制,生成的RDB文件不保存到磁盘而是直接通过网络发送给从节点。无盘复制适用于主节点所在机器磁盘性能较差但网络宽带较充裕的场景。需要注意的是,无盘复制目前依然处于实验阶段。

repl-ping-replica-period 10 ,repl-diskless-sync-delay 5 master每隔一段固定的时间向从服务器发送一个PING命令

repl-timeout 复制超时时间。

repl-disable-tcp-nodelay 设置为yes,主节点会等待一段时间才发送TCP数据包,具体等待时间取决于Linux内核,一般是40毫秒。适用于主从网络环境复杂或带宽紧张的场景。默认为no。

repl-backlog-size 复制积压缓冲区,复制积压缓冲区是保存在主节点上的一个固定长度的队列。用于从Redis 2.8开始引入的部分复制。

repl-backlog-ttl 如果master上的从服务器全都断开了,且在指定的时间内没有连接上,则backlog会被master清除掉。repl-backlog-ttl即用来设置该时长,默认为3600s,如果设置为0,则永不清除。

replica-priority 设置从服务器的优先级,用于Redis Sentinel主从切换时使用,值越小,则提升为主的优先级越高。需要注意的是,如果设置为0,则代表该从服务器不参加选主。

replica-announce-ip,replica-announce-port 常用于端口转发或NAT场景下,对Master暴露真实IP和端口信息。


# Master-Replica replication. Use replicaof to make a Redis instance a copy of
# another Redis server. A few things to understand ASAP about Redis replication.
# Master-Replica 复制。使用replicaof将一个Redis的实例作为另外Redis服务器的副本。
#
#   +------------------+      +---------------+
#   |      Master      | ---> |    Replica    |
#   | (receive writes) |      |  (exact copy) |
#   +------------------+      +---------------+
#
# 1) Redis replication is asynchronous, but you can configure a master to
#    stop accepting writes if it appears to be not connected with at least
#    a given number of replicas.
# 1) Redis复制是异步的, 但是你可以配置一个主服务器来停止接受写操作,
#   如果它看起来至少没有连接到给定数量的副本。
# 2) Redis replicas are able to perform a partial resynchronization with the
#    master if the replication link is lost for a relatively small amount of
#    time. You may want to configure the replication backlog size (see the next
#    sections of this file) with a sensible value depending on your needs.
# 2) 如果复制链接丢失的时间相对较短,Redis副本能够与主服务器执行部分重新同步。
#   你可能想要根据需要配置具有合理值的复制积压大小(请参阅文件下部分)。
# 3) Replication is automatic and does not need user intervention. After a
#    network partition replicas automatically try to reconnect to masters
#    and resynchronize with them.
# 3) 复制是自动的,不需要用户来参与。在网络分区之后,副本自动尝试重新连接到主服务器并
#    与它们重新同步
#    
#  
# replicaof <masterip> <masterport>

# If the master is password protected (using the "requirepass" configuration
# directive below) it is possible to tell the replica to authenticate before
# starting the replication synchronization process, otherwise the master will
# refuse the replica request.
# 如果主服务器受密码保护(使用下面的“requirepass”配置指令),可以在启动复制同步进程之前
# 告诉副本进行身份验证,否则主服务器将拒绝复制请求。
# masterauth <master-password>

# When a replica loses its connection with the master, or when the replication
# is still in progress, the replica can act in two different ways:
# 当副本丢失与主服务器的连接,或者当复制仍在进行时,副本可以以两种不同的方式运行:
#
# 1) if replica-serve-stale-data is set to 'yes' (the default) the replica will
#    still reply to client requests, possibly with out of date data, or the
#    data set may just be empty if this is the first synchronization.
# 1) 如果replica-serve-stale-data 被设置为‘yes’(默认值),副本仍会响应客户端请求,
#    可能是数据过期,或者如果这是第一次同步,数据集可能只是空的。
#
# 2) if replica-serve-stale-data is set to 'no' the replica will reply with
#    an error "SYNC with master in progress" to all the kind of commands
#    but to INFO, replicaOF, AUTH, PING, SHUTDOWN, REPLCONF, ROLE, CONFIG,
#    SUBSCRIBE, UNSUBSCRIBE, PSUBSCRIBE, PUNSUBSCRIBE, PUBLISH, PUBSUB,
#    COMMAND, POST, HOST: and LATENCY.
# 2) 如果replica-service-stale-data被设置为“no”,那么该副本将会对所有类型的命令做出
# 错误的响应,“SYNC with master in progress”,但是对INFO、replicaOF、AUTH、PING、
# SHUTDOWN、 REPLCONF、ROLE、CONFIG、SUBSCRIBE、UNSUBSCRIBE、PSUBSCRIBE、
# PUNSUBSCRIBE、 PUBLISH、PUBSUB、COMMAND、POST、HOST:和LATENCY进行同步。
#
replica-serve-stale-data yes

# You can configure a replica instance to accept writes or not. Writing against
# a replica instance may be useful to store some ephemeral data (because data
# written on a replica will be easily deleted after resync with the master) but
# may also cause problems if clients are writing to it because of a
# misconfiguration.
# 你可以配置一个副本实例来接受写操作或者不接受写操作。
# 对副本实例进行写操作对于存储一些临时数据可能是很有用的(因为在与主实例重新同步之后,在副本上
# 写的数据将很容易被删除)但是如果客户端由于配置错误而对其进行写操作,也可能会导致问题。
#
#
# Since Redis 2.6 by default replicas are read-only.
# 因为redis 2.6默认情况下是只读的。
#
# Note: read only replicas are not designed to be exposed to untrusted clients
# on the internet. It's just a protection layer against misuse of the instance.
# 注意: 只读副本不是为了暴露给在网上不受信任的客户端而设计的。
# 它只是一个防止滥用实例的保护层。
# Still a read only replica exports by default all the administrative commands
# such as CONFIG, DEBUG, and so forth. To a limited extent you can improve
# security of read only replicas using 'rename-command' to shadow all the
# administrative / dangerous commands.
# 默认情况下,仍然是只读副本导出所有管理命令,如CONFIG, DEBUG等。
# 在一定程度上,你可以使用‘rename-command’来隐藏所有管理/危险的命令,从而提高只读副本的
# 安全性。
replica-read-only yes

# Replication SYNC strategy: disk or socket.
# 复制同步策略:disk or socket.
# -------------------------------------------------------
# WARNING: DISKLESS REPLICATION IS EXPERIMENTAL CURRENTLY
# 警告:无磁盘复制目前处于试验阶段
# -------------------------------------------------------
#
# New replicas and reconnecting replicas that are not able to continue the replication
# 无法继续复制的新副本和重新连接的副本
# process just receiving differences, need to do what is called a "full
# synchronization". An RDB file is transmitted from the master to the replicas.
# The transmission can happen in two different ways:
# 进程只是接收差异,需要做的就是所谓的“完全同步”。RDB文件从主服务器传输到副本。
# 传输方式可以通过两种不同的方式发生:
# 1) Disk-backed: The Redis master creates a new process that writes the RDB
#                 file on disk. Later the file is transferred by the parent
#                 process to the replicas incrementally.
# 1) Disk-backed: Redis主服务器将创建一个新进程,将RDB文件写在磁盘上。
#                 稍后父进程将文件以增量方式传输到副本。
# 2) Diskless: The Redis master creates a new process that directly writes the
#              RDB file to replica sockets, without touching the disk at all.
# 2) Diskless: Redis主服务器创建一个新进程,直接将RDB文件写入副本套接字,而根本不接触磁盘
# With disk-backed replication, while the RDB file is generated, more replicas
#使用磁盘支持的复制,在RDB文件生成时,会产生很多的副本
# can be queued and served with the RDB file as soon as the current child producing
# the RDB file finishes its work. With diskless replication instead once
# the transfer starts, new replicas arriving will be queued and a new transfer
# will start when the current one terminates.
# 一旦当前生成RDB文件的子程序完成其工作,就可以排队并与
# RDB文件一起提供服务。 在无盘复制的情况下,一旦传输开始
# ,到达的新副本将会排队,当当前副本终止时,将启动新的传输
#
# When diskless replication is used, the master waits a configurable amount of
# time (in seconds) before starting the transfer in the hope that multiple replicas
# will arrive and the transfer can be parallelized.
# 当使用无磁盘复制时,主服务器在开始传输之前会等待一段
# 可配置的时间(以秒为单位),希望多个副本可以到达并且
# 传输可以并行化。
# With slow disks and fast (large bandwidth) networks, diskless replication
# works better.
# 使用慢速磁盘和快速(大带宽)网络,无磁盘复制可以
# 更好的工作
repl-diskless-sync no

# When diskless replication is enabled, it is possible to configure the delay
# the server waits in order to spawn the child that transfers the RDB via socket
# to the replicas.
# 当使用无磁盘复制时,可以配置服务器等待的延迟,以便生成通过套接字将RDB传输到副本的子节点。
#
# This is important since once the transfer starts, it is not possible to serve
# new replicas arriving, that will be queued for the next RDB transfer, so the server
# waits a delay in order to let more replicas arrive.
# 这一点很重要,因为一旦传输开始,就不可能为到达的新副本提供服务,
# 这些副本将排队等待下一次RDB传输,因此服务器等待延迟,以便让更多副本到达。
#
# The delay is specified in seconds, and by default is 5 seconds. To disable
# it entirely just set it to 0 seconds and the transfer will start ASAP.
# 延迟单位指定以秒为单位,默认的为5秒。要完全禁用它,只需将它设置为0秒,传输将尽快完成。
repl-diskless-sync-delay 5

# Replicas send PINGs to server in a predefined interval. It's possible to change
# this interval with the repl_ping_replica_period option. The default value is 10
# seconds.
# 副本按预先定义好的时间间隔向主服务器发送pings命令。可以使用repl_ping_replica_period更改时间
# 间隔。默认值是10秒。
#
# repl-ping-replica-period 10

# The following option sets the replication timeout for:
# 下面的选项设置复制的超时时间:
#
# 1) Bulk transfer I/O during SYNC, from the point of view of replica.
# 1) 从副本的角度来看,同步过程中的批量I/O传输。
# 2) Master timeout from the point of view of replicas (data, pings).
# 2) 从副本(data,pings)的角度来看主服务器超时时间。
# 3) Replica timeout from the point of view of masters (REPLCONF ACK pings).
# 3) 从主服务器的角度看副本超时(REPLCONF ACK ping)
#
# It is important to make sure that this value is greater than the value
# specified for repl-ping-replica-period otherwise a timeout will be detected
# every time there is low traffic between the master and the replica.
# 确保此值大于为repl-ping-replica-period设置的值很重要,否则每次主服务器和副本之间的
# 流量较低时都会检测到超时。
#
# repl-timeout 60

# Disable TCP_NODELAY on the replica socket after SYNC?
# 同步之后在副本套接字上禁用TCP_NODELAY ?
#
# If you select "yes" Redis will use a smaller number of TCP packets and
# less bandwidth to send data to replicas. But this can add a delay for
# the data to appear on the replica side, up to 40 milliseconds with
# Linux kernels using a default configuration.
# 如果你选择‘yes’,Redis将使用较少数量的TCP数据包和很少的带宽向副本发送数据。
# 但是这可能会增加数据在副本上出现的延迟,使用默认配置的Linux内核,最多可延迟40毫秒。
#
# If you select "no" the delay for data to appear on the replica side will
# be reduced but more bandwidth will be used for replication.
# 如果选择‘no’,则数据数据出现在副本上的延迟将会减少,但这将使用更多的带宽来进行复制。
#
# By default we optimize for low latency, but in very high traffic conditions
# or when the master and replicas are many hops away, turning this to "yes" may
# be a good idea.
# 默认情况下,我们会针对低延时进行优化,但是在非常高的流量条件下,或者当副本和主服务器需要多次
# 跳转时,将它设置为‘yes’时会是一个好的主意。
repl-disable-tcp-nodelay no

# Set the replication backlog size. The backlog is a buffer that accumulates
# replica data when replicas are disconnected for some time, so that when a replica
# wants to reconnect again, often a full resync is not needed, but a partial
# resync is enough, just passing the portion of data the replica missed while
# disconnected.
# 设置复制代办事项列表大小。backlog是一个缓冲区,当副本断开连接一段时间之后,它会积累副本的
# 数据,因此当副本想要重新连接时,通常不需要完全重新同步,但是部分重新同步就足够了,只需要
# 传递在断开连接时副本丢失的部分数据。
#
# The bigger the replication backlog, the longer the time the replica can be
# disconnected and later be able to perform a partial resynchronization.
# 复制backlog值越大,副本可以断开连接的时间就越长,并且以后能够执行部分重新同步。
#
# The backlog is only allocated once there is at least a replica connected.
# 只有在至少连接了一个副本之后,才会分配backlog。
#
# repl-backlog-size 1mb

# After a master has no longer connected replicas for some time, the backlog
# will be freed. The following option configures the amount of seconds that
# need to elapse, starting from the time the last replica disconnected, for
# the backlog buffer to be freed.
# 当主服务器有一段时间不在连接副本之后,将释放backlog。下面的选项配置从最后一个副本断开连接开始,
# 要释放积压缓冲区所需的秒数。
#
# Note that replicas never free the backlog for timeout, since they may be
# promoted to masters later, and should be able to correctly "partially
# resynchronize" with the replicas: hence they should always accumulate backlog.
# 请注意,副本永远不会为超时而释放积压,因为它们可能会在以后被升级为主服务器,并且
# 能够与副本正确的‘部分重新同步’,因此它们应该始终积累积压。
#
# A value of 0 means to never release the backlog.
# 值0意味着永远不释放积压。
#
# repl-backlog-ttl 3600

# The replica priority is an integer number published by Redis in the INFO output.
# It is used by Redis Sentinel in order to select a replica to promote into a
# master if the master is no longer working correctly.
# 副本优先级是Redis在INFO输出中发布的一个整数。
# 如果主服务器不在正常工作,Redis Sentinel将使用它来选择要升级为主服务器的副本。
#
# A replica with a low priority number is considered better for promotion, so
# for instance if there are three replicas with priority 10, 100, 25 Sentinel will
# pick the one with priority 10, that is the lowest.
# 优先级较低的副本被认为更适合升级,例如,如果有三个优先级为10,100,25的副本,Sentinel 将会选择优先级
# 为10的副本,因为这是最低的。
#
# However a special priority of 0 marks the replica as not able to perform the
# role of master, so a replica with priority of 0 will never be selected by
# Redis Sentinel for promotion.
# 但是一个特殊的优先级为0的副本将不能被升级为主服务器,因为Redis Sentinel永远不会选择优先级为0的副本
# 进行升级
#
# By default the priority is 100.
# 默认的优先级是100.
replica-priority 100

# It is possible for a master to stop accepting writes if there are less than
# N replicas connected, having a lag less or equal than M seconds.
# 如果连接的副本少于N个,并且延迟小于或等于M秒,则主服务器有可能停止接受写入操作。
#
# The N replicas need to be in "online" state.
# N个副本需要出于在线状态。
#
# The lag in seconds, that must be <= the specified value, is calculated from
# the last ping received from the replica, that is usually sent every second.
# 以秒为单位的延迟(必须<=指定值)是根据从副本收到的最后一次ping计算的,通常每秒发送一次
#
# This option does not GUARANTEE that N replicas will accept the write, but
# will limit the window of exposure for lost writes in case not enough replicas
# are available, to the specified number of seconds.
# 此选项不能保证n个副本将接受写入,但会将丢失写入的暴露时间限制在指定的秒数内,以防没有足够的副本可用。
#
# For example to require at least 3 replicas with a lag <= 10 seconds use:
# 例如,要要求至少3个延迟<=10秒的副本,请使用:
#
# min-replicas-to-write 3
# min-replicas-max-lag 10
#
# Setting one or the other to 0 disables the feature.
# 将其中一个或另一个设置为0将禁用该特性。
#
# By default min-replicas-to-write is set to 0 (feature disabled) and
# min-replicas-max-lag is set to 10.
# 默认情况下,min- copy -to-write设置为0(禁用特性),min- copy -max-lag设置为10

# A Redis master is able to list the address and port of the attached
# replicas in different ways. For example the "INFO replication" section
# offers this information, which is used, among other tools, by
# Redis Sentinel in order to discover replica instances.
# Another place where this info is available is in the output of the
# "ROLE" command of a master.
# Redis主服务器能够以不同方式列出附加副本的地址和端口。
# 例如,“INFO replication”部分提供了这些信息,Redis Sentinel使用这些信息以及其他工具来发现副本实例。
# 另一个可以获得此信息的地方是master的“role”命令的输出。
#
# The listed IP and address normally reported by a replica is obtained
# in the following way:
# 所列的IP和地址通常由一个副本报告,通过以下方法获得:
#
#   IP: The address is auto detected by checking the peer address
#   of the socket used by the replica to connect with the master.
#   IP: 通过检查复制副本用于连接主机的套接字的对等地址,可以自动检测该地址。
#
#   Port: The port is communicated by the replica during the replication
#   handshake, and is normally the port that the replica is using to
#   listen for connections.
#   Port:该端口在复制握手期间由副本通信,通常是副本用来侦听端口。
#
# However when port forwarding or Network Address Translation (NAT) is
# used, the replica may be actually reachable via different IP and port
# pairs. The following two options can be used by a replica in order to
# report to its master a specific set of IP and port, so that both INFO
# and ROLE will report those values.
# 然而,当使用端口转发或网络地址转换(NAT)时,副本实际上可以通过不同的IP和端口访问。
# 副本可以使用一下两个选项向其主服务器报告一组特定的IP和端口,一遍INFo和ROLE都能报告这些值
#
# There is no need to use both the options if you need to override just
# the port or the IP address.
# 如果只需要覆盖端口或IP地址,则不需要同时使用这两种选项。
#
# replica-announce-ip 5.5.5.5
# replica-announce-port 1234


六 、SECURITY 安全


# Require clients to issue AUTH <PASSWORD> before processing any other
# commands.  This might be useful in environments in which you do not trust
# others with access to the host running redis-server.
# 要求客户端在处理任何其他命令之前发出Auth<Password>。
# 这在不信任其他具有访问主机运行Redis-server的主机的环境中可能是有用的。
#
# This should stay commented out for backward compatibility and because most
# people do not need auth (e.g. they run their own servers).
# 为了向后兼容性,这应该保留注释,因为大多数人不需要auth(例如,他们运行自己的服务器)
#
# Warning: since Redis is pretty fast an outside user can try up to
# 150k passwords per second against a good box. This means that you should
# use a very strong password otherwise it will be very easy to break.
# 警告:由于Redis非常快,外部用户可以在一个好的盒子上每秒尝试多达150k的密码。
# 这意味着您应该使用一个非常强大的密码,否则它将非常容易被打破。
#
# requirepass foobared

# Command renaming.
#
# It is possible to change the name of dangerous commands in a shared
# environment. For instance the CONFIG command may be renamed into something
# hard to guess so that it will still be available for internal-use tools
# but not available for general clients.
# 可以在共享环境中更改危险命令的名称。 例如,可以将CONFIG命令重命名为难以猜测的内容,
# 以便它仍可用于内部使用工具,但不适用于一般客户端。
#
# Example:
#
# rename-command CONFIG b840fc02d524045429941cc15f59e41cb7be6c52
#
# It is also possible to completely kill a command by renaming it into
# an empty string:
# 还可以通过将命令重命名为空字符串来完全终止命令:
#
# rename-command CONFIG ""
#
# Please note that changing the name of commands that are logged into the
# AOF file or transmitted to replicas may cause problems.
# 请注意,更改记录到AOF文件中或发送到复制副本的命令的名称可能会引起问题。

七、MEMORY MANAGEMENT 内存管理

maxmemory 指定Redis最大内存限制,Redis在启动时会把数据加载到内存中,达到最大内存后,Redis会先尝试清除已到期或即将到期的Key,当此方法处理 后,仍然到达最大内存设置,将无法再进行写入操作,但仍然可以进行读取操作。Redis新的vm机制,会把Key存放内存,Value会存放在swap区

maxmemory-policy noeviction
当内存使用达到最大值时,redis使用的清除策略。
(1)volatile-lru:使用LRU算法移除key,只对设置了过期时间的键
(2)allkeys-lru:使用LRU算法移除key
(3)volatile-random:在过期集合中移除随机的key,只对设置了过期时间的键
(4)allkeys-random:移除随机的key
(5)volatile-ttl:移除那些TTL值最小的key,即那些最近要过期的key
(6)noeviction:不进行移除。针对写操作,只是返回错误信息

maxmemory-samples 5 设置样本数量,LRU算法和最小TTL算法都并非是精确的算法,而是估算值,所以你可以设置样本的大小,
redis默认会检查这么多个key并选择其中LRU的那个

replica-ignore-maxmemory yes 是否忽略maxmemory设置


# Set a memory usage limit to the specified amount of bytes.
# 将内存使用限制设置为指定的字节数。
# When the memory limit is reached Redis will try to remove keys
# according to the eviction policy selected (see maxmemory-policy).
# 当达到内存限制时,Redis将根据所选的清除策略(请参阅maxmemory-policy)删除键。
#
# If Redis can't remove keys according to the policy, or if the policy is
# set to 'noeviction', Redis will start to reply with errors to commands
# that would use more memory, like SET, LPUSH, and so on, and will continue
# to reply to read-only commands like GET.
# 果Redis不能根据策略删除键,或者如果策略被设置为“noeviction”,Redis将开始对需要
# 更多内存的命令(如set、LPUSH等)进行错误响应,并将继续 回复像GET这样的只读命令。
#
# This option is usually useful when using Redis as an LRU or LFU cache, or to
# set a hard memory limit for an instance (using the 'noeviction' policy).
# 当使用Redis作为LRU或LFU缓存,或为实例设置硬内存限制(使用“noeviction”策略)时,
# 此选项通常很有用。
#
# WARNING: If you have replicas attached to an instance with maxmemory on,
# the size of the output buffers needed to feed the replicas are subtracted
# from the used memory count, so that network problems / resyncs will
# not trigger a loop where keys are evicted, and in turn the output
# buffer of replicas is full with DELs of keys evicted triggering the deletion
# of more keys, and so forth until the database is completely emptied.
# 如果将副本附加到具有最大内存的实例上,从使用的内存计数中减去提供副本所需的输出缓冲区
# 的大小,这样,网络问题/重新同步不会触发关键被驱逐的循环,反过来,副本的输出缓冲区已
# 满,删除键的DEL会触发删除更多键,依此类推,直到数据库完全清空为止。
#
# In short... if you have replicas attached it is suggested that you set a lower
# limit for maxmemory so that there is some free RAM on the system for replica
# output buffers (but this is not needed if the policy is 'noeviction').
# 总之……
# 如果您附加了副本,建议您为maxmemory设置一个较低的限制,以便在系统上为副本输出缓冲区
# 提供一些空闲RAM(但如果策略是“noeviction”,则不需要这样做)。
#
# maxmemory <bytes>

# MAXMEMORY POLICY: how Redis will select what to remove when maxmemory
# is reached. You can select among five behaviors:
# MAXMEMORY POLICY: 当达到maxmemory时,Redis将选择删除什么。您可以选择以下五种行
# 为:
#
# volatile-lru -> Evict using approximated LRU among the keys with an expire set.
# volatile-lru -> 使用具有过期集的键之间的近似LRU进行驱逐。
# allkeys-lru -> Evict any key using approximated LRU.
# allkeys-lru -> 使用近似LRU退出任何键。
# volatile-lfu -> Evict using approximated LFU among the keys with an expire set.
# volatile-lfu -> 使用具有过期集的键之间的近似LFU进行驱逐。
# allkeys-lfu -> Evict any key using approximated LFU.
# allkeys-lfu -> 使用近似LFU驱逐任何键。
# volatile-random -> Remove a random key among the ones with an expire set.
# volatile-random -> 删除具有过期集的键之间的随机键。
# allkeys-random -> Remove a random key, any key.
# allkeys-random -> 删除任意一个随机键。
# volatile-ttl -> Remove the key with the nearest expire time (minor TTL)
# volatile-ttl -> 删除具有最近过期时间的键(较小的TTL)
# noeviction -> Don't evict anything, just return an error on write operations.
# noeviction -> 不要删除任何内容,只需在写操作上返回一个错误。
# LRU means Least Recently Used
# LRU的意思是最近最少使用
# LFU means Least Frequently Used
# LFU的意思是最不常用的
# Both LRU, LFU and volatile-ttl are implemented using approximated
# randomized algorithms.
# LRU、LFU和volatile-ttl均采用近似随机算法实现。
#
# Note: with any of the above policies, Redis will return an error on write
#       operations, when there are no suitable keys for eviction.
#
#       At the date of writing these commands are: set setnx setex append
#       incr decr rpush lpush rpushx lpushx linsert lset rpoplpush sadd
#       sinter sinterstore sunion sunionstore sdiff sdiffstore zadd zincrby
#       zunionstore zinterstore hset hsetnx hmset hincrby incrby decrby
#       getset mset msetnx exec sort
# 注意:对于上面的任何策略,当没有合适的键用于清除时,Redis将在写操作上返回一个错误。
# 在编写这些命令时:
# set setnx setex append
#       incr decr rpush lpush rpushx lpushx linsert lset rpoplpush sadd
#       sinter sinterstore sunion sunionstore sdiff sdiffstore zadd zincrby
#       zunionstore zinterstore hset hsetnx hmset hincrby incrby decrby
#       getset mset msetnx exec sort
# 
#
# The default is:
#
# maxmemory-policy noeviction

# LRU, LFU and minimal TTL algorithms are not precise algorithms but approximated
# algorithms (in order to save memory), so you can tune it for speed or
# accuracy. For default Redis will check five keys and pick the one that was
# used less recently, you can change the sample size using the following
# configuration directive.
# LRU、LFU和minimal TTL算法并不是精确的算法,而是近似的算法(为了节省内存),因此您可
# 以对其进行调优以获得速度或精度。默认情况下,Redis将检查五个键并选择最近使用较少的
# 键,您可以使用以下配置指令更改示例大小。
#
# The default of 5 produces good enough results. 10 Approximates very closely
# true LRU but costs more CPU. 3 is faster but not very accurate.
# 默认值5可以产生足够好的结果。10非常接近真实的LRU,但是需要更多的CPU。3更快,
# 但不是很准确。
#
# maxmemory-samples 5

# Starting from Redis 5, by default a replica will ignore its maxmemory setting
# (unless it is promoted to master after a failover or manually). It means
# that the eviction of keys will be just handled by the master, sending the
# DEL commands to the replica as keys evict in the master side.
# 从Redis 5开始,默认情况下,副本将忽略它的maxmemory设置(除非在故障转移后或手动将其
# 提升为master).这意味着键的清除将由主服务器来处理,当键在主服务器端被驱逐时,将DEL命
# 令发送给从服务器。
#
# This behavior ensures that masters and replicas stay consistent, and is usually
# what you want, however if your replica is writable, or you want the replica to have
# a different memory setting, and you are sure all the writes performed to the
# replica are idempotent, then you may change this default (but be sure to understand
# what you are doing).
# 此行为可确保主服务器和从服务器保持一致,并且通常是您所需的,但是如果您的从服务器是可
# 写的,或者您希望从务器具有不同的内存设置,并且您确信对从服务器执行的所有写操作都是幂
# 等的, 然后你可以改变这个默认值(但一定要明白你在做什么)。
#
# Note that since the replica by default does not evict, it may end using more
# memory than the one set via maxmemory (there are certain buffers that may
# be larger on the replica, or data structures may sometimes take more memory and so
# forth). So make sure you monitor your replicas and make sure they have enough
# memory to never hit a real out-of-memory condition before the master hits
# the configured maxmemory setting.
# 注意,由于默认情况下副本不会被删除,因此它可能最终使用的内存比通过maxmemory设置的
# 内存多(某些缓冲区在副本上可能更大,或者数据结构有时可能占用更多内存,等等)。
# 因此,请确保监视副本并确保它们有足够的内存,以便在主服务器达到配置的maxmemory设置
# 之前永远不会遇到真正的内存不足情况。

#
# replica-ignore-maxmemory yes

八、APPEND ONLY MODE 追加

appendonly no 是否开启aof

appendfilename “appendonly.aof” aof文件名

appendfsync
执行fynsc的策略
取值范围:
1 everysec 每秒执行sync 折衷方案
2 always 每次写操作都立刻写入到aof文件。慢,但是最安全
3 no 不要立刻刷,只有在操作系统需要刷的时候再刷。比较快
设置always往往比较影响性能,但是数据丢失的风险最低
一般推荐设置everysec

no-appendfsync-on-rewrite no 设置yes后,如果有保存的进程在执行,则不执行aof的appendfsync策略的fsync

auto-aof-rewrite-percentage
相对于上次aof文件大小的增长百分比如果超过这个值,则重写aof

auto-aof-rewrite-min-size
自动重写aof文件的最小大小,比 auto-aof-rewrite-percentage优先级高

aof-load-truncated
加入aof文件被截断了
1 设置yes,redis可以启动并且显示日志告知这个信息
2 设置no,redis启动失败,显示错误

aof-use-rdb-preamble
aof前部分用rdb,后面保存时缓存的命令还是用aof格式
优点:保存和恢复更快
设置yes开启


# 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).
# 默认情况下,Redis异步地将数据集转储到磁盘上。这种模式在许多应用程序中已经足够好了,
# 但是Redis进程或断电可能导致几分钟的写丢失(取决于配置的保存点)
# 
#
# 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.
# Append Only文件是另一种持久性模式,它提供了更好的持久性。例如,使用默认的数据fsync
# 策略(请参阅配置文件的后面部分)Redis在服务器断电之类的突发事件中只会损失一秒钟的写
# 操作,或者如果Redis进程本身发生了错误,但操作系统仍然正常运行,则只会损失一次写操
# 作。
#
# AOF and RDB persistence can be enabled at the same time without problems.
# 可以同时启用AOF和RDB持久性,不会出现任何问题。
# If the AOF is enabled on startup Redis will load the AOF, that is the file
# with the better durability guarantees.
# 如果在启动时启用了AOF,则Redis将加载AOF,这是具有更好持久性保证的文件
#
# Please check http://redis.io/topics/persistence for more information.

appendonly no

# The name of the append only file (default: "appendonly.aof")

appendfilename "appendonly.aof"

# The fsync() call tells the Operating System to actually write data on disk
# instead of waiting for more data in the output buffer. Some OS will really flush
# data on disk, some other OS will just try to do it ASAP.
# fsync()调用告诉操作系统实际在磁盘上写入数据,而不是在输出缓冲区中等待更多的数据。
# 一些操作系统会真正地刷新磁盘上的数据,而另一些操作系统只是试图尽快完成。
#
# Redis supports three different modes:
# Redis支持三种不同的模式:
#
# no: don't fsync, just let the OS flush the data when it wants. Faster.
# no:不用同步,只要让操作系统在需要的时候刷新数据即可。更快。
# always: fsync after every write to the append only log. Slow, Safest.
# always:每次写入仅追加日志后同步。缓慢的,安全的
# everysec: fsync only one time every second. Compromise.
# everysec:每秒只同步一次。折衷。
#
# The default is "everysec", as that's usually the right compromise between
# speed and data safety. It's up to you to understand if you can relax this to
# "no" that will let the operating system flush the output buffer when
# it wants, for better performances (but if you can live with the idea of
# some data loss consider the default persistence mode that's snapshotting),
# or on the contrary, use "always" that's very slow but a bit safer than
# everysec.
# 默认值是“everysec”,因为这通常是速度和数据安全性之间的正确折衷。
# 这取决于您是否可以将这个值放宽到“no”,以便操作系统在需要时刷新输出缓冲区,以获得更好
# 的性能(但是,如果您能够接受一些数据丢失的想法,请考虑默认的持久性模式,即快照),或
# 者相反,使用“always”,这是非常慢的,但比每秒钟都要安全一点。
#
# More details please check the following article:
# http://antirez.com/post/redis-persistence-demystified.html
#
# If unsure, use "everysec".
# 如果不确定,使用“everysec”。

# appendfsync always
appendfsync everysec
# appendfsync no

# When the AOF fsync policy is set to always or everysec, and a background
# saving process (a background save or AOF log background rewriting) is
# performing a lot of I/O against the disk, in some Linux configurations
# Redis may block too long on the fsync() call. Note that there is no fix for
# this currently, as even performing fsync in a different thread will block
# our synchronous write(2) call.
# 当AOF fsync策略被设置为always或everysec,并且后台保存进程(后台保存或AOF日志后台
# 重写)对磁盘执行大量I/O操作时,在某些Linux配置中,Redis可能会在fsync()调用上阻塞太
# 长时间。注意,目前还没有对此进行修复,因为即使在不同的线程中执行fsync也会阻塞我们的
# 同步write(2)调用。
#
# In order to mitigate this problem it's possible to use the following option
# that will prevent fsync() from being called in the main process while a
# BGSAVE or BGREWRITEAOF is in progress.
# 为了缓解这个问题,可以使用下面的选项来防止在执行BGSAVE或BGREWRITEAOF时在主进程中调
# 用fsync()。
#
# This means that while another child is saving, the durability of Redis is
# the same as "appendfsync none". In practical terms, this means that it is
# possible to lose up to 30 seconds of log in the worst scenario (with the
# default Linux settings).
# 这意味着当另外一个子进程正在保存时,Redis的持久性与“appendfsync none”相同。
# 实际上,这意味着在最坏的情况下可能会损失30秒的日志(使用默认的Linux设置)
#
# If you have latency problems turn this to "yes". Otherwise leave it as
# "no" that is the safest pick from the point of view of durability.
# 如果您有延迟问题,请将此选项变为“yes”。否则,从耐久性的角度来看,将其设置为“不”是最
# 安全的选择。

no-appendfsync-on-rewrite no

# Automatic rewrite of the append only file.
# 自动重写只追加文件
# Redis is able to automatically rewrite the log file implicitly calling
# BGREWRITEAOF when the AOF log size grows by the specified percentage.
# 当日志大小以指定的百分比增长时,Redis能够隐式调用BGREWRITEAOF自动重写日志文件
#
# This is how it works: Redis remembers the size of the AOF file after the
# latest rewrite (if no rewrite has happened since the restart, the size of
# the AOF at startup is used).
# 这就是它的工作原理:Redis记得最近一次重写后AOF文件的大小(如果重启后没有发生重写,则
# 使用启动时AOF的大小)
#
# This base size is compared to the current size. If the current size is
# bigger than the specified percentage, the rewrite is triggered. Also
# you need to specify a minimal size for the AOF file to be rewritten, this
# is useful to avoid rewriting the AOF file even if the percentage increase
# is reached but it is still pretty small.
# 这个基准大小和当前大小做比较。如果当前大小大于指定的百分比,则会触发重写。
# 此外,您还需要为要重写的AOF文件指定最小大小,这对于避免重写AOF文件很有用,即使达到了
# 增加的百分比,但仍然非常小。
#
# Specify a percentage of zero in order to disable the automatic AOF
# rewrite feature.
# 指定0的百分比,以禁用自动AOF重写特性

auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb

# An AOF file may be found to be truncated at the end during the Redis
# startup process, when the AOF data gets loaded back into memory.
# This may happen when the system where Redis is running
# crashes, especially when an ext4 filesystem is mounted without the
# data=ordered option (however this can't happen when Redis itself
# crashes or aborts but the operating system still works correctly).
# 在Redis启动过程的最后,当AOF数据加载回内存时,可能会发现AOF文件被截断。
# 当运行Redis的系统崩溃时可能会发生这种情况,特别是在没有data=ordered选项的情况下挂
# 载ext4文件系统时(然而,当Redis本身崩溃或中止时,这不会发生,但操作系统仍然正常工
# 作)
#
# Redis can either exit with an error when this happens, or load as much
# data as possible (the default now) and start if the AOF file is found
# to be truncated at the end. The following option controls this behavior.
# 发生这种情况时,Redis可以带着错误退出,或者加载尽可能多的数据,如果发现AOF文件在末尾
# 被截断,则可以启动。以下选项控制此行为。
#
# If aof-load-truncated is set to yes, a truncated AOF file is loaded and
# the Redis server starts emitting a log to inform the user of the event.
# Otherwise if the option is set to no, the server aborts with an error
# and refuses to start. When the option is set to no, the user requires
# to fix the AOF file using the "redis-check-aof" utility before to restart
# the server.
# 如果将AOF -load-truncated设置为yes,就会加载一个截短的AOF文件,并且Redis服务器
# 开始发出日志来通知用户该事件。否则,如果将该选项设置为no,服务器将以错误中止并拒绝启
# 动。当该选项设置为no时,用户需要在重启服务器之前使用“redis-check-aof”实用程序修复
# AOF文件。
#
# Note that if the AOF file will be found to be corrupted in the middle
# the server will still exit with an error. This option only applies when
# Redis will try to read more data from the AOF file but not enough bytes
# will be found.
# 注意,如果AOF文件在中间被破坏,服务器仍然会带着错误退出。这个选项只适用于当Redis试图
# 从AOF文件中读取更多数据,但没有找到足够的字节时。
aof-load-truncated yes

# When rewriting the AOF file, Redis is able to use an RDB preamble in the
# AOF file for faster rewrites and recoveries. When this option is turned
# on the rewritten AOF file is composed of two different stanzas:
# 当重写AOF文件时,Redis能够在AOF文件中使用RDB序言,以便更快地重写和恢复。启用此选项
# 后,重写的AOF文件由两个不同的节组成:
#
#   [RDB file][AOF tail]
#
# When loading Redis recognizes that the AOF file starts with the "REDIS"
# string and loads the prefixed RDB file, and continues loading the AOF
# tail.
# 当加载Redis时,识别出AOF文件以“Redis”字符串开始并加载前缀RDB文件,然后继续加载AOF
# 尾部。
aof-use-rdb-preamble yes

九、NETWORK 网络

bind 限定访问的主机地址。如果没有bind,就是任意ip地址都可以访问。 生产环境 下,需要写自己应用服务器的ip地址。

protected-mode 安全防护模式。如果没有指定bind指令,也没有配置密码,那么保 护模式就开启,只允许本机访问

port 端口号 默认是6379

timeout 超时时间。 默认永不超时

tcp-keepalive 对客户端的心跳检测间隔时间


# By default, if no "bind" configuration directive is specified, Redis listens
# for connections from all the network interfaces available on the server.
# 默认情况下,如果没有指定“bind”配置指令,Redis将侦听服务器上所有可用网络接口的连接。
# It is possible to listen to just one or multiple selected interfaces using
# the "bind" configuration directive, followed by one or more IP addresses.
# 可以使用“bind”配置指令监听一个或多个选定的接口,然后监听一个或多个IP地址。
#
# Examples:
#
# bind 192.168.1.100 10.0.0.1
# bind 127.0.0.1 ::1
#
# ~~~ WARNING ~~~ If the computer running Redis is directly exposed to the
# internet, binding to all the interfaces is dangerous and will expose the
# instance to everybody on the internet. So by default we uncomment the
# following bind directive, that will force Redis to listen only into
# the IPv4 loopback interface address (this means Redis will be able to
# accept connections only from clients running into the same computer it
# is running).
#
# IF YOU ARE SURE YOU WANT YOUR INSTANCE TO LISTEN TO ALL THE INTERFACES
# JUST COMMENT THE FOLLOWING LINE.
# 如果运行Redis的计算机直接暴露在internet上,绑定到所有接口是危险的,并且会将实例暴露
# 给internet上的所有人。因此,默认情况下,我们取消以下bind指令的注释,这将迫使Redis
# 只监听IPv4环回接口地址(这意味着Redis将只能接受运行在同一台计算机上的客户机的连
# 接)。
# 如果确定要实例侦听所有接口,只需注释以下行
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bind 127.0.0.1

# Protected mode is a layer of security protection, in order to avoid that
# Redis instances left open on the internet are accessed and exploited.
# 保护模式是一种安全保护层,为了避免在internet上打开的Redis实例被访问和利用。
#
# When protected mode is on and if:
# 当保护模式打开时,如果:
#
# 1) The server is not binding explicitly to a set of addresses using the
#    "bind" directive.
# 1) 服务器没有使用“bind”指令显式绑定到一组地址。
# 2) No password is configured.
# 2) 没有配置密码。
#
# The server only accepts connections from clients connecting from the
# IPv4 and IPv6 loopback addresses 127.0.0.1 and ::1, and from Unix domain
# sockets.
# 服务器只接受来自IPv4和IPv6环回地址127.0.0.1和::1的客户机连接,以及来自Unix域套
# 接字的连接。
#
# By default protected mode is enabled. You should disable it only if
# you are sure you want clients from other hosts to connect to Redis
# even if no authentication is configured, nor a specific set of interfaces
# are explicitly listed using the "bind" directive.
# 默认情况下启用了受保护模式。只有当您确定希望来自其他主机的客户机连接到Redis(即使没有
# 配置身份验证),或者使用“bind”指令显式列出一组特定的接口时,才应该禁用它
protected-mode yes

# Accept connections on the specified port, default is 6379 (IANA #815344).
# 接受指定端口上的连接,默认值为6379
# If port 0 is specified Redis will not listen on a TCP socket.
# 如果端口0被指定,Redis将不会监听TCP套接字。
port 6379

# TCP listen() backlog.
#
# In high requests-per-second environments you need an high backlog in order
# to avoid slow clients connections issues. Note that the Linux kernel
# will silently truncate it to the value of /proc/sys/net/core/somaxconn so
# make sure to raise both the value of somaxconn and tcp_max_syn_backlog
# in order to get the desired effect.
# 在每秒高请求的环境中,您需要高积压以避免缓慢的客户端连接问题.请注意,Linux内核将以静默方式将其截断为/ proc / sys / net / 
# core / somaxconn的值确保提高somaxconn和tcp_max_syn_backlog的值,以获得所需的效果。
tcp-backlog 511

# Unix socket.
#
# Specify the path for the Unix socket that will be used to listen for
# incoming connections. There is no default, so Redis will not listen
# on a unix socket when not specified.
# 指定用于侦听传入连接的Unix套接字的路径。没有默认值,所以在未指定时,Redis不会在unix套接字上侦听。
#
# unixsocket /tmp/redis.sock
# unixsocketperm 700

# Close the connection after a client is idle for N seconds (0 to disable)
# 在客户端空闲N秒后关闭连接(0表示禁用)
timeout 0

# TCP keepalive.
#
# If non-zero, use SO_KEEPALIVE to send TCP ACKs to clients in absence
# of communication. This is useful for two reasons:
# 如果非零,则使用SO_KEEPALIVE在没有通信的情况下向客户机发送TCP ack。这样做有两个原因:
#
# 1) Detect dead peers.
# 1)发现死去的同伴。
# 2) Take the connection alive from the point of view of network
#    equipment in the middle.
# 2)从中间网络设备的角度进行连接
#
# On Linux, the specified value (in seconds) is the period used to send ACKs.
# Note that to close the connection the double of the time is needed.
# On other kernels the period depends on the kernel configuration.
# 在Linux上,指定的值(以秒为单位)是用于发送ack的周期。
# 注意,要关闭连接,需要双倍的时间。
# 对于其他内核,周期取决于内核配置
#
# A reasonable value for this option is 300 seconds, which is the new
# Redis default starting with Redis 3.2.1.
# 这个选项的合理值是300秒,这是从Redis 3.2.1开始的新的Redis默认值。
tcp-keepalive 300

十、REDIS CLUSTER REDIS集群

cluster-enabled yes
是否开启集群配置。如果配置yes则开启集群功能,此redis实例作为集群的一个节点,否则,它是一个普通的单一的redis实例。

cluster-config-file nodes-6379.conf
虽然此配置的名字叫"集群配置文件",但是此配置文件不能人工编辑,它是集群节点自动维护的文件,主要用于记录集群中有哪些节点、他们的状态以及一些持久化参数等,方便在重启时恢复这些状态。通常是在收到请求之后这个文件就会被更新。

cluster-node-timeout 15000
这是集群中的节点能够失联的最大时间,超过这个时间,该节点就会被认为故障。如果主节点超过这个时间还是不可达,则用它的从节点将启动故障迁移,升级成主节点。注意,任何一个节点在这个时间之内如果还是没有连上大部分的主节点,则此节点将停止接收任何请求。一般设置为15秒即可。

cluster-slave-validity-factor 10
如果设置成0,则无论从节点与主节点失联多久,从节点都会尝试升级成主节点。如果设置成正数,则cluster-node-timeout乘以cluster-slave-validity-factor得到的时间,是从节点与主节点失联后,此从节点数据有效的最长时间,超过这个时间,从节点不会启动故障迁移。

cluster-migration-barrier 1
主节点需要的最小从节点数,只有达到这个数,主节点失败时,它从节点才会进行迁移。更详细介绍可以看本教程后面关于副本迁移到部分。

cluster-require-full-coverage yes
在部分key所在的节点不可用时,如果此参数设置为"yes"(默认值), 则整个集群停止接受操作;如果此参数设置为”no”,则集群依然为可达节点上的key提供读操作


# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# WARNING EXPERIMENTAL: Redis Cluster is considered to be stable code, however
# in order to mark it as "mature" we need to wait for a non trivial percentage
# of users to deploy it in production.
# WARNING EXPERIMENTAL: 尽管当前Redis Cluster代码已经稳定,但是为了将这部分代码水准标记为“mature”,
# 仍需要一批有分量的用户将该功能应用到生产环境。即Redis Cluster功能仍需要生产实践的考验。
# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#
# 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:
#正常情况下,启动的Redis实例为非集群模式。只有当节点配置成集群模式时才能成为集群节点。如需
#以集群模式启动,取消下述配置的注释即可
#
# cluster-enabled yes

# 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.
#每个集群节点都有一个集群配置文件。该文件不是用来让用户编辑,而是持久化集群信息。
# 该文件由集群节点创建并更新。每个Redis 集群节点都需要有唯一的集群配置文件。所以在同一系
#统创建的多个Redis实例需要确保不存在配置文件名相同的情况发生
#
# cluster-config-file nodes-6379.conf

# 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 multiple of the node timeout.
# 集群节点超时阈值用来作为节点不可达并被标记为失效状态的超时上限,单位是毫秒
#(millisecond)
# 大多数其他内部时间限制是节点超时的倍数
# 
# cluster-node-timeout 15000

# A replica of a failing master will avoid to start a failover if its data
# looks too old.
# 当主节点失效后,Redis避免让存储数据过旧的从节点发起故障转移
#
# 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:
# 没有简单的方式可以直接准确判定从节点的”data age”,可以通过下面两个方面的检测实现:
#
# 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.
# 1) 如果有多个从节点可以发起故障转移,可以让他们交换信息以选出数据状态最节点主节点的从节
# 点。从节点可以通过offset进行排名并通过该排名延迟发起故障转移的时机
# 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).
#    If the last interaction is too old, the replica will not try to failover
#    at all.
# 2) 每个独立的从节点计算最近一次与主节点交互的时间。这里的交互可以是最近一次PING、最近一
#次接收到来自主节点的命令(当主服务器依然是“连接”状态)、与主节点断开连接的时间(当复制链
#接已经down掉时)。如果最近一次与主节点的交互已经足够久远,那么这个从节点将放弃进行故障转
#移。
#
# The point "2" can be tuned by user. Specifically a replica will not perform
# the failover if, since the last interaction with the master, the time
# elapsed is greater than:
#
#   (node-timeout * replica-validity-factor) + repl-ping-replica-period
# 在2)中的时间阈值可以由用户设定。特别地,当从节点的最近一次与主节点的交互远大于(node-
#timeout * slave-validity-factor) + repl-ping-slave-period 时,这个从节点将不会
#执行故障转移
#
# So for example if node-timeout is 30 seconds, and the 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.
# 例如假设node-timeout为30秒,slave-validity-factor参数为10,repl-ping-slave-
#period 为10秒,当从节点距离最近一次与主节点的交互时间大于310秒(30*10+10)时,该从节点
#不能进行故障转移
#
# A large 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.
# 一个过大的从节点有效因子(slave-validity-factor)会允许存储过旧数据的从节点进行故障
# 转移,而一个过小的从节点有效因子将会妨碍集群选择从节点成为新的主节点。
#
# For maximum availability, it is possible to set the 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).
# 为了获得最大的可用性,可以将从节点有效因子(slave-validity-factor)赋值为0。也就是
# 说,从节点忽略距离最近一次与主节点交互的时间段,则是直接点尝试发起故障转移。(但是这种策# 略下,这些从节点仍会根据offset的排名来推迟发起故障转移的时间)
#
# Zero is the only value able to guarantee that when all the partitions heal
# the cluster will always be able to continue.
#从节点有效因子(slave-validity-factor)值为0是唯一可以保证网络分区消失后,集群仍继续
#工作的值
#
# cluster-replica-validity-factor 10

# 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. This number
# is the "migration barrier". 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.
# Redis集群支持将从节点迁移到孤立主节点(orphaned masters),没有可以工作从节点的主节
#点)。该功能减少了集群孤立主节点故障但没有可工作从节点进行故障转移的情况的发生。
# 从节点可以迁移到孤立主节点当且仅当原来的主节点的剩余可工作从节点个数大于等于指定的可工作
#从节点数。这个数称为从节点迁移屏蔽因子(migration barrier)。当迁移屏蔽因子设置为1时,
#当且仅当主节点拥有至少两个可工作的从节点才允许其中从节点迁移到孤立主节点(orphaned 
#masters)。该因子通常用来表明使用者需要为集群中的主节点配置从节点个数
#
# Default is 1 (replicas migrate only if their masters remain with at least
# one replica). To disable migration just set it to a very large value.
# A value of 0 can be set but is useful only for debugging and dangerous
# in production.
# 默认迁移屏蔽因子是1(从节点可以执行迁移当前仅当其主节点在该节点迁移后仍保有至少一个从节
#点)。如果想关闭该功能,只需将该参数设置成一个极大值即可。
# 允许将迁移屏蔽因子置零。这种行为仅在调试时有用,且在生产环境中存在极大风险。
#
# cluster-migration-barrier 1

# By default Redis Cluster nodes stop accepting queries if they detect there
# is at least an hash slot uncovered (no available node is serving it).
# This way if the cluster is partially down (for example a range of hash slots
# are no longer covered) all the cluster becomes, eventually, unavailable.
# It automatically returns available as soon as all the slots are covered again.
#
# However sometimes you want the subset of the cluster which is working,
# to continue to accept queries for the part of the key space that is still
# covered. In order to do so, just set the cluster-require-full-coverage
# option to no.
# 默认情况下,Redis集群将停止接收客户端请求(停止服务)当集群检测到存在哈希槽没有对应负责
#的节点。也就是说,如果集群部分down(如有一部分哈希槽没有对应的节点),整个集群最终将会不
#可用。(集群信息传播遵循最终一致性)
# 当所有的槽都再次有对应负责的节点后,集群将会自动再次可用。
# 但是有时希望即使集群只有部分槽有对应的节点,集群也能继续接受客户端请求并处理对应的键空
#间。为了达到上述目的,将ecluster-require-full-coverage 设置为“no”即可。
#
# cluster-require-full-coverage yes

# This option, when set to yes, prevents replicas from trying to failover its
# master during master failures. However the master can still perform a
# manual failover, if forced to do so.
#
# This is useful in different scenarios, especially in the case of multiple
# data center operations, where we want one side to never be promoted if not
# in the case of a total DC failure.
#如果将此选项设置为yes,则可以防止副本在主服务器发生故障时尝试对其主服务器进行故障转移。但#是,如果强制执行,主服务器仍然可以执行手动故障转移。
#这在不同的场景中都很有用,尤其是在多个数据中心操作的情况下,如果不是在完全DC故障的情况
#下,我们希望永远不要提升一侧
#
# cluster-replica-no-failover no

# In order to setup your cluster make sure to read the documentation
# available at http://redis.io web site.

【参考链接】
https://www.cnblogs.com/xuliangxing/p/7151685.html

https://wenku.baidu.com/view/f5212912fe00bed5b9f3f90f76c66137ef064f53.html?re=view

https://raw.githubusercontent.com/antirez/redis/5.0/redis.conf

http://www.cnblogs.com/ivictor/p/9749491.html

https://www.cnblogs.com/52php/p/6213343.html

英语水平有限,如果哪里有不恰当的地方,或者专业术语解释有误的地方请大家予以指正。

你可能感兴趣的:(Nosql,一起读书,nosql)