redis 配置文件

自己看着注释,大概字面翻译的,有的地方可能不对 ;


我是在 Windows 下安装的 redis 配置文件和 Linux 有的地方不一样:


Units

# 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.

# 当内存大小需要使用的时候,才有能使用到单位 ;
# 单位,K 和 KB ,M 和 MB 不一样,一个麻瓜心中是整数,一个是魔法师心中的整数 ;
# 对大小写不敏感





Include

################################## 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.
#
# 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.
#
# 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 c:\path\to\other.conf

# 大概意思是说,redis 可以引入其他配置文件,使用 include 
# 那些需要给多个多个服务器使用,同时还想有一点自己的小想法的配置,就放在这里配置
# 配置的时候,注意 include 的位置,redis 会使用后面的 include 覆盖掉前面的 include 配置


General


################################# 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.
# NOT SUPPORTED ON WINDOWS daemonize no

# 
# 说默认redis 不是以守护进程运行的,需要自己去设置一下,但是在 Windows上默认是以守护进程运行的 ;


# 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
# Note: these supervision methods only signal "process is ready."
#       They do not enable continuous liveness pings back to your supervisor.
# NOT SUPPORTED ON WINDOWS supervised no

# If a pid file is specified, Redis writes it where specified at startup
# and removes it at exit.
#
# 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".
#
# 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.
# NOT SUPPORTED ON WINDOWS pidfile /var/run/redis.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

# 指定服务器日志级别,一般有上面的四个级别;



# Specify the log file name. Also 'stdout' can be used to force
# Redis to log on the standard output.
logfile "server_log.txt"

# 指定日志文件的名字,大概是说redis 通过标准输出流打印日志



# To enable logging to the Windows EventLog, just set 'syslog-enabled' to
# yes, and optionally update the other syslog parameters to suit your needs.
# If Redis is installed and launched as a Windows Service, this will
# automatically be enabled.
syslog-enabled yes


# 大概意思是说,为了确保日子可以出出发Windows的事件日志,将'syslog-enabled' 属性置为 "yes"
# 然后有选择的设置,你需要的参数 ;
# 如果 redis 被安装和启动为 Windows的一个服务,该属性默认为 yes ;





# Specify the source name of the events in the Windows Application log.
syslog-ident redis

# 日志输出到控制台的时候,前面的标识


# 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
databases 16

# 默认的数据库数量 ;
# 默认的是数据库是 0 下标的数据库,可以使用 "select dbid" 来切换数据库
# 数据库 id  从 0 到数据库数量-1 ,跟数组下标一个道理


Security


################################## 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.
#
# This should stay commented out for backward compatibility and because most
# people do not need auth (e.g. they run their own servers).
#
# 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.
#
# 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.
#
# 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 slaves may cause problems.



# 前半部分说的是, redis 可以设置密码,如果允许在一个你不确定的环境中,这样每次输入命令都需要输入密码;
# 为了保持向后兼容,还有大部分人的 redis 都运行在自己的服务器环境中,所有应该不设置密码 ;
# 还说了,密码应该设置的难一点,否则很容易被撞库破解,说 redis 很快,每秒可以接受150K 的密码尝试
# 依靠一个好的容器,大概是这个意思 ;


# 修改密码,使用 config set requirepass "密码字符串"  ;停用密码就将其设置为 "" ;
 

# 后面的意思大概是说,可以使用 "rename-command key newkey" 修改 命令的名字 
# 保证在一个不熟悉的环境中,有些危险命令只有你自己能使用 ;
# 但是这个操作,只对内部使用的工具有效,对一般的客户端是不奏效的 ;
# 同样可以使用该命令,让某个命令失效 ,只需要将新的名字设置为 "" ;

# 关于修改命令名字的操作,都会被记录到 AOF 文件中,或者传送给 从服务器
# 这一点需要注意,可能到导致一些问题

Limits


################################### LIMITS ####################################

# Set the max number of connected clients at the same time. By default
# this limit is set to 10000 clients, however if the Redis server is not
# able to configure the process file limit to allow for the specified limit
# the max number of allowed clients is set to the current file limit
# minus 32 (as Redis reserves a few file descriptors for internal uses).
#
# Once the limit is reached Redis will close all the new connections sending
# an error 'max number of clients reached'.
#
# maxclients 10000

# 设置同一时刻允许的最大连接数量
# 然后又大概说,如果 redis 服务器,不能读取这个配置文件的 limit ,
## 那么就会去使用它自己的一个什么文件,里面描述了 limit 大概是 32  ;(整的跟阅读理解是的。。。)

# 假如达到了最大限制,redis 会关闭所有新的连接,并回复一个 'max number of clients reached';


# If Redis is to be used as an in-memory-only cache without any kind of
# persistence, then the fork() mechanism used by the background AOF/RDB
# persistence is unnecessary. As an optimization, all persistence can be
# turned off in the Windows version of Redis. This will redirect heap
# allocations to the system heap allocator, and disable commands that would
# otherwise cause fork() operations: BGSAVE and BGREWRITEAOF.
# This flag may not be combined with any of the other flags that configure
# AOF and RDB operations.
# persistence-available [(yes)|no]

# Don't use more memory than 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).
#
# 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.
#
# This option is usually useful when using Redis as an LRU cache, or to set
# a hard memory limit for an instance (using the 'noeviction' policy).
#
# WARNING: If you have slaves attached to an instance with maxmemory on,
# the size of the output buffers needed to feed the slaves 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 slaves is full with DELs of keys evicted triggering the deletion
# of more keys, and so forth until the database is completely emptied.
#
# In short... if you have slaves attached it is suggested that you set a lower
# limit for maxmemory so that there is some free RAM on the system for slave
# output buffers (but this is not needed if the policy is 'noeviction').
#
# WARNING: not setting maxmemory will cause Redis to terminate with an
# out-of-memory exception if the heap limit is reached.
#
# NOTE: since Redis uses the system paging file to allocate the heap memory,
# the Working Set memory usage showed by the Windows Task Manager or by other
# tools such as ProcessExplorer will not always be accurate. For example, right
# after a background save of the RDB or the AOF files, the working set value
# may drop significantly. In order to check the correct amount of memory used
# by the redis-server to store the data, use the INFO client command. The INFO
# command shows only the memory used to store the redis data, not the extra
# memory used by the Windows process for its own requirements. Th3 extra amount
# of memory not reported by the INFO command can be calculated subtracting the
# Peak Working Set reported by the Windows Task Manager and the used_memory_peak
# reported by the INFO command.
#
# maxmemory <bytes>





# MAXMEMORY POLICY: how Redis will select what to remove when maxmemory
# is reached. You can select among five behaviors:
#
# volatile-lru -> remove the key with an expire set using an LRU algorithm
# allkeys-lru -> remove any key according to the LRU algorithm
# volatile-random -> remove a random key with an expire set
# allkeys-random -> remove a random key, any key
# volatile-ttl -> remove the key with the nearest expire time (minor TTL)
# noeviction -> don't expire at all, just return an error on write operations
#
# 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
#
# The default is:
#
# maxmemory-policy noeviction

# 最大缓存策略,也就是达到最大内存限制,redis 怎么做,一共有 5个选项 ;
# 默认是 noeviction ,内存满了,也不失效任何 key,只是报错 ;
# 其他五个,大概是说,内存满了
# "volatile-lru" :对设置了失效时间的 key ,使用 LRU 移除一部分 key
# "allkeys-lru" :对所有 key ,使用 LRU 移除一部分 key ;
# "volatile-random" :对设置了失效时间的 key,随机的移除一部分 key ;
# "allkeys-random" :对所有 key,随机的移除一部分 key ;
# "volatile-ttl" : 移除那些快要过期的 key ;





# LRU 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.
#
# The default of 5 produces good enough results. 10 Approximates very closely
# true LRU but costs a bit more CPU. 3 is very fast but not very accurate.
#
# maxmemory-samples 5


# 样本数量,每次在多少个 key 里面进行检查,选择移除最符合要求的那一个 ,默认是 5  ;
# 大概是说 LRU 和 TTL ,为了节省内存,都不是精确的算法,而是一种估算 
# 所以,你可以根据你的需求,是需要速度还是需要准确性,来设置样本大小;
# 给出建议, redis 默认是使用 5 作为样本大小,为了更精确,可以换成 10 ,为了更快,可以换成 3

SnapShotting

################################ SNAPSHOTTING  ################################
#
# 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
#
#   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 ""

save 900 1
save 300 10
save 60 10000

## 说 可以通过 save <seconds> <changes> 进行持久化,只要上面的两个参数的条件得到满足 ;
## 默认的配置是,900s有1key改动、300s有10个key改动、60s有10000个key改动 ;
## 如不想使用 ,则可以注释掉,或者 直接添加一个 save "" ;


# 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.
stop-writes-on-bgsave-error yes

## 就是说,redis 很厉害,如果在持久化的过程中,出现错误,它将不再接受往内存中写数据
## 它将会通知开发人员,数据可能已经不能继续持久化了,以杜绝没人发现这个情况
## 导致一些不可预知的问题发生;

## 如果子线程的问题解决了,redis  会自动的再次接受往内存中写数据的操作 ;

## 如果你自己有对 redis 进行检测,你自己可以处理这样的情况,在 持久化出错误时,
## 你自己能解决,你不希望 redis 停止工作,则设置为 no  ;






# 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.
rdbcompression yes

## 说,设置为 yes 以后,在进行备份的时候,会对字符串对象进行LZF压缩,
## 但是压缩会消耗 CPU 的性能,可以关闭,但是关闭以后,快照文件可能会非常大 ;
## 你自己看着办吧 ;




# 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.

## 说,自从 RDB的第五个版本开始,有一个 CRC64 检验,放在文本的末尾,这使得可以更能抵挡文本格式的损坏
## 但是需要消耗 10% 左右的性能,在保存和加载 RDB 文件的时候 ;
## 所以你可以关闭它,来获得最大的性能 ;

## 不建议关闭,性能损耗,通过升级硬件来解决 ;




# RDB files created with checksum disabled have a checksum of zero that will
# tell the loading code to skip the check.
rdbchecksum yes

## 说,在加载快照的时候,告诉 redis ,是否进行检验,没有校验的话,需要跳过检验码(没校验为0),




# 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.
#
# The Append Only File will also be created inside this directory.
#
# Note that you must specify a directory here, not a file name.
dir ./

## 指定 RDB 文件的保存路径,后面的 AOF 文件也存在这里 ;

## ./ 代表 redis 的安装路径


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).

--- 说 AOF 也是一种 redis 默认的持久化的方式;
--- 绝大多数情况下, AOF 已经表现的很不错了;
--- 除了在一些极端的情况下,比如 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.

--- 大概是 这个 AOF 是一个可供选择的持久性模式,它提供了很好的持久性 ;
--- 用了 AOF ,在默认的配置下,只会丢到一秒以内的写操作;


# 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.

--- 说 AOF 和 RDB 可以共存,但是当二者都存在的时候,默认选择加载 AOF 文件,
--- 因为 AOF 文件更全;

# Please check http://redis.io/topics/persistence for more information.

--- no 表示不使用 AOF , yes 代表使用 AOF,默认是不用的
appendonly no

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

--- 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.
#
# Redis supports three different modes:
#
# no: don't fsync, just let the OS flush the data when it wants. Faster.
# always: fsync after every write to the append only log. Slow, Safest.
# everysec: fsync only one time every second. Compromise.
#
# 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.
#
# More details please check the following article:
# http://antirez.com/post/redis-persistence-demystified.html
#
# If unsure, use "everysec".

# appendfsync always
appendfsync everysec
# appendfsync no

--- 前半部分大概是说,有一个 fsync() 方法,会告诉操作系统直接将数据往磁盘写,不要在继续等待缓存的数据了 ;
--- 一些操作系统针对 fsync() ,会真实的去刷新缓存,开始写数据,但是有一些,则只是尝试去做(ASAP) ;

--- 然后接着说,redis,有三种模式可供选择
--- no ,表示不同步,让操作系统自己想什么就什么时候,去刷新缓冲区,然后将进行对磁盘的写,这种效率最快
--- always ,每个写命令,都进行同步一次,最慢,但是最安全 ;
--- everysec ,每过一秒,才进行同步,同步这一秒之内发生的 写操作 ,效率和安全都能得到保证 ;

--- 默认是  everysec 


# 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.
#
# 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.
#
# 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).
#
# 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.
no-appendfsync-on-rewrite no

--- 大概是说,AOF 的 always 和 everysec 模式,都会导致 redis 在不停的使用 fsync() ,在某些 Linux 下面,
--- 会导致 redis 占对 fsync() 太久,导致 fsync()的回调失败,这个问题,至今没有得到正确的解决;

--- 为了缓解这情况,推荐使用  BGSAVE or BGREWRITEAOF  命令 ;

--- 上述问题的存在,其实也表示,有线程在进行保存操作的时候,比如 rewrite 
--- 这期间的 redis 其实是没有进行持久化的,直到占用 IO 的操作完成以后,才会继续进行持久化
--- 在Linux的默认配置下,最坏的情况会丢失 30s 的数据 ; 

--- 对于这个配置,如果你有延迟问题,则修改为yes,否则设置为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.

--- 表达的就是,当 AOF 文件超过指定大小,AOF 会进行自动的 rewriter 操作

# 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).

# 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.

# Specify a percentage of zero in order to disable the automatic AOF
# rewrite feature.
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb

--- 说 rewriter 的触发条件,redis 会记住上次 rewriter 的大小,如果从启动开始还没有进过 rewriter 
--- 则与启动时候的 rewriter 文件的大小为准 ;

--- 为了避免达到 rewriter 触发条件,但是 rewrite 文件的大小还很小,不需要进行 rewrite 操作
--- redis 还规定了最小 rewrite 的大小,默认是 64m



# 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 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.
#
# 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.
#
# 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-load-truncated yes

--- 没怎么看的=懂,大概说,AOF文件末尾可能会被截断,当 redis 出现问题的时候,比如发生错误强制退出等
--- 下次重启加载 AOF 的时候,发现 AOF 被截断,如果该属性被设置为 no ,则 redis 不会得到启动
--- 如果设置为 yes ,则 redis 会得到启动,但是会通知用户;

--- 对于设置为 no 的用户,需要使用 resistance-check-aof 工具,对 AOF 进行修复,然后再重启 redis ;



Replication

################################# REPLICATION #################################

# Master-Slave replication. Use slaveof to make a Redis instance a copy of
# another Redis server. A few things to understand ASAP about Redis replication.
#
# 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 slaves.
# 2) Redis slaves 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.
# 3) Replication is automatic and does not need user intervention. After a
#    network partition slaves automatically try to reconnect to masters
#    and resynchronize with them.
#
# slaveof <masterip> <masterport>

## 说主从复制,就是一台 redis 实例,对另外一台 redis 实例的复制。有几点关于 主从复制,需要尽快掌握

## 1、redis 的主从复制是异步的,但是你可以配置主机,使得其在所有从机都与它断开联系以后,停止接受写操作 ;
## 2、大概是说,redis 的从机如果和主机断开连接,在一个相当短的时间即重新连接上,
##    redis允许从机进行局部的再同步,不需要对整个数据进行再次的同步,
##    这个时间好像是取决于主机的一个储备区的大小,只要主要没有刷新过储备区数据,就允许你局部同步,
##    这个储备区大小视你需要而定 ;
## 3、在一个网络中的redis的主机和从机,从机是自动尝试连接主机并与其进行主从复制的,不需要人为的介入 ;



# If the master is password protected (using the "requirepass" configuration
# directive below) it is possible to tell the slave to authenticate before
# starting the replication synchronization process, otherwise the master will
# refuse the slave request.
#
# masterauth <master-password>

## 如果主机设置了访问密码,则需要告诉从机密码,没有密码,从机连接主机,主机是直接 refuse的;



# When a slave loses its connection with the master, or when the replication
# is still in progress, the slave can act in two different ways:
#
# 1) if slave-serve-stale-data is set to 'yes' (the default) the slave 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.
#
# 2) if slave-serve-stale-data is set to 'no' the slave will reply with
#    an error "SYNC with master in progress" to all the kind of commands
#    but to INFO and SLAVEOF.
#
slave-serve-stale-data yes


## 说如果从机与主机断开连接了,redis 一般有两种出来方式;
## 1、第一种是默认的,从机还是会响应客户端的请求,但是回应的数据,就不好说了,可能是过时的;
##    如果是在第一次进行同步的时候,就断开连接,则数据全是空;
## 2、如果将该配置置为 no ,则从机对除了 info  和 slave 命令以外的命令,
##	  都回复一个  "SYNC with master in progress" ;




# You can configure a slave instance to accept writes or not. Writing against
# a slave instance may be useful to store some ephemeral data (because data
# written on a slave 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 slaves are read-only.
#
# Note: read only slaves 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 slave 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 slaves using 'rename-command' to shadow all the
# administrative / dangerous commands.
slave-read-only yes

## 说,可以配置 redis 的从机是否可写,如果配置了可写,则从机可以保存一些短暂性的数据,因为从机保存的数据
## 在和主机进行了同步以后,就没了 ;如果错误的配置了可写,可能引起一些问题;

## 自从 2.6 版本开始,redis 默认从机是只读的,也就是不可写 ;

## 对从机进行只读配置,不是因为对客户端不信任,而是不想破坏掉主从分离,分离就好好分离 ;
## 下面说的好像是,对于只读的从机,那些管理命令,诸如 config、debug等等,也是可用的,为了更好的限制
## 从机,redis建议我们在 security  使用 'rename-command' 命令,把这些危险的命令隐藏掉 ;




# Replication SYNC strategy: disk or socket.
#
# -------------------------------------------------------
# WARNING: DISKLESS REPLICATION IS EXPERIMENTAL CURRENTLY
# -------------------------------------------------------
#
# New slaves and reconnecting slaves 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 slaves.
# The transmission can happen in two different ways:
#
# 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 slaves incrementally.
# 2) Diskless: The Redis master creates a new process that directly writes the
#              RDB file to slave sockets, without touching the disk at all.
#
# With disk-backed replication, while the RDB file is generated, more slaves
# 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 slaves arriving will be queued and a new transfer
# will start when the current one terminates.
#
# When diskless replication is used, the master waits a configurable amount of
# time (in seconds) before starting the transfer in the hope that multiple slaves
# will arrive and the transfer can be parallelized.
#
# With slow disks and fast (large bandwidth) networks, diskless replication
# works better.
repl-diskless-sync no

## 说redis开发一个实验性行的功能,主从复制,可以使用 磁盘,也可以走网络传播(实验性) ;
## 说新的从机或者重新连接的从机,都需要进行一次全量复制,全量复制用到的 RDB 文件,从主机传送到从机
## 现在有两种方法;
## 1、主机创建一个新的进程,对其内存中的数据进行备份到 RDB 文件里面,备份完事以后,
##    主机将这个文件递增的发给从机 ;
## 2、主机直接开启新的进程,将RDB文件直接通过socket写给从机,不经过磁盘 ;

## 通过磁盘的主从复制,只要子进程完成RDB文件的创建,从机就排队等着接受这个RDB文件
## 通过socket的主从复制,从机们也是排队等着,当前的传送完成,即开启新的传送 ;

## 当基于socket的传送被使用时,在开始传送之前,主机会等待一个时间按秒计算(在配置文件在进行配置)
## 希望在这个时间内,更多的从机连接上,然后并发的进行传送 RDB 文件 ;




# 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 slaves.
#
# This is important since once the transfer starts, it is not possible to serve
# new slaves arriving, that will be queued for the next RDB transfer, so the server
# waits a delay in order to let more slaves arrive.
#
# 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.
repl-diskless-sync-delay 5

## 说基于socket的主从复制,会等待一定的时间,为的是,期间更多的从机能连接过来,然后并发的进行传送 RDB 文件
## 一旦传送开始,主机就拒绝新的从机进行连接,直到传送完成以后,新的从机才可以连接成功;
## 该延迟默认是 5s,设置为 0 ,就表示不等待;


# Slaves send PINGs to server in a predefined interval. It's possible to change
# this interval with the repl_ping_slave_period option. The default value is 10
# seconds.
#
# repl-ping-slave-period 10

## 规定心跳检测的间隔 ,默认是 10 s


# The following option sets the replication timeout for:
#
# 1) Bulk transfer I/O during SYNC, from the point of view of slave.
# 2) Master timeout from the point of view of slaves (data, pings).
# 3) Slave timeout from the point of view of masters (REPLCONF ACK pings).
#
# It is important to make sure that this value is greater than the value
# specified for repl-ping-slave-period otherwise a timeout will be detected
# every time there is low traffic between the master and the slave.
#
# repl-timeout 60

## 超时时间,保证比上面的心跳检测的时间要大 ;

# Disable TCP_NODELAY on the slave socket after SYNC?
#
# If you select "yes" Redis will use a smaller number of TCP packets and
# less bandwidth to send data to slaves. But this can add a delay for
# the data to appear on the slave side, up to 40 milliseconds with
# Linux kernels using a default configuration.
#
# If you select "no" the delay for data to appear on the slave side will
# be reduced but more bandwidth will be used for replication.
#
# By default we optimize for low latency, but in very high traffic conditions
# or when the master and slaves are many hops away, turning this to "yes" may
# be a good idea.
repl-disable-tcp-nodelay no

## 默认是 no ,这样 redis 就会使用大的带宽,来保证从机接受数据的延迟变小;
## 如果置为 yes ,则 redis发送更小的数据包,占用更小的带宽,但是从机接受会有一个延迟
## ,在Linux的默认配置下,这个时间是 40 毫秒 ;

## Redis 说 默认情况下,它为了优化延迟,将其置为 no,但是如果你有许多台从机,
## 数据传输频繁,建议你置为  yes ;



# Set the replication backlog size. The backlog is a buffer that accumulates
# slave data when slaves are disconnected for some time, so that when a slave
# wants to reconnect again, often a full resync is not needed, but a partial
# resync is enough, just passing the portion of data the slave missed while
# disconnected.
#
# The bigger the replication backlog, the longer the time the slave can be
# disconnected and later be able to perform a partial resynchronization.
#
# The backlog is only allocated once there is at least a slave connected.
#
# repl-backlog-size 1mb

## 说有一个储备区,在主机上,当从机与主机断开连接以后,储备区就储备此刻以后的数据,当从机重新连接以后
## 一般是不需要进行全量复制的,只需要把储备区 数据拿过来就好了,前提是储备区没有被写满 ;
## 储备区越大,从机就可以断开连接越久 ;
## 至少有一个从机连接到主机,主机才会分配储备区 ;



# After a master has no longer connected slaves 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 slave disconnected, for
# the backlog buffer to be freed.
#
# A value of 0 means to never release the backlog.
#
# repl-backlog-ttl 3600

## 如果主机经过一段时间都没有从机连接上来,则储备区将被释放掉 ;
## 默认是 3600 s 




# The slave priority is an integer number published by Redis in the INFO output.
# It is used by Redis Sentinel in order to select a slave to promote into a
# master if the master is no longer working correctly.
#
# A slave with a low priority number is considered better for promotion, so
# for instance if there are three slaves with priority 10, 100, 25 Sentinel will
# pick the one with priority 10, that is the lowest.
#
# However a special priority of 0 marks the slave as not able to perform the
# role of master, so a slave with priority of 0 will never be selected by
# Redis Sentinel for promotion.
#
# By default the priority is 100.
slave-priority 100

## 每个从机都有一个代表优先权的数字,用于哨兵挑选新的主机,当主机不能正确工作以后 ;
## 数字越低,代表优先级越高,但是 0 除外,0 表永远也不会被选为主机 ;
## 默认是 100 





# It is possible for a master to stop accepting writes if there are less than
# N slaves connected, having a lag less or equal than M seconds.
#
# The N slaves need to be in "online" state.
#
# The lag in seconds, that must be <= the specified value, is calculated from
# the last ping received from the slave, that is usually sent every second.
#
# 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 slaves
# are available, to the specified number of seconds.
#
# For example to require at least 3 slaves with a lag <= 10 seconds use:
#
# min-slaves-to-write 3
# min-slaves-max-lag 10
#
# Setting one or the other to 0 disables the feature.
#
# By default min-slaves-to-write is set to 0 (feature disabled) and
# min-slaves-max-lag is set to 10.


## 说redis 可以设置 在一定时间内,必须至少有 N 台从机与主机相连,否则 主机就拒绝写 ;






posted @ 2018-12-06 11:28  Yiaz  阅读(227)  评论(0编辑  收藏  举报