Redis 5.0.3 配置文件详解(易读-白话翻译)-通用与RDB持久化

2021年11月21日 阅读数:13
这篇文章主要向大家介绍Redis 5.0.3 配置文件详解(易读-白话翻译)-通用与RDB持久化,主要内容包括基础应用、实用技巧、原理机制等方面,希望对大家有所帮助。

整个系列的目录: Redis 5.0.3 配置文件详解(易读-白话翻译)-目录    linux

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

# 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会以守护进程的方式运行,而且会在/var/run目录下生成一个redis.pid文件
daemonize no

# If you run Redis from upstart or systemd, Redis can interact with your
# supervision tree. Options:
#   supervised no      - no supervision interaction
#   supervised upstart - signal upstart by putting Redis into SIGSTOP mode
#   supervised systemd - signal systemd by writing READY=1 to $NOTIFY_SOCKET
#   supervised auto    - detect upstart or systemd method based on
#                        UPSTART_JOB or NOTIFY_SOCKET environment variables
# 使用Linux系统的upstart或者systemd两种方式来管理redis的启动,须要结合linux的版原本决定,centos7设置为systemd,而ubuntu设置为upstart
# Note: these supervision methods only signal "process is ready."
#       They do not enable continuous liveness pings back to your supervisor.
supervised no

# If a pid file is specified, Redis writes it where specified at startup
# and removes it at exit.
# 若是设置了pid文件,那么Redis启动时会写该pid文件到指定的目录下,退出时删除该pid文件
#
# 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".
# 若是redis是以守护进程方式运行的,若是没有指定"pidfile"的值,默认生成一个/var/run/redis.pid文件,不然使用指定的"pidfile"
# 若是redis是以非守护进程方式运行,若是没有指定"pidfile"的值,则不会产生pid file
#
# 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.
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)
# 指定Redis服务的详细日志级别,有debug\verbose\notice\warning四种级别,debug固然是不推荐的,日志太多了,除非有特殊状况,开发环境能够试试
loglevel notice

# 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
# 若是以非守护进程的方式运行,且没有指定"logfile",那么日志会发送到/dev/null(空文件),咱们没法经过它看到任何日志,但若是指定了"logfile",则输出到配置的文件当中
# 若是以守护进程的方式运行,且没有指定"logfile",那么日志会输出到标准输出(控制台),但若是指定了"logfile",则输出到配置的文件当中
logfile ""

# 如下3个(syslog-enabled/syslog-ident/syslog-facility)参数感受不须要关注,它们的目的就是将日志输出使用系统自带的logger,并且能够修改syslog的参数来实现本身特殊的需求
# 我本身没有去测试过,感受应该不多会用到,也许大企业专门负责Redis集群的会使用它来定制Redis的日志输出格式,而后使用程序来统计最后经过UI来展现
# To enable logging to the system logger, just set 'syslog-enabled' to yes,
# and optionally update the other syslog parameters to suit your needs.
# 若是要使用system logger,则将"syslog-enabled"设置为yes
# syslog-enabled no

# Specify the syslog identity.
# 指定syslog的id,应该是随便指定吧,起到惟一标识的做用???
# syslog-ident redis

# Specify the syslog facility. Must be USER or between LOCAL0-LOCAL7.
# 指定localxxx,须要配合/etc/rsyslog.conf文件使用,意思就是将日志文件输出导出到rsyslog.conf指定的文件中。若是开启了syslog-enable,也许本身指定的logfile就失效了,须要经过rsyslog.conf指定localxxx将日志导出指定的文件中
# syslog-facility local0

# 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
# 设置redis有多少个db,默认是16个,能够超过16,可是最大值是多少我也不知道。
# 客户端链接上服务器以后,能够经过"select databases-1"来选择使用的db,好比要使用第15个db,则使用"select 14"
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.
#
# 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.
# 是否启动的时候输出(显示)Redis的ASCII LOGO,这个没事就不要去动他了吧,看看也不错至少晓得它正在启动了
always-show-logo yes

################################ SNAPSHOTTING 持久化 ################################
# 下持久化有三种,RDB\AOF\RDB+AOF混合,简答提一下对应的实现原理
# RDB:将数据库以二进制存放在磁盘文件中,持久化的时间间隙比较大,丢失的数据比较多,单独只使用这种方式不推荐
# AOF:将操做数据库的指令(包括协议信息)以文本方式存放在磁盘文件中,根据配置最多会丢失1S的数据,这种方式还能够
# 混合:推荐这种方式,可是4.0开始才有此功能,混合持久化结合了RDB快速恢复数据和AOF丢失数据少的优势,并且减小了磁盘开销。。。关于它们更详细的介绍请查看
# Redis设计与实现-RDB持久化 https://my.oschina.net/u/3049601/blog/3153571
# Redis设计与实现-AOF持久化 https://my.oschina.net/u/3049601/blog/3153678
# Redis设计与实现-混合持久化 https://my.oschina.net/u/3049601/blog/3158904
#
# Save the DB on disk: 
# 保存DB到磁盘中
#   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
#   15分钟内至少有一个KEY改变了
#   after 300 sec (5 min) if at least 10 keys changed
#   5分钟内至少有10个KEY改变了
#   after 60 sec if at least 10000 keys changed
#   1分钟内至少有10000个KEY改变了
#
#   Note: you can disable saving completely by commenting out all "save" lines.
#
#   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 ""
#   若是想禁止RDB持久化,能够将下面的三个save配置项使用"#"注释掉。还可使用save ""来代替使用"#"来注释掉三个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.
# 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.
#
# 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.
# 若是RDB开启了且最近的BGSAVE失败了,那么Redis默认是不会再接收新增或者修改请求了,但若是BGSAVE又恢复工做,那么新增和修改操做能够继续(表示能够自动恢复)
# 若是公司有本身的监控系统能够很好的检测Redis服务和持久化状况,那么能够将此功能关闭,这样能够提升系统的可用性
# 若是使用集群,且从节点够的状况下有本身的监控,真的能够将这个功能关闭掉
stop-writes-on-bgsave-error yes

# Compress string objects using LZF when dump .rdb databases?
# For default that's set to 'yes' as it's almost always a win.
# 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.
# 默认会采用LZF压缩dump出来的数据库并写入到xxx.rdb文件中。压缩会增长CPU的开销,若是想节约CPU的开销,能够将"rdbcompression"设置为"no",可是会占用更多的磁盘
rdbcompression yes

# Since version 5 of RDB a CRC64 checksum is placed at the end of the file.
# 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.
# 从Redis5版本开始,默认在RDB文件末尾有一个CRC64(一个随机算法,生成信息指纹用的)校验和,它可让文件格式能够更强的抵抗风险,可是它会带来10左右的性能损失,咱们能够禁止它以得到最大的性能输出
#
# RDB files created with checksum disabled have a checksum of zero that will
# tell the loading code to skip the check.
# 若是禁用掉"checksum",那么生成的RDB文件结尾的校验和为"0",那么加载程序则会跳过校验
# 针对大企业(不差钱)我的以为就保留默认设置应该比较好
rdbchecksum yes

# The filename where to dump the DB
# 指定RDB文件的名字,建议使用ip+port来指定,运维能够更好的分辨,甚至能够经过程序扫描展现到UI上
dbfilename dump.rdb

# The working directory.
#
# The DB will be written inside this directory, with the filename specified
# above using the 'dbfilename' configuration directive.
#
# The Append Only File will also be created inside this directory.
#
# Note that you must specify a directory here, not a file name.
# 指定RDB和AOF文件的存储目录,注意:这里只能指定到目录,不要带文件名称
dir ./