一、Redis目录结构
redis-server.exe:服务程序 redis-check-dump.exe:本地数据库检查 redis-check-aof.exe:更新日志检查 redis-benchmark.exe:性能测试
二、Redis配置文件
# Redis配置文件示例
# 单位注意事项:当需要内存大小时,可以指定为1k 5GB 4M等通常形式:
#
# 1k => 1000 bytes
# 1kb => 1024 bytes
# 1m => 1000000 bytes
# 1mb => 1024*1024 bytes
# 1g => 1000000000 bytes
# 1gb => 1024*1024*1024 bytes
#
# 单位是不区分大小写的,所以 1GB 1Gb 1gB 都是一样的。
################################## INCLUDES ###################################
# 在这里包含一个或多个其他配置文件。这是有用的,如果你有一个标准的模板,去所有的Redis服务器,但也需要自定义一些每个服务器的设置。
# Include文件可以包含其他文件,所以要明智地使用它。
#
# 注意选项“include”不会被admin或Redis Sentinel命令“CONFIG REWRITE”重写。
# 因为Redis总是使用最后处理的行作为配置指令的值,你最好把include放在这个文件的开头,以避免在运行时覆盖配置更改。
#
# 如果你想用include来覆盖配置选项,最好把include放在最后一行。
#
# include .\path\to\local.conf
# include c:\path\to\other.conf
################################## NETWORK #####################################
# 默认情况下,如果没有指定“bind”配置指令,Redis将监听来自服务器上所有可用网络接口的连接。使用“bind”配置指令,可以只监听一个或多个选定的接口,后面跟着一个或多个IP地址。
# 例子:
# bind 192.168.1.100 10.0.0.1
# bind 127.0.0.1 ::1
#
# ~~~ WARNING ~~~
# 如果运行Redis的计算机直接暴露在互联网上,绑定到所有接口是危险的,并且会将实例暴露给互联网上的每个人。
# 因此,默认情况下,我们取消注释下面的bind指令,这将强制Redis只监听IPv4回环接口地址(这意味着Redis将只能接受来自运行到同一台计算机的客户端的连接)。
# 如果您确定希望实例侦听所有接口,只注释下面一行。
bind 127.0.0.1
# 保护模式是一层安全保护,以避免互联网上开放的Redis实例被访问和利用。
# 当保护模式开启时,如果:
# 1)服务器没有使用“bind”指令显式绑定到一组地址。
# 2)未配置密码。
# 服务器只接受来自IPv4和IPv6环回地址127.0.0.1和::1以及Unix域套接字的客户端连接。
# 缺省情况下,启用保护模式。只有当你确定你想要其他主机的客户端连接到Redis,即使没有配置身份验证,也没有使用“bind”指令显式列出特定的接口集时,你才应该禁用它。
protected-mode yes
# 接受指定端口上的连接,默认值是6379 (IANA #815344)。
# 如果指定端口0,Redis将不监听TCP套接字。
port 6379
# TCP listen() backlog.
# 在每秒请求数高的环境中,您需要高并发的backlog,避免客户端连接缓慢的问题。
# 请注意,Linux内核将静默地将其截断为/proc/sys/net/core/somaxconn的值,因此请确保提高somaxconn和tcp_max_syn_backlog的值,以获得所需的效果。
tcp-backlog 511
# Unix socket.
# 指定将用于侦听传入连接的Unix套接字的路径。
# 没有默认值,所以当没有指定时,Redis将不会监听unix套接字。
# unixsocket /tmp/redis.sock
# unixsocketperm 700
# 在客户端空闲N秒(0为禁用)超时0后关闭连接
# TCP keepalive。
# 如果非零,使用SO_KEEPALIVE在没有通信的情况下向客户端发送TCP应答。这有两个有用的原因:
# 1)检测失效的对等体。
# 2)从中间网络设备的角度来看,连接是活的。
# 在Linux操作系统中,指定的值(以秒为单位)是发送ack的周期。请注意,要关闭连接需要两倍的时间。在其他内核上,周期取决于内核配置。
# 该选项的合理值是60秒。
tcp-keepalive 0
################################# GENERAL #####################################
# 默认情况下,Redis不作为守护进程运行。如果你需要,就说yes。注意,Redis会在/var/run/ Redis中写入一个pid文件。被daemon化时的Pid。WINDOWS系统不支持(window可以通过:redis-server --service-install redis.windows.conf --loglevel verbose 设置开启启动)
# 如果你从upstart或systemd运行Redis, Redis可以与你的监督树交互。
# 选项:
# supervised no - 无监督互动
# supervised upstart - 通过将Redis置于SIGSTOP模式向upstart发送信号
# supervised systemd - 通过写READY=1到$NOTIFY_SOCKET来通知systemd
# supervised auto - 根据UPSTART_JOB或NOTIFY_SOCKET环境变量检测upstart或systemd方法
# 注意:这些监督方法只表示“进程准备好了”。他们不允许持续的活动ping回你的主管。在WINDOWS上不支持
# 如果指定了pid文件,Redis会在启动时将其写入指定的位置并在退出时删除它。
# 当服务器运行非守护进程时,如果没有创建pid文件,则不创建pid文件在配置中指定。当服务器处于守护状态时,pid文件即使没有指定,也会使用#,默认为"/var/run/redis.pid"。
# 创建一个pid文件是最好的努力:如果Redis不能创建它,没有什么不好的事情发生,服务器将启动并正常运行。WINDOWS不支持pidfile /var/run/redis.pid
# 指定服务器的详细级别。这可以是:
# debug(大量信息,对开发/测试有用)
# verbose(许多很少有用的信息,但不像调试级别那样混乱)
# notice(稍微冗长,可能是您在生产环境中需要的)
# warning(只记录非常重要/关键的消息)
loglevel notice
# 指定日志文件名。'stdout'也可以用来强制Redis登录标准输出。
logfile ""
# 要启用日志到Windows EventLog,只需将'syslog-enabled'设置为yes,并可选择更新其他syslog参数以适应您的需要。
# 如果Redis作为Windows服务安装和启动,这将自动启用。
# syslog-enabled no
# 指定Windows应用程序日志中事件的源名称。
# syslog-ident redis
# 设置数据库的数量。默认数据库是db0,您可以使用select <dbid>在每个连接的基础上选择一个不同的数据库,其中dbid是0到'databases'-1之间的一个数字
databases 16
################################ SNAPSHOTTING ################################
#
# 将DB保存在磁盘上: save <seconds> <changes>
# 如果对DB进行了给定的秒数和给定的写操作,将保存DB。
# 在下面的例子中,行为将是保存:
# 在900秒(15分钟)后,如果至少有一个键被更改
# 在300秒(5分钟)后,如果至少有10个键被更改
# 60秒后,如果至少有10000个密钥被更改
# 注意:你可以通过注释掉所有的“save”行来完全禁用保存。
# 也可以通过添加一个带有单个空字符串参数的保存指令来删除所有先前配置的保存点(也表示禁用功能),如下例所示:
# save "" 完全注释掉save就可以禁用rdb持久化
save 900 1
save 300 10
save 60 10000
# 默认情况下,如果RDB快照被启用(至少一个保存点)并且最近的后台保存失败,Redis将停止接受写操作。
# 这将使用户意识到(以一种困难的方式)数据没有正确地保存在磁盘上,否则很可能没有人会注意到,并且会发生一些灾难。
# 如果后台保存进程重新开始工作,Redis将自动允许再次写入。
# 然而,如果你设置了适当的Redis服务器和持久化监控,你可能想要禁用这个功能,这样Redis即使在磁盘、权限等问题上也能正常工作。
stop-writes-on-bgsave-error yes
# 压缩字符串对象时使用LZF转储。rdb数据库? 默认设置为“是”,因为它几乎总是运行。
# 如果你想节省一些CPU在保存子设置为'no',但数据集可能会更大,如果你有可压缩的值或键。
rdbcompression yes
# 从RDB版本5开始,CRC64校验和被放在文件的末尾。
# 这使得格式更能抵抗损坏,但在保存和加载RDB文件时,有一个性能损失(大约10%),所以你可以禁用它以获得最大的性能。
# 在禁用校验和的情况下创建的RDB文件的校验和为零,这将告诉加载代码跳过检查。
rdbchecksum yes
# 转储数据库的文件名
dbfilename dump.rdb
# 工作目录。
# DB将被写入到这个目录中,使用上面使用'dbfilename'配置指令指定的文件名。
# 只追加文件也会在这个目录下创建。
# 注意,这里必须指定一个目录,而不是文件名。
dir ./
################################# REPLICATION #################################
# 主从复制。使用slaveof将一个Redis实例作为另一个Redis服务器的副本。关于Redis复制,有几件事需要尽快理解。
# 1)Redis复制是异步的,但是你可以配置一个主服务器,如果它看起来没有连接到至少给定数量的从服务器,它就会停止接受写操作。
# 2)如果复制链路丢失相对较短的时间,Redis从端可以执行与主端的部分重同步。您可能希望根据您的需要将复制积压大小(请参阅本文件的下一部分)配置为合理的值。
# 3)复制是自动的,不需要用户干预。在网络分区之后,从服务器会自动尝试重新连接到主服务器,并与主服务器重新同步。
# slaveof <masterip> <masterport>
# 如果主服务器受密码保护(使用下面的“requirepass”配置指令),则可以在启动复制同步进程之前告诉从服务器进行身份验证,否则主服务器将拒绝从服务器的请求。
# masterauth <master-password>
# 当从端与主端失去连接,或者当复制仍在进行时,从端可以采取两种不同的方式:
# 1)如果slave-server-stale-data设置为“yes”(默认值),slave仍然会回复客户端请求,可能会有过期的数据,或者如果这是第一次同步,数据集可能只是空的。
# 2)如果slave-server-stale-data被设置为no, slave会对INFO和SLAVEOF以外的所有类型的命令回复错误“SYNC with master in progress”。
slave-serve-stale-data yes
# 您可以将从实例配置为接受或不接受写。对从实例进行写操作可能有助于存储一些临时数据(因为写在从实例上的数据在与主实例重新同步后很容易被删除),但如果客户端由于配置错误而写入从实例,也可能导致问题。
# 因为Redis 2.6默认slave是只读的。
# 注意:只读从端不被设计为暴露给互联网上不受信任的客户端。它只是防止滥用实例的保护层。默认情况下,只读从服务器仍然输出所有管理命令,如CONFIG、DEBUG等。在一定程度上,您可以使用'rename-command'来跟踪所有管理/危险命令,从而提高只读从服务器的安全性。
slave-read-only yes
# 复制同步策略:磁盘或套接字。
# -------------------------------------------------------
# 警告:无磁盘复制目前处于试验阶段
# -------------------------------------------------------
# 如果新的从机和重新连接的从机不能继续复制过程,则需要执行所谓的“完全同步”。RDB文件从主服务器传输到从服务器。
# 传播可以通过两种不同的方式发生:
# 1)磁盘支持:Redis主服务器创建一个新进程,将RDB文件写入磁盘。随后,该文件由父进程逐步传输到从进程。
# 2)无磁盘:Redis主服务器创建一个新进程,直接将RDB文件写入从端套接字,根本不需要接触磁盘。
# 使用磁盘支持复制,当RDB文件生成时,只要当前生成RDB文件的子节点完成其工作,就可以将更多的从节点排队并使用RDB文件。而使用无磁盘复制时,一旦传输开始,到达的新从服务器将进入队列,并且在当前传输终止时将开始新的传输。
# 当使用无磁盘复制时,主服务器在开始传输之前等待一段可配置的时间(以秒为单位),希望有多个从服务器到达,并且可以并行传输。
# 对于慢速磁盘和快速(大带宽)网络,无磁盘复制效果更好。
repl-diskless-sync no
# 当启用无磁盘复制时,可以配置服务器等待的延迟,以便生成通过套接字将RDB传输到从服务器的子服务器。
# 这一点很重要,因为一旦传输开始,就不可能为到达的新slave提供服务,它们将排队等待下一个RDB传输,因此服务器等待延迟,以便让更多的slave到达。
# 延迟时间以秒为单位,缺省值为5秒。要完全禁用它,只需将其设置为0秒,传输将尽快开始。
repl-diskless-sync-delay 5
# 从服务器以预定义的时间间隔向服务器发送ping。可以使用repl_ping_slave_period选项更改此间隔。缺省值是10秒。
# repl-ping-slave-period 10
# 以下选项设置复制超时:
# 1)同步期间的批量传输I/O,从slave的角度来看。
# 2)从slave(数据,ping)的角度来看,Master超时。
# 3)从主站超时(REPLCONF ping)。
# 重要的是要确保这个值大于为repl-ping-slave-period指定的值,否则每次主服务器和从服务器之间的流量较低时都会检测到超时。
# repl-timeout 60
# 同步完成后在从端socket上禁用TCP_NODELAY?
# 果你选择“yes”,Redis将使用更少的TCP数据包和更少的带宽向slave发送数据。但是这会增加数据出现在从属端的延迟,对于使用默认配置的Linux内核,延迟可达40毫秒。
# 如果选择“no”,则从端出现数据的延迟将减少,但将使用更多带宽用于复制。
# 默认情况下,我们针对低延迟进行了优化,但在非常高的流量条件下,或者当主服务器和从服务器相距许多跳时,将此设置为“yes”可能是一个好主意。
repl-disable-tcp-nodelay no
# 设置复制积压大小。积压是一个缓冲区,用于在从服务器断开连接一段时间后积累从服务器数据,因此当从服务器想要再次重新连接时,通常不需要完全重新同步,但部分重新同步就足够了,只需传递从服务器断开连接时丢失的部分数据。
# 复制积压越大,从服务器断开连接的时间就越长,以后就能够执行部分重新同步。
# 只有在至少有一个从属连接时才分配积压。
# repl-backlog-size 1mb
# 当主服务器在一段时间内不再连接从服务器时,积压将被释放。下面的选项配置了释放积压缓冲区所需的秒数(从最后一个从服务器断开连接开始)。
# 值为0意味着永远不释放积压。
# repl-backlog-ttl 3600
# 从机优先级是Redis在INFO输出中发布的一个整数。Redis哨兵使用它来选择一个从,当主不再正常工作时,将其提升为主。
# 优先级较低的从机被认为更有利于升级,例如,如果有三个优先级为10、100、25的从机,哨兵会选择优先级为10的从机,这是最低的。
# 然而,一个特殊的优先级为0的从机不能扮演主从机的角色,所以一个优先级为0的从机将永远不会被Redis哨兵选中升级。
# 缺省情况下,优先级为100。
slave-priority 100
# 如果连接的从服务器少于N个,并且延迟小于或等于M秒,主服务器就有可能停止接受写操作。N个slave需要处于“online”状态。
# 以秒为单位的延迟(必须<=指定的值)是从从服务器接收到的最后一个ping开始计算的,该ping通常每秒发送一次。
# 此选项不能保证N个副本将接受写入,但是在没有足够的slave可用的情况下,会将丢失写入的暴露窗口限制为指定的秒数。
# 例如,需要至少3个slave且延迟<=10秒,使用:
# min-slaves-to-write 3
# min-slaves-max-lag 10
#
# 将其中一个设置为0将禁用该特性。
# 默认情况下,min-slaves-to-write设置为0(禁用特性),min-slaves-max-lag设置为10。
################################## SECURITY ###################################
# 要求客户端在处理任何其他命令之前发出AUTH <PASSWORD>。在您不相信其他人可以访问运行redis-server的主机的环境中,这可能很有用。
# 为了向后兼容,这个应该被注释掉,因为大多数人不需要auth(例如,他们运行自己的服务器)。
# 警告:由于Redis非常快,外部用户可以在一个好的盒子上每秒尝试15万个密码。这意味着你应该使用一个非常强大的密码,否则它将很容易被破解。
#
requirepass 123456
# 命令重命名。
# 在共享环境中,可以更改危险命令的名称。例如,CONFIG命令可能被重命名为难以猜测的东西,以便它仍然可用于内部使用的工具,但不可用于一般客户端。
#
# 例子:rename-command CONFIG b840fc02d524045429941cc15f59e41cb7be6c52
# 也可以通过将命令重命名为空字符串来完全终止命令:
# rename-command CONFIG ""
#
# 请注意,更改登录到AOF文件或传输到slave的命令的名称可能会导致问题。
################################### LIMITS ####################################
# 设置同时连接的最大客户端数。默认情况下,这个限制被设置为10000个客户端,但是如果Redis服务器不能配置进程文件限制来允许指定的限制,允许的最大客户端数量被设置为当前文件限制减去32(因为Redis保留了一些文件描述符供内部使用)。
# 一旦达到限制,Redis将关闭所有新连接,并发送错误“已达到的最大客户端数”。
# maxclients 10000
# 如果Redis被用作仅内存缓存而没有任何类型的持久化,那么后台AOF/RDB持久化使用的fork()机制是不必要的。作为优化,所有的持久化可以在Windows版本的Redis中关闭。这将把堆分配重定向到系统堆分配器,并禁用可能导致fork()操作的命令:BGSAVE和BGREWRITEAOF。
# 此标志不能与配置AOF和RDB操作的任何其他标志组合使用。
# persistence-available [(yes)|no]
# 不要使用超过指定字节数的内存。当达到内存限制时,Redis将根据选择的退出策略(参见maxmemory-policy)尝试删除键。
# 如果Redis不能根据策略删除键,或者如果策略设置为'noeviction', Redis将开始错误地回复需要更多内存的命令,如set, LPUSH等,并且将继续回复只读命令,如GET。
# 当使用Redis作为LRU缓存,或者为实例设置硬内存限制(使用'noeviction'策略)时,这个选项通常很有用。
# 警告:如果你有slave连接到一个实例,maxmemory打开,输出缓冲区的大小需要从使用的内存计数中减去,这样网络问题/重新同步就不会触发一个循环,键被驱逐,反过来,slave的输出缓冲区充满了被驱逐的键的del,触发删除更多的键,以此类推,直到数据库完全清空。
# 简而言之……如果您有附属,建议您为maxmemory设置一个较低的限制,以便系统上有一些空闲的RAM用于附属输出缓冲区(但如果策略是'noeviction',则不需要这样做)。
# 警告:如果达到堆限制,不设置maxmemory将导致Redis以内存不足异常终止。
#
# 注意:由于Redis使用系统分页文件来分配堆内存,因此Windows任务管理器或其他工具(如ProcessExplorer)显示的工作集内存使用情况并不总是准确的。
# 例如,在后台保存RDB或AOF文件之后,工作集值可能会显著下降。为了检查redis-server用于存储数据的内存的正确数量,可以使用INFO client命令(可以使用客户端redis-cli命令info查看)。INFO命令只显示用于存储redis数据的内存,而不显示Windows进程为满足自身需求而使用的额外内存。INFO命令未报告的额外内存量可以通过减去Windows任务管理器报告的峰值工作集和INFO命令报告的used_memory_peak来计算。
#
maxmemory 1GB
# maxmemory释义:定义最大可用物理内存。
# 案例:默认单位:bytes
# maxmemory 1048576
# maxmemory 1048576B
# maxmemory 1000KB
# maxmemory 100MB
# maxmemory 1GB
# maxmemory 1000K
# maxmemory 100M
# maxmemory 1G
# 默认
maxmemory-policy noeviction
# maxmemory-policy释义:配置redis的过期策略,具体可配置策略如下:
# noeviction: 不删除策略, 达到最大内存限制时, 如果需要更多内存, 直接返回错误信息。(默认值)
# allkeys-lru: 所有key通用; 优先删除最近最少使用(less recently used ,LRU) 的 key。
# volatile-lru: 只限于设置了 expire 的部分; 优先删除最近最少使用(less recently used ,LRU) 的 key。
# allkeys-random: 所有key通用; 随机删除一部分 key。
# volatile-random: 只限于设置了 expire 的部分; 随机删除一部分 key。
# volatile-ttl: 只限于设置了 expire 的部分; 优先删除剩余时间(time to live,TTL) 短的key。
# 注意:使用上述任何一种策略,当没有合适的键可以退出时,Redis将在写操作时返回错误。
## 额外补充 ##
# 定时过期:每个设置过期时间的key都需要创建一个定时器,到过期时间就会立即清除。该策略可以立即清除过期的数据,对内存很友好;但是会占用大量的CPU资源去处理过期的数据,从而影响缓存的响应时间和吞吐量。
# 惰性过期:只有当访问一个key时,才会判断该key是否已过期,过期则清除。该策略可以最大化地节省CPU资源,却对内存非常不友好。极端情况可能出现大量的过期key没有再次被访问,从而不会被清除,占用大量内存。
# 定期过期:每隔一定的时间,会扫描一定数量的数据库的expires字典中一定数量的key,并清除其中已过期的key。该策略是前两者的一个折中方案。通过调整定时扫描的时间间隔和每次扫描的限定耗时,可以在不同情况下使得CPU和内存资源达到最优的平衡效果。
# LRU和最小TTL算法不是精确算法,而是近似算法(为了节省内存),因此您可以对其进行调优以提高速度或准确性。
# 默认情况下,Redis会检查五个键,并选择最近使用较少的键,你可以使用以下配置指令更改样本大小。
# 默认值5可以产生足够好的结果。10非常接近真实的LRU,但需要更多的CPU。3是非常快,但不是很准确。
maxmemory-samples 5
############################## APPEND ONLY MODE ###############################
# 默认情况下,Redis将数据集异步转储到磁盘上。这种模式在许多应用程序中已经足够好了,但是(RDB方式)Redis进程的问题或停电可能会导致几分钟的写丢失(取决于配置的保存点)。
# 只追加文件是另一种持久性模式,提供了更好的持久性。
# 例如,使用默认的数据同步策略(见后面的配置文件),Redis可以在一个戏剧性的事件中只丢失一秒钟的写,比如服务器停电,或者如果Redis进程本身发生了错误,只丢失一次写,但操作系统仍然正常运行。
# AOF和RDB持久化可以同时启用而不会出现问题。如果在启动时启用AOF, Redis将加载AOF,这是具有更好的持久性保证的文件。
# 请登录http://redis.io/topics/persistence了解更多信息。
# AOF持久化开启与关闭
appendonly no
# 只追加文件的名称(默认:"appendonly.aof")
appendfilename "appendonly.aof"
# fsync()调用告诉操作系统实际写数据到磁盘上,而不是等待更多的数据在输出缓冲区中。有些操作系统真的会刷新磁盘上的数据,有些操作系统只是尝试尽快刷新。
# Redis支持三种不同的模式:
# no:不要fsync,让操作系统在需要的时候刷新数据。得更快。
# always:每次写入追加日志后进行fsync。缓慢的,安全的。
# everysec:每秒只同步一次。妥协。
# 默认值是“everysec”,因为这通常是速度和数据安全之间的正确折衷。这取决于您是否可以将其放宽为“no”,以便操作系统在需要时刷新输出缓冲区,以获得更好的性能(但如果您可以接受一些数据丢失的想法,请考虑默认的持久性模式,即快照),或者相反,使用“always”,这非常慢,但比everysec更安全。
# 更多细节请查看以下文章:http://antirez.com/post/redis-persistence-demystified.html
# 如果不确定,使用“everysec”。
# appendfsync always
appendfsync everysec
# appendfsync no
# 当AOF fsync策略设置为always或everysec时,后台保存进程(后台保存或AOF日志后台重写)正在对磁盘执行大量I/O,在某些Linux配置中,Redis可能会阻塞fsync()调用太长时间。
# 请注意,目前还没有解决这个问题,因为即使在不同的线程中执行fsync也会阻塞我们的同步写(2)调用。
# 为了缓解这个问题,可以使用以下选项来防止在BGSAVE或BGREWRITEAOF正在进行时在主进程中调用fsync()。
# 这意味着当另一个子线程正在保存时,Redis的持久性与“appendfsync no”相同。实际上,这意味着在最坏的情况下(使用默认的Linux设置)可能会丢失长达30秒的日志记录。
# 如果您有延迟问题,将此选项改为“yes”。否则,从耐用性的角度来看,这是最安全的选择。
no-appendfsync-on-rewrite no
# 自动重写只追加的文件。
# Redis能够自动重写日志文件隐式调用BGREWRITEAOF当AOF日志大小增长到指定的百分比。
# 它是这样工作的:Redis在最近一次重写后会记住AOF文件的大小(如果重启后没有发生重写,则使用启动时的AOF大小)。
# 这个基本大小与当前大小进行比较。如果当前大小大于指定的百分比,则触发重写。
# auto-aof-rewrite-percentage和auto-aof-rewrite-min-size是或的关系,满足一个即可重写
# 指定一个0的百分比,以禁用自动AOF重写功能。当为100是,下次重写的长度为本次x2
auto-aof-rewrite-percentage 100
# 您还需要指定要重写的AOF文件的最小大小,这对于避免重写AOF文件很有用,即使达到了百分比增加,但它仍然很小。
auto-aof-rewrite-min-size 64mb
# 在Redis启动过程结束时,当AOF数据被加载回内存时,可能会发现AOF文件被截断。
# 这可能发生在Redis运行的系统崩溃时,特别是当ext4文件系统挂载时没有data=ordered选项(但是这不会发生在Redis本身崩溃或中止,但操作系统仍然正常工作时)。
# 当这种情况发生时,Redis可以退出并出现错误(错误不在文件末尾),或者加载尽可能多的数据(现在是默认的),如果发现AOF文件在最后被截断(错误在文件末尾),则启动。
# 以下选项控制此行为:
# 如果aof-load-truncated设置为yes,则加载一个被截断的AOF文件(忽略最后出现的错误),并且Redis服务器开始发送日志以通知用户该事件。
# 否则,如果该选项被设置为no,服务器将以错误终止并拒绝启动。当该选项设置为no时,用户需要在重新启动服务器之前使用“redis-check-aof”实用程序修复AOF文件。
# 请注意,如果AOF文件在中间被发现损坏,服务器仍然会退出并出现错误。此选项仅适用于Redis将尝试从AOF文件读取更多数据,但没有找到足够的字节时。
aof-load-truncated yes
################################ LUA SCRIPTING ###############################
# Lua脚本的最大执行时间,以毫秒为单位。
# 如果达到最大执行时间,Redis将记录脚本在最大允许时间后仍在执行,并将开始回复带有错误的查询。
#
# 当长时间运行的脚本超过最大执行时间时,只有script KILL和SHUTDOWN NOSAVE命令可用。第一个可用于停止尚未调用写命令的脚本。第二种方法是在脚本已经发出写命令,但用户不想等待脚本自然终止的情况下关闭服务器的唯一方法。
# 将其设置为0或负值,以便无限制地执行而不发出警告。
lua-time-limit 5000
################################ REDIS CLUSTER ###############################
# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# 警告实验:Redis集群被认为是稳定的代码,但是为了将其标记为“成熟”,我们需要等待一定比例的用户将其部署到生产环境中。
# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#
# 正常的Redis实例不能成为Redis集群的一部分;只有作为集群节点启动的节点才可以。为了启动一个Redis实例作为集群节点,启用集群支持取消注释:
# cluster-enabled yes
# 每个集群节点都有一个集群配置文件。此文件不适合手工编辑。它由Redis节点创建和更新。每个Redis集群节点需要一个不同的集群配置文件。确保在同一系统中运行的实例没有重叠的集群配置文件名。
# cluster-config-file nodes-6379.conf
# 集群节点超时是节点不可达的毫秒数,它必须被认为处于故障状态。大多数其他内部时间限制是节点超时的倍数。
# cluster-node-timeout 15000
# 如果主服务器的从服务器的数据看起来太旧,它将避免启动故障转移。
# 对于slave来说,没有简单的方法可以精确测量其“data age”,因此执行以下两个检查:
# 1)如果有多个能够进行故障转移的从机,它们交换消息,以便尝试给具有最佳复制偏移量的从机提供优势(处理来自主机的更多数据)。从服务器将尝试通过偏移量获得它们的等级,并在故障转移开始时应用与它们的等级成比例的延迟。
# 2)每一个从节点计算与主节点最后一次交互的时间。这可以是收到的最后一个ping或命令(如果主服务器仍处于“已连接”状态),也可以是与主服务器断开连接后经过的时间(如果复制链接当前已断开)。如果最后一个交互太旧,从服务器根本不会尝试故障转移。
#
# 点“2”可由用户自行调整。特别是,如果从服务器与主服务器的最后一次交互后,经过的时间大于: (node-timeout * slave-validity-factor) + repl-ping-slave-period
。所以,如果node-timeout为30秒,slave-validity因子为10,并且假设默认的repl-ping-slave周期为10秒,那么如果从服务器无法与主服务器通信超过310秒,则从服务器将不会尝试进行故障转移。
# 较大的slave有效性因子可能允许数据太旧的slave进行主故障转移,而过小的值可能使集群根本无法选择slave。
# 为了获得最大的可用性,可以将slave-validity-factor设置为0,这意味着,无论它们最后一次与主服务器交互是在什么时候,从服务器将始终尝试对主服务器进行故障转移。(然而,他们总是尝试应用与他们的偏移等级成比例的延迟)。
# 零是唯一能够保证当所有分区愈合时集群始终能够继续运行的值。
# cluster-slave-validity-factor 10
# Cluster slaves are able to migrate to orphaned masters, that are masters that are left without working slaves.
# 这提高了集群抵抗故障的能力,否则,如果没有工作的slave,则无法在故障发生时进行故障转移。
#
# Slaves migrate to orphaned masters only if there are still at least a given number of other working slaves for their old master. This number is the "migration barrier". A migration barrier of 1 means that a slave will migrate only if there is at least 1 other working slave for its master and so forth. It usually reflects the number of slaves you want for every master in your cluster.
#
# Default is 1 (slaves migrate only if their masters remain with at least
# one slave). 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.
#
# 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.
#
# cluster-require-full-coverage yes
# In order to setup your cluster make sure to read the documentation
# available at http://redis.io web site.
################################## SLOW LOG ###################################
# The Redis Slow Log is a system to log queries that exceeded a specified
# execution time. The execution time does not include the I/O operations
# like talking with the client, sending the reply and so forth,
# but just the time needed to actually execute the command (this is the only
# stage of command execution where the thread is blocked and can not serve
# other requests in the meantime).
#
# You can configure the slow log with two parameters: one tells Redis
# what is the execution time, in microseconds, to exceed in order for the
# command to get logged, and the other parameter is the length of the
# slow log. When a new command is logged the oldest one is removed from the
# queue of logged commands.
# The following time is expressed in microseconds, so 1000000 is equivalent
# to one second. Note that a negative number disables the slow log, while
# a value of zero forces the logging of every command.
slowlog-log-slower-than 10000
# There is no limit to this length. Just be aware that it will consume memory.
# You can reclaim memory used by the slow log with SLOWLOG RESET.
slowlog-max-len 128
################################ LATENCY MONITOR ##############################
# The Redis latency monitoring subsystem samples different operations
# at runtime in order to collect data related to possible sources of
# latency of a Redis instance.
#
# Via the LATENCY command this information is available to the user that can
# print graphs and obtain reports.
#
# The system only logs operations that were performed in a time equal or
# greater than the amount of milliseconds specified via the
# latency-monitor-threshold configuration directive. When its value is set
# to zero, the latency monitor is turned off.
#
# By default latency monitoring is disabled since it is mostly not needed
# if you don't have latency issues, and collecting data has a performance
# impact, that while very small, can be measured under big load. Latency
# monitoring can easily be enabled at runtime using the command
# "CONFIG SET latency-monitor-threshold <milliseconds>" if needed.
latency-monitor-threshold 0
############################# EVENT NOTIFICATION ##############################
# Redis can notify Pub/Sub clients about events happening in the key space.
# This feature is documented at http://redis.io/topics/notifications
#
# For instance if keyspace events notification is enabled, and a client
# performs a DEL operation on key "foo" stored in the Database 0, two
# messages will be published via Pub/Sub:
#
# PUBLISH __keyspace@0__:foo del
# PUBLISH __keyevent@0__:del foo
#
# It is possible to select the events that Redis will notify among a set
# of classes. Every class is identified by a single character:
#
# K Keyspace events, published with __keyspace@<db>__ prefix.
# E Keyevent events, published with __keyevent@<db>__ prefix.
# g Generic commands (non-type specific) like DEL, EXPIRE, RENAME, ...
# $ String commands
# l List commands
# s Set commands
# h Hash commands
# z Sorted set commands
# x Expired events (events generated every time a key expires)
# e Evicted events (events generated when a key is evicted for maxmemory)
# A Alias for g$lshzxe, so that the "AKE" string means all the events.
#
# The "notify-keyspace-events" takes as argument a string that is composed
# of zero or multiple characters. The empty string means that notifications
# are disabled.
#
# Example: to enable list and generic events, from the point of view of the
# event name, use:
#
# notify-keyspace-events Elg
#
# Example 2: to get the stream of the expired keys subscribing to channel
# name __keyevent@0__:expired use:
#
# notify-keyspace-events Ex
#
# By default all notifications are disabled because most users don't need
# this feature and the feature has some overhead. Note that if you don't
# specify at least one of K or E, no events will be delivered.
notify-keyspace-events ""
############################### ADVANCED CONFIG ###############################
# Hashes are encoded using a memory efficient data structure when they have a
# small number of entries, and the biggest entry does not exceed a given
# threshold. These thresholds can be configured using the following directives.
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
# Lists are also encoded in a special way to save a lot of space.
# The number of entries allowed per internal list node can be specified
# as a fixed maximum size or a maximum number of elements.
# For a fixed maximum size, use -5 through -1, meaning:
# -5: max size: 64 Kb <-- not recommended for normal workloads
# -4: max size: 32 Kb <-- not recommended
# -3: max size: 16 Kb <-- probably not recommended
# -2: max size: 8 Kb <-- good
# -1: max size: 4 Kb <-- good
# Positive numbers mean store up to _exactly_ that number of elements
# per list node.
# The highest performing option is usually -2 (8 Kb size) or -1 (4 Kb size),
# but if your use case is unique, adjust the settings as necessary.
list-max-ziplist-size -2
# Lists may also be compressed.
# Compress depth is the number of quicklist ziplist nodes from *each* side of
# the list to *exclude* from compression. The head and tail of the list
# are always uncompressed for fast push/pop operations. Settings are:
# 0: disable all list compression
# 1: depth 1 means "don't start compressing until after 1 node into the list,
# going from either the head or tail"
# So: [head]->node->node->...->node->[tail]
# [head], [tail] will always be uncompressed; inner nodes will compress.
# 2: [head]->[next]->node->node->...->node->[prev]->[tail]
# 2 here means: don't compress head or head->next or tail->prev or tail,
# but compress all nodes between them.
# 3: [head]->[next]->[next]->node->node->...->node->[prev]->[prev]->[tail]
# etc.
list-compress-depth 0
# Sets have a special encoding in just one case: when a set is composed
# of just strings that happen to be integers in radix 10 in the range
# of 64 bit signed integers.
# The following configuration setting sets the limit in the size of the
# set in order to use this special memory saving encoding.
set-max-intset-entries 512
# Similarly to hashes and lists, sorted sets are also specially encoded in
# order to save a lot of space. This encoding is only used when the length and
# elements of a sorted set are below the following limits:
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
# HyperLogLog sparse representation bytes limit. The limit includes the
# 16 bytes header. When an HyperLogLog using the sparse representation crosses
# this limit, it is converted into the dense representation.
#
# A value greater than 16000 is totally useless, since at that point the
# dense representation is more memory efficient.
#
# The suggested value is ~ 3000 in order to have the benefits of
# the space efficient encoding without slowing down too much PFADD,
# which is O(N) with the sparse encoding. The value can be raised to
# ~ 10000 when CPU is not a concern, but space is, and the data set is
# composed of many HyperLogLogs with cardinality in the 0 - 15000 range.
hll-sparse-max-bytes 3000
# Active rehashing uses 1 millisecond every 100 milliseconds of CPU time in
# order to help rehashing the main Redis hash table (the one mapping top-level
# keys to values). The hash table implementation Redis uses (see dict.c)
# performs a lazy rehashing: the more operation you run into a hash table
# that is rehashing, the more rehashing "steps" are performed, so if the
# server is idle the rehashing is never complete and some more memory is used
# by the hash table.
#
# The default is to use this millisecond 10 times every second in order to
# actively rehash the main dictionaries, freeing memory when possible.
#
# If unsure:
# use "activerehashing no" if you have hard latency requirements and it is
# not a good thing in your environment that Redis can reply from time to time
# to queries with 2 milliseconds delay.
#
# use "activerehashing yes" if you don't have such hard requirements but
# want to free memory asap when possible.
activerehashing yes
# The client output buffer limits can be used to force disconnection of clients
# that are not reading data from the server fast enough for some reason (a
# common reason is that a Pub/Sub client can't consume messages as fast as the
# publisher can produce them).
#
# The limit can be set differently for the three different classes of clients:
#
# normal -> normal clients including MONITOR clients
# slave -> slave clients
# pubsub -> clients subscribed to at least one pubsub channel or pattern
#
# The syntax of every client-output-buffer-limit directive is the following:
#
# client-output-buffer-limit <class> <hard limit> <soft limit> <soft seconds>
#
# A client is immediately disconnected once the hard limit is reached, or if
# the soft limit is reached and remains reached for the specified number of
# seconds (continuously).
# So for instance if the hard limit is 32 megabytes and the soft limit is
# 16 megabytes / 10 seconds, the client will get disconnected immediately
# if the size of the output buffers reach 32 megabytes, but will also get
# disconnected if the client reaches 16 megabytes and continuously overcomes
# the limit for 10 seconds.
#
# By default normal clients are not limited because they don't receive data
# without asking (in a push way), but just after a request, so only
# asynchronous clients may create a scenario where data is requested faster
# than it can read.
#
# Instead there is a default limit for pubsub and slave clients, since
# subscribers and slaves receive data in a push fashion.
#
# Both the hard or the soft limit can be disabled by setting them to zero.
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit slave 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
# Redis调用内部函数来执行许多后台任务,比如及时关闭客户端的连接,清除从未被请求的过期键,等等。
# 不是所有的任务都以相同的频率执行,但是Redis根据指定的“hz”值检查任务是否执行。
# 设置定期删除的频率(即每秒运行多少次),默认“hz”设置为10。提高这个值会在Redis空闲的时候占用更多的CPU,但同时也会让Redis在同时有很多键到期的时候反应更快,并且可以更精确地处理超时。
# 范围在1到500之间,但是超过100的值通常不是一个好主意。大多数用户应该使用默认值10,只有在需要非常低延迟的环境中才将其提高到100。
hz 10
# When a child rewrites the AOF file, if the following option is enabled
# the file will be fsync-ed every 32 MB of data generated. This is useful
# in order to commit the file to the disk more incrementally and avoid
# big latency spikes.
aof-rewrite-incremental-fsync yes
################################## INCLUDES ###################################
# Include one or more other config files here. This is useful if you
# have a standard template that goes to all Redis server but also need
# to customize a few per-server settings. Include files can include
# other files, so use this wisely.
#
# include /path/to/local.conf
# include /path/to/other.conf
# 混合持久化:将 aof-use-rdb-preamble 选项设置为 yes,并且要同时启用 RDB 和 AOF 两种持久化。
浙公网安备 33010602011771号