redis配置文件redis.conf參數(shù)說明

# 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.
#Redis默認不是以守護進程的方式運行严沥,可以通過該配置項修改膨俐,使用yes啟用守護進程
daemonize no

# When running daemonized, Redis writes a pid file in /var/run/redis.pid by
# default. You can specify a custom pid file location here.
#當 Redis 以守護進程的方式運行的時候,Redis 默認會把 pid 文件放在/var/run/redis.pid
#可配置到其他地址炼蹦,當運行多個 redis 服務時凹髓,需要指定不同的 pid 文件和端口
pidfile /var/run/redis.pid

# Accept connections on the specified port, default is 6379.
# If port 0 is specified Redis will not listen on a TCP socket.
#端口
port 6379

# If you want you can bind a single interface, if the bind option is not
# specified all the interfaces will listen for incoming connections.
#指定Redis可接收請求的IP地址,不設置將處理所有請求,建議生產(chǎn)環(huán)境中設置
# bind 127.0.0.1

# Close the connection after a client is idle for N seconds (0 to disable)
#客戶端連接的超時時間,單位為秒,超時后會關閉連接
timeout 0

# Set server verbosity to 'debug'
# it 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)
#日志記錄等級村斟,4個可選值
loglevel notice

# Specify the log file name. Also 'stdout' 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
#配置 log 文件地址,默認打印在命令行終端的窗口上,也可設為/dev/null屏蔽日志抱完、
logfile stdout

# Set the number of databases. The default database is DB 0, you can select
# a different one on a per-connection basis using SELECT where
# dbid is a number between 0 and 'databases'-1
#設置數(shù)據(jù)庫的個數(shù),可以使用 SELECT 命令來切換數(shù)據(jù)庫贼陶。
databases 16

#
# Save the DB on disk:
#
#   save
#
#   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 at all commenting all the "save" lines.
#設置 Redis 進行數(shù)據(jù)庫鏡像的頻率。保存數(shù)據(jù)到disk的策略
#900秒之內(nèi)有1個keys發(fā)生變化時
#30秒之內(nèi)有10個keys發(fā)生變化時
#60秒之內(nèi)有10000個keys發(fā)生變化時
save 900 1
save 300 10
save 60 10000

# 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

# 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.
# 
# Also the Append Only File will be created inside this directory.
# 
# Note that you must specify a directory here, not a file name.
#數(shù)據(jù)庫鏡像備份的文件放置的路徑
#路徑跟文件名分開配置是因為 Redis 備份時,先會將當前數(shù)據(jù)庫的狀態(tài)寫入到一個臨時文件
#等備份完成時碉怔,再把該臨時文件替換為上面所指定的文件
#而臨時文件和上面所配置的備份文件都會放在這個指定的路徑當中
#默認值為 ./
dir /var/lib/redis/

# Master-Slave replication. Use slaveof to make a Redis instance a copy of
# another Redis server. Note that the configuration is local to the slave
# so for example it is possible to configure the slave to save the DB with a
# different interval, or to listen to another port, and so on.
#設置該數(shù)據(jù)庫為其他數(shù)據(jù)庫的從數(shù)據(jù)庫
#slaveof <masterip> <masterport> 當本機為從服務時烘贴,設置主服務的IP及端口
# slaveof

# 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.
#指定與主數(shù)據(jù)庫連接時需要的密碼驗證
#masterauth <master-password> 當本機為從服務時,設置主服務的連接密碼
# masterauth

# When a slave lost the 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 data 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丟失與master的連接時撮胧,或slave仍然在于master進行數(shù)據(jù)同步時(未與master保持一致)
#slave可有兩種方式來響應客戶端請求:
#1)如果 slave-serve-stale-data 設置成 'yes'(默認)桨踪,slave仍會響應客戶端請求,此時可能會有問題
#2)如果 slave-serve-stale-data 設置成 'no',slave會返回"SYNC with master in progress"錯誤信息芹啥,但 INFO 和SLAVEOF命令除外锻离。
slave-serve-stale-data yes

# Require clients to issue AUTH 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.
#設置客戶端連接后進行任何其他指定前需要使用的密碼
#redis速度相當快,一個外部用戶在一秒鐘進行150K次密碼嘗試墓怀,需指定強大的密碼來防止暴力破解
# requirepass foobared

# Set the max number of connected clients at the same time. By default there
# is no limit, and it's up to the number of file descriptors the Redis process
# is able to open. The special value '0' means no limits.
# Once the limit is reached Redis will close all the new connections sending
# an error 'max number of clients reached'.
#限制同時連接的客戶數(shù)量汽纠。
#當連接數(shù)超過這個值時,redis 將不再接收其他連接請求傀履,客戶端嘗試連接時將收到 error 信息
# maxclients 128

# Don't use more memory than the specified amount of bytes.
# When the memory limit is reached Redis will try to remove keys
# accordingly to the eviction policy selected (see maxmemmory-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
# an 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').
#設置redis能夠使用的最大內(nèi)存虱朵。
#達到最大內(nèi)存設置后,Redis會先嘗試清除已到期或即將到期的Key(設置過expire信息的key)
#在刪除時,按照過期時間進行刪除啤呼,最早將要被過期的key將最先被刪除
#如果已到期或即將到期的key刪光卧秘,仍進行set操作呢袱,那么將返回錯誤
#此時redis將不再接收寫請求,只接收get請求官扣。
#maxmemory的設置比較適合于把redis當作于類似memcached 的緩存來使用
# maxmemory <bytes>

# By default Redis asynchronously dumps the dataset on disk. If you can live
# with the idea that the latest records will be lost if something like a crash
# happens this is the preferred way to run Redis. If instead you care a lot
# about your data and don't want to that a single record can get lost you should
# enable the append only mode: when this mode is enabled Redis will append
# every write operation received in the file appendonly.aof. This file will
# be read on startup in order to rebuild the full dataset in memory.
#
# Note that you can have both the async dumps and the append only file if you
# like (you have to comment the "save" statements above to disable the dumps).
# Still if append only mode is enabled Redis will load the data from the
# log file at startup ignoring the dump.rdb file.
#
# IMPORTANT: Check the BGREWRITEAOF to check how to rewrite the append
# log file in background when it gets too big.
#redis 默認每次更新操作后會在后臺異步的把數(shù)據(jù)庫鏡像備份到磁盤,但該備份非常耗時羞福,且備份不宜太頻繁
#redis 同步數(shù)據(jù)文件是按上面save條件來同步的
#如果發(fā)生諸如拉閘限電惕蹄、拔插頭等狀況,那么將造成比較大范圍的數(shù)據(jù)丟失
#所以redis提供了另外一種更加高效的數(shù)據(jù)庫備份及災難恢復方式
#開啟append only 模式后,redis 將每一次寫操作請求都追加到appendonly.aof 文件中
#redis重新啟動時,會從該文件恢復出之前的狀態(tài)。
#但可能會造成 appendonly.aof 文件過大治专,所以redis支持BGREWRITEAOF 指令卖陵,對appendonly.aof重新整理
appendonly no

# The name of the append only file (default: "appendonly.aof")
##更新日志文件名,默認值為appendonly.aof
# appendfilename appendonly.aof

# The fsync() call tells the Operating System to actually write data on disk
# instead to wait 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 if one second passed since the last fsync. Compromise.
#
# The default is "everysec" 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 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.
#
# If unsure, use "everysec".
#設置對 appendonly.aof 文件進行同步的頻率
#always 表示每次有寫操作都進行同步,everysec 表示對寫操作進行累積,每秒同步一次张峰。
#no表示等操作系統(tǒng)進行數(shù)據(jù)緩存同步到磁盤泪蔫,都進行同步,everysec 表示對寫操作進行累積,每秒同步一次
# appendfsync always
appendfsync everysec
# appendfsync no

# Virtual Memory allows Redis to work with datasets bigger than the actual
# amount of RAM needed to hold the whole dataset in memory.
# In order to do so very used keys are taken in memory while the other keys
# are swapped into a swap file, similarly to what operating systems do
# with memory pages.
#
# To enable VM just set 'vm-enabled' to yes, and set the following three
# VM parameters accordingly to your needs.
#是否開啟虛擬內(nèi)存支持。
#redis 是一個內(nèi)存數(shù)據(jù)庫喘批,當內(nèi)存滿時,無法接收新的寫請求,所以在redis2.0后,提供了虛擬內(nèi)存的支持
#但需要注意的撩荣,redis 所有的key都會放在內(nèi)存中,在內(nèi)存不夠時,只把value 值放入交換區(qū)
#雖使用虛擬內(nèi)存饶深,但性能基本不受影響餐曹,需要注意的是要把vm-max-memory設置到足夠來放下所有的key
vm-enabled no
# vm-enabled yes

# This is the path of the Redis swap file. As you can guess, swap files
# can't be shared by different Redis instances, so make sure to use a swap
# file for every redis process you are running. Redis will complain if the
# swap file is already in use.
#
# The best kind of storage for the Redis swap file (that's accessed at random) 
# is a Solid State Disk (SSD).
#
# *** WARNING *** if you are using a shared hosting the default of putting
# the swap file under /tmp is not secure. Create a dir with access granted
# only to Redis user and configure Redis to create the swap file there.
#設置虛擬內(nèi)存的交換文件路徑,不可多個Redis實例共享
vm-swap-file /tmp/redis.swap

# vm-max-memory configures the VM to use at max the specified amount of
# RAM. Everything that deos not fit will be swapped on disk *if* possible, that
# is, if there is still enough contiguous space in the swap file.
#
# With vm-max-memory 0 the system will swap everything it can. Not a good
# default, just specify the max amount of RAM you can in bytes, but it's
# better to leave some margin. For instance specify an amount of RAM
# that's more or less between 60 and 80% of your free RAM.
#設置開啟虛擬內(nèi)存后,redis將使用的最大物理內(nèi)存大小敌厘。
#默認為0台猴,redis將把他所有能放到交換文件的都放到交換文件中,以盡量少的使用物理內(nèi)存
#即當vm-max-memory設置為0的時候,其實是所有value都存在于磁盤
#在生產(chǎn)環(huán)境下,需要根據(jù)實際情況設置該值,最好不要使用默認的 0
vm-max-memory 0

# Redis swap files is split into pages. An object can be saved using multiple
# contiguous pages, but pages can't be shared between different objects.
# So if your page is too big, small objects swapped out on disk will waste
# a lot of space. If you page is too small, there is less space in the swap
# file (assuming you configured the same number of total swap file pages).
#
# If you use a lot of small objects, use a page size of 64 or 32 bytes.
# If you use a lot of big objects, use a bigger page size.
# If unsure, use the default :)
#設置虛擬內(nèi)存的頁大小
如果 value 值比較大,如要在 value 中放置博客、新聞之類的所有文章內(nèi)容饱狂,就設大一點
vm-page-size 32

# Number of total memory pages in the swap file.
# Given that the page table (a bitmap of free/used pages) is taken in memory,
# every 8 pages on disk will consume 1 byte of RAM.
#
# The total swap size is vm-page-size * vm-pages
#
# With the default of 32-bytes memory pages and 134217728 pages Redis will
# use a 4 GB swap file, that will use 16 MB of RAM for the page table.
#
# It's better to use the smallest acceptable value for your application,
# but the default is large in order to work in most conditions.
#設置交換文件的總的 page 數(shù)量
#注意page table信息是放在物理內(nèi)存中曹步,每8個page 就會占據(jù)RAM中的 1 個 byte
#總的虛擬內(nèi)存大小 = vm-page-size * vm-pages
vm-pages 134217728

# Max number of VM I/O threads running at the same time.
# This threads are used to read/write data from/to swap file, since they
# also encode and decode objects from disk to memory or the reverse, a bigger
# number of threads can help with big objects even if they can't help with
# I/O itself as the physical device may not be able to couple with many
# reads/writes operations at the same time.
#
# The special value of 0 turn off threaded I/O and enables the blocking
# Virtual Memory implementation.
#設置 VM IO 同時使用的線程數(shù)量。
vm-max-threads 4

# Hashes are encoded in a special way (much more memory efficient) when they
# have at max a given numer of elements, and the biggest element does not
# exceed a given threshold. You can configure this limits with the following
# configuration directives.
#redis 2.0后引入了 hash 數(shù)據(jù)結構休讳。 
#hash 中包含超過指定元素個數(shù)并且最大的元素當沒有超過臨界時箭窜,hash 將以zipmap來存儲
#zipmap又稱為 small hash,可大大減少內(nèi)存的使用
hash-max-zipmap-entries 512
hash-max-zipmap-value 64

# 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 an hash table
# that is rhashing, 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
# active rehashing 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 form 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.
#是否重置Hash表
#設置成yes后redis將每100毫秒使用1毫秒CPU時間來對redis的hash表重新hash衍腥,可降低內(nèi)存的使用
#當使用場景有較為嚴格的實時性需求,不能接受Redis時不時的對請求有2毫秒的延遲的話磺樱,把這項配置為no。
#如果沒有這么嚴格的實時性要求,可以設置為 yes,以便能夠盡可能快的釋放內(nèi)存
activerehashing yes

Redis官方文檔對VM的使用提出了一些建議:
當key很小而value很大時,使用VM的效果會比較好.因為這樣節(jié)約的內(nèi)存比較大
當key不小時,可以考慮使用一些非常方法將很大的key變成很大的value,如可將key,value組合成一個新的value

最好使用linux ext3 等對稀疏文件支持比較好的文件系統(tǒng)保存你的swap文件
vm-max-threads參數(shù)可設置訪問swap文件的線程數(shù)婆咸,最好不要超過機器的核數(shù)竹捉;設置為0則所有對swap文件的操作都是串行的,可能會造成比較長時間的延遲,但是對數(shù)據(jù)完整性有很好的保證
redis數(shù)據(jù)存儲

redis的存儲分為內(nèi)存存儲尚骄、磁盤存儲和log文件三部分块差,配置文件中有三個參數(shù)對其進行配置。
save seconds updates倔丈,save配置憨闰,指出在多長時間內(nèi),有多少次更新操作需五,就將數(shù)據(jù)同步到數(shù)據(jù)文件鹉动。可多個條件配合宏邮,默認配置了三個條件泽示。

appendonly yes/no ,appendonly配置蜜氨,指出是否在每次更新操作后進行日志記錄械筛,如果不開啟,可能會在斷電時導致一段時間內(nèi)的數(shù)據(jù)丟失飒炎。因為redis本身同步數(shù)據(jù)文件是按上面的save條件來同步的埋哟,所以有的數(shù)據(jù)會在一段時間內(nèi)只存在于內(nèi)存中。

appendfsync no/always/everysec 郎汪,appendfsync配置赤赊,no表示等操作系統(tǒng)進行數(shù)據(jù)緩存同步到磁盤,always表示每次更新操作后手動調(diào)用fsync()將數(shù)據(jù)寫到磁盤怒竿,everysec表示每秒同步一次砍鸠。

總結

1k => 1000 bytes
1kb => 1024 bytes
1m => 1000000 bytes
1mb => 10241024 bytes
1g => 1000000000 bytes
1gb => 10241024*1024 bytes
Redis 配置中對單位的大小寫不敏感,1GB耕驰、1Gb和1gB都是相同的爷辱。由此也說明,Redis 只支持 bytes,不支持 bit 單位饭弓。
Redis 支持以 “includes” 的方式引入其他配置文件双饥,比如:
include/path/to/local.conf
include/path/to/other.conf
需要注意的是,假如多個一個配置項在不同配置文件中都有定義弟断,則以最后一行讀入的為準咏花,就是說后面的配置項會覆蓋前面的配置項。

1.1通用配置
默認情況下阀趴,Redis 并不是以 daemon 形式來運行的昏翰。通過 daemonize 配置項可以控制Redis的運行形式,如果改為 yes刘急,那么 Redis 就會以 daemon 形式運行:
daemonize no
當以 daemon 形式運行時棚菊,Redis 會生成一個 pid 文件,默認會生成在 /var/run/Redis.pid 叔汁。當然统求,可以通過 pidfile 來指定 pid 文件生成的位置,比如:
pidfile /path/to/Redis.pid
默認情況下据块,Redis 會響應本機所有可用網(wǎng)卡的連接請求码邻。當然,Redis 允許通過 bind 配置項來指定要綁定的IP另假,比如:
bind 192.168.1.2 10.8.4.2
Redis的默認服務端口是6379像屋,可以通過 port 配置項來修改。如果端口設置為0的話浪谴,Redis 便不會監(jiān)聽端口了开睡。
port 6379
可是因苹,如果Redis不監(jiān)聽端口苟耻,還怎么與外界通信呢?其實Redis還支持通過 unix socket 方式來接收請求扶檐⌒渍龋可以通過 unix socket 配置項來指定 unix socket 文件的路徑,并通過 unix socket perm 來指定文件的權限款筑。
unixsocket /tmp/Redis.sock
unixsocketperm 700

在高 QPS 的環(huán)境下需要提高 backlog 的值來避免 TCP 的慢連接問題智蝠。想要提高 backlog 的值,除了需要設置 Redis 的 tcp-backlog 奈梳,還要同時提高更改 Linux 的配置杈湾,否則,Linux內(nèi)核會默認將其截取為 /proc/sys/net/core/somaxconn 的大小攘须。
tcp-backlog 511
當一個 Redis-client 一直沒有請求發(fā)向 server 端漆撞,那么 server 端有權主動關閉這個連接,可以通過timeout 來設置“空閑超時時限”,0表示永不關閉浮驳。
timeout 0
TCP連接焙费矗活策略,可以通過 tcp-keepalive 配置項來進行設置至会,單位為秒离咐,假如設置為60秒,則 server 端會每60秒向連接空閑的客戶端發(fā)起一次 ACK 請求奉件,以檢查客戶端是否已經(jīng)掛掉宵蛀,對于無響應的客戶端則會關閉其連接。所以關閉一個連接最長需要120秒的時間县貌。如果設置為0糖埋,則不會進行保活檢測窃这。
tcp-keepalive 0
Redis支持通過 loglevel 配置項設置日志等級瞳别,共分四級,即 debug杭攻、verbose祟敛、notice、warning兆解。
loglevel notice
Redis也支持通過 logfile 配置項來設置日志文件的生成位置馆铁。如果設置為空字符串,則 Redis 會將日志輸出到標準輸出锅睛。假如在 daemon 情況下將日志設置為輸出到標準輸出埠巨,則日志會被寫到 /dev/null 中。
logfile ""
如果希望日志打印到 syslog 中现拒,也很容易辣垒,通過 syslog-enabled 來控制。另外印蔬,syslog-ident 還可以指定syslog 里的日志標志勋桶,比如:
syslog-ident Redis
而且還支持指定 syslog 設備,值可以是 USER 或 LOCAL0-LOCAL7 侥猬。具體可以參考 syslog 服務本身的用法例驹。
syslog-facility local0
對于 Redis 來說,可以設置其數(shù)據(jù)庫的總數(shù)量退唠,假如希望一個 Redis 包含16個數(shù)據(jù)庫鹃锈,那么設置如下:
databases 16
這16個數(shù)據(jù)庫的編號將是0到15。默認的數(shù)據(jù)庫是編號為0的數(shù)據(jù)庫瞧预。用戶可以使用 select <DBid> 來選擇相應的數(shù)據(jù)庫屎债。

1.2快照配置
快照寨蹋,主要涉及的是 Redis 的 RDB 持久化相關的配置。
可以用如下的指令來讓數(shù)據(jù)保存到磁盤上扔茅,即控制 RDB 快照功能:
save <seconds> <changes>
舉例來說:
save 900 1 //表示每15分鐘且至少有1個 key 改變已旧,就觸發(fā)一次持久化
save 300 10 //表示每5分鐘且至少有10個 key 改變,就觸發(fā)一次持久化
save 60 10000 //表示每60秒至少有10000個 key 改變召娜,就觸發(fā)一次持久化
如果想禁用 RDB 持久化的策略运褪,只要不設置任何 save 指令就可以,或者給 save 傳入一個空字符串參數(shù)也可以達到相同效果玖瘸,就像這樣:
save""
如果用戶開啟了 RDB 快照功能秸讹,那么在 Redis 持久化數(shù)據(jù)到磁盤時如果出現(xiàn)失敗,默認情況下雅倒,Redis 會停止接受所有的寫請求璃诀。這樣做的好處在于可以讓用戶很明確的知道內(nèi)存中的數(shù)據(jù)和磁盤上的數(shù)據(jù)已經(jīng)存在不一致了。如果 Redis 不顧這種不一致蔑匣,一意孤行的繼續(xù)接收寫請求劣欢,就可能會引起一些災難性的后果。
如果下一次 RDB 持久化成功裁良,Redis 會自動恢復接受寫請求凿将。
當然,如果不在乎這種數(shù)據(jù)不一致或者有其他的手段發(fā)現(xiàn)和控制這種不一致的話完全可以關閉這個功能价脾,以便在快照寫入失敗時牧抵,也能確保 Redis 繼續(xù)接受新的寫請求。配置項如下:
stop-writes-on-bgsave-error yes
對于存儲到磁盤中的快照侨把,可以設置是否進行壓縮存儲犀变。如果是的話,Redis 會采用 LZF 算法進行壓縮秋柄。如果不想消耗 CPU 來進行壓縮的話获枝,可以設置為關閉此功能,但是存儲在磁盤上的快照會比較大华匾。
rdbcompression yes
在存儲快照后映琳,我們還可以讓 Redis 使用 CRC64 算法來進行數(shù)據(jù)校驗,但是這樣做會增加大約10%的性能消耗蜘拉,如果希望獲取到最大的性能提升,可以關閉此功能有鹿。
rdbchecksum yes
我們還可以設置快照文件的名稱旭旭,默認是這樣配置的:
dbfilename dump.rdb
還可以設置這個快照文件存放的路徑。比如默認設置就是:
dir ./db/

1.3主從配置
Redis 提供了主從同步功能葱跋。
通過 slaveof 配置項可以控制某一個 Redis 作為另一個 Redis 的從服務器持寄,通過指定 IP 和端口來定位到主Redis 的位置源梭。一般情況下建議用戶為從 Redis 設置一個不同頻率的快照持久化的周期,或者為從 Redis 配置一個不同的服務端口等等稍味。
slaveof <masterip> <masterport>
如果主 Redis 設置了驗證密碼的話(使用 requirepass 來設置)废麻,則在從 Redis 的配置中要使用masterauth 來設置校驗密碼,否則的話模庐,主 Redis 會拒絕從 Redis 的訪問請求烛愧。
masterauth <master-password>
當從 Redis 失去了與主 Redis 的連接,或者主從同步正在進行中時掂碱, Redis 該如何處理外部發(fā)來的訪問請求呢怜姿?這里,從 Redis 可以有兩種選擇:
第一種選擇:如果 slave-serve-stale-data 設置為 yes (默認)疼燥,則從 Redis 仍會繼續(xù)響應客戶端的讀寫請求沧卢。
第二種選擇:如果 slave-serve-stale-data 設置為 no,則從 Redis 會對客戶端的請求返回 “SYNC with master inprogress” 醉者,當然也有例外但狭,當客戶端發(fā)來 INFO 請求和 SLAVEOF 請求,從 Redis 還是會進行處理撬即。
可以控制一個從 Redis 是否可以接受寫請求熟空。將數(shù)據(jù)直接寫入從 Redis ,一般只適用于那些生命周期非常短的數(shù)據(jù)搞莺,因為在主從同步時息罗,這些臨時數(shù)據(jù)就會被清理掉。自從 Redis2.6 版本之后才沧,默認從 Redis 為只讀迈喉。
slave-read-only yes
只讀的從 Redis 并不適合直接暴露給不可信的客戶端。為了盡量降低風險温圆,可以使用 rename-command指令來將一些可能有破壞力的命令重命名挨摸,避免外部直接調(diào)用。比如:
rename-command CONFIG b8c02d524045429941cc15f59e41cb7be6c52
從 Redis 會周期性的向主 Redis 發(fā)出 PING 包岁歉〉迷耍可以通過 repl_ping_slave_period 指令來控制其周期。默認是10秒锅移。
repl-ping-slave-period 10
在主從同步時熔掺,可能在這些情況下會有超時發(fā)生:
(1)以從 Redis 的角度來看,當有大規(guī)模 IO 傳輸時非剃。
(2)以從 Redis 的角度來看置逻,當數(shù)據(jù)傳輸或 PING 時,主 Redis 超時
(3)以主 Redis 的角度來看备绽,在回復從 Redis 的 PING 時券坞,從 Redis 超時
用戶可以設置上述超時的時限鬓催,不過要確保這個時限比 repl-ping-slave-period 的值要大宵呛,否則每次主Redis 都會認為從 Redis 超時弦悉。
repl-timeout 60
我們可以控制在主從同步時是否禁用 TCP_NODELAY 。如果開啟 TCP_NODELAY 碉京,那么主 Redis 會使用更少的 TCP 包和更少的帶寬來向從 Redis 傳輸數(shù)據(jù)猴伶。但是這可能會增加一些同步的延遲课舍,大概會達到40毫秒左右。如果關閉了 TCP_NODELAY 蜗顽,那么數(shù)據(jù)同步的延遲時間會降低布卡,但是會消耗更多的帶寬。
repl-disable-tcp-nodelay no
我們還可以設置同步隊列長度雇盖。隊列長度( backlog )是主 Redis 中的一個緩沖區(qū)忿等,在與從 Redis 斷開連接期間,主 Redis 會用這個緩沖區(qū)來緩存應該發(fā)給從 Redis 的數(shù)據(jù)崔挖。這樣的話贸街,當從 Redis 重新連接上之后,就不必重新全量同步數(shù)據(jù)狸相,只需要同步這部分增量數(shù)據(jù)即可薛匪。
repl-backlog-size 1mb
如果主 Redis 等了一段時間之后,還是無法連接到從 Redis 脓鹃,那么緩沖隊列中的數(shù)據(jù)將被清理掉逸尖。我們可以設置主 Redis 要等待的時間長度。如果設置為0瘸右,則表示永遠不清理娇跟。默認是1個小時。
repl-backlog-ttl 3600
我們可以給眾多的從 Redis 設置優(yōu)先級太颤,在主 Redis 持續(xù)工作不正常的情況苞俘,優(yōu)先級高的從 Redis 將會升級為主 Redis 。而編號越小龄章,優(yōu)先級越高吃谣。比如一個主 Redis 有三個從 Redis ,優(yōu)先級編號分別為10做裙、100岗憋、25,那么編號為10的從 Redis 將會被首先選中升級為主 Redis 菇用。當優(yōu)先級被設置為0時澜驮,這個從Redis 將永遠也不會被選中。默認的優(yōu)先級為100惋鸥。
slave-priority 100
假如主 Redis 發(fā)現(xiàn)有超過M個從 Redis 的連接延時大于N秒杂穷,那么主 Redis 就停止接受外來的寫請求。這是因為從 Redis 一般會每秒鐘都向主Redis發(fā)出PING卦绣,而主Redis會記錄每一個從 Redis 最近一次發(fā)來 PING 的時間點耐量,所以主 Redis 能夠了解每一個從 Redis 的運行情況。
min-slaves-to-write 3
min-slaves-max-lag 10
上面這個例子表示滤港,假如有大于等于3個從 Redis 的連接延遲大于10秒廊蜒,那么主 Redis 就不再接受外部的寫請求。上述兩個配置中有一個被置為0溅漾,則這個特性將被關閉山叮。默認情況下 min-slaves-to-write 為0,而 min-slaves-max-lag 為10添履。

1.4 安全配置
我們可以要求 Redis 客戶端在向 Redis-server 發(fā)送請求之前屁倔,先進行密碼驗證。由于 Redis 性能非常高暮胧,每秒鐘可以完成多達15萬次的密碼嘗試锐借,所以最好設置一個足夠復雜的密碼,否則很容易被黑客破解往衷。
requirepass chenlongfei
這里通過 requirepass 將密碼設置成我的名字钞翔。
Redis 允許我們對 Redis 指令進行更名,比如將一些比較危險的命令改個名字席舍,避免被誤執(zhí)行布轿。比如可以把 CONFIG 命令改成一個很復雜的名字,這樣可以避免外部的調(diào)用来颤,同時還可以滿足內(nèi)部調(diào)用的需要:
rename-command CONFIG b840fc02d5240454299c15f59e41cb7be6c89
我們甚至可以禁用掉 CONFIG 命令汰扭,那就是把 CONFIG 的名字改成一個空字符串:
rename-command CONFIG ""
但需要注意的是,如果使用 AOF 方式進行數(shù)據(jù)持久化脚曾,或者需要與從 Redis 進行通信东且,那么更改指令的名字可能會引起一些問題。

1.5 限制配置
我們可以設置 Redis 同時可以與多少個客戶端進行連接本讥。默認情況下為10000個客戶端珊泳。當無法設置進程文件句柄限制時, Redis 會設置為當前的文件句柄限制值減去32拷沸,因為 Redis 會為自身內(nèi)部處理邏輯留一些句柄出來色查。
如果達到了此限制, Redis 則會拒絕新的連接請求撞芍,并且向這些連接請求方發(fā)出 “max number of clients reached” 以作回應秧了。
maxclients 10000
我們甚至可以設置 Redis 可以使用的內(nèi)存量。一旦到達內(nèi)存使用上限序无, Redis 將會試圖移除內(nèi)部數(shù)據(jù)验毡,移除規(guī)則可以通過 maxmemory-policy 來指定衡创。
如果 Redis 無法根據(jù)移除規(guī)則來移除內(nèi)存中的數(shù)據(jù),或者我們設置了“不允許移除”晶通,那么 Redis 則會針對那些需要申請內(nèi)存的指令返回錯誤信息璃氢,比如 SET 、 LPUSH 等狮辽。但是對于無內(nèi)存申請的指令一也,仍然會正常響應,比如 GET 等喉脖。
maxmemory <bytes>
需要注意的一點是椰苟,如果 Redis 是主 Redis (說明 Redis 有從 Redis ),那么在設置內(nèi)存使用上限時树叽,需要在系統(tǒng)中留出一些內(nèi)存空間給同步隊列緩存舆蝴,只有在設置的是“不移除”的情況下,才不用考慮這個因素菱皆。
對于內(nèi)存移除規(guī)則來說须误, Redis 提供了多達6種的移除規(guī)則。他們是:
(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:不進行移除京痢。針對寫操作,只是返回錯誤信息
無論使用上述哪一種移除規(guī)則篷店,如果沒有合適的 key 可以移除的話祭椰, Redis 都會針對寫請求返回錯誤信息。
maxmemory-policy volatile-lru
LRU算法和最小TTL算法都并非是精確的算法疲陕,而是估算值方淤。所以可以設置樣本的大小。假如 Redis 默認會檢查三個 key 并選擇其中 LRU 的那個蹄殃,那么可以改變這個 key 樣本的數(shù)量携茂。
maxmemory-samples 3

1.6 AOF配置
默認情況下, Redis 會異步的將數(shù)據(jù)持久化到磁盤诅岩。這種模式在大部分應用程序中已被驗證是很有效的讳苦,但是在一些問題發(fā)生時,比如斷電吩谦,則這種機制可能會導致數(shù)分鐘的寫請求丟失鸳谜。
如上半部分中介紹的, AOF 是一種更好的保持數(shù)據(jù)一致性的方式式廷。即使當服務器斷電時咐扭,也僅會有1秒鐘的寫請求丟失,當 Redis 進程出現(xiàn)問題且操作系統(tǒng)運行正常時,甚至只會丟失一條寫請求蝗肪。
官方建議袜爪, AOF 機制和 RDB 機制可以同時使用,不會有任何沖突穗慕。
appendonly yes
我們還可以設置 AOF 文件的名稱:
appendfilename "appendonly.aof"
fsync()調(diào)用饿敲,用來告訴操作系統(tǒng)立即將緩存的指令寫入磁盤妻导。一些操作系統(tǒng)會“立即”進行逛绵,而另外一些操作系統(tǒng)則會“盡快”進行。
Redis支持三種不同的模式:
(1)no:不調(diào)用 fsync() 倔韭。而是讓操作系統(tǒng)自行決定 sync 的時間术浪。這種模式下, Redis 的性能會最快寿酌。
(2)always:在每次寫請求后都調(diào)用 fsync() 胰苏。這種模式下, Redis 會相對較慢醇疼,但數(shù)據(jù)最安全硕并。
(3)everysec:每秒鐘調(diào)用一次 fsync() 。這是性能和安全的折衷秧荆。
默認情況下為 everysec 倔毙。
appendfsync everysec
當 fsync 方式設置為 always 或 everysec 時,如果后臺持久化進程需要執(zhí)行一個很大的磁盤IO操作乙濒,那么 Redis 可能會在 fsync() 調(diào)用時卡住陕赃。目前尚未修復這個問題,這是因為即使我們在另一個新的線程中去執(zhí)行 fsync() 颁股,也會阻塞住同步寫調(diào)用么库。
為了緩解這個問題,我們可以使用下面的配置項甘有,這樣的話诉儒,當 BGSAVE 或 BGWRITEAOF 運行時, fsync() 在主進程中的調(diào)用會被阻止亏掀。這意味著當另一路進程正在對 AOF 文件進行重構時忱反, Redis 的持久化功能就失效了,就好像我們設置了 “appendsync none” 一樣幌氮。如果 Redis 有時延問題缭受,那么可以將下面的選項設置為yes。否則請保持no该互,因為這是保證數(shù)據(jù)完整性的最安全的選擇米者。
no-appendfsync-on-rewrite no
我們允許 Redis 自動重寫 aof 。當 aof 增長到一定規(guī)模時, Redis 會隱式調(diào)用 BGREWRITEAOF 來重寫log文件蔓搞,以縮減文件體積胰丁。
Redis 是這樣工作的: Redis 會記錄上次重寫時的 aof 大小。假如 Redis 自啟動至今還沒有進行過重寫喂分,那么啟動時 aof 文件的大小會被作為基準值锦庸。這個基準值會和當前的 aof 大小進行比較。如果當前 aof 大小超出所設置的增長比例蒲祈,則會觸發(fā)重寫甘萧。另外還需要設置一個最小大小,是為了防止在 aof 很小時就觸發(fā)重寫梆掸。
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
如果設置 auto-aof-rewrite-percentage 為0扬卷,則會關閉此重寫功能。
指Redis在恢復時酸钦,會忽略最后一條可能存在問題的指令怪得,默認值yes。即在 aof 寫入時卑硫,可能存在指令寫錯的問題(突然斷電徒恋,寫了一半),這種情況下欢伏,yes會log并繼續(xù)入挣,而no會直接恢復失敗。
aof-load-truncated yes

1.7 LUA腳本配置
lua 腳本的最大運行時間是需要被嚴格限制的颜懊,單位是毫秒:
lua-time-limit 5000
如果此值設置為0或負數(shù)财岔,則既不會有報錯也不會有時間限制。

1.8 集群設置
平常的 Redis 實例不能作為集群的節(jié)點河爹,只有作為集群節(jié)點啟動的實例才可以匠璧。下面的配置可以是 Redis 實例作為集群節(jié)點啟動:
cluster-enabled yes
每個集群節(jié)點都有一個集群配置文件,該文件是由集群節(jié)點來創(chuàng)建和維護的咸这,不能人工參與夷恍。每個集群節(jié)點需要不同的配置文件,所以需要保證同一個系統(tǒng)下的集群節(jié)點沒有重名的配置文件媳维,建議以端口號標記配置文件酿雪。
cluster-config-file nodes-6379.conf
當節(jié)點超時大于 cluster-node-timeout 的時候后,就會被認為宕機了侄刽,單位為毫秒指黎。
cluster-node-timeout 15000
Redis 集群有一種 failover (故障轉移)機制,即當主 Redis 宕機之后州丹,會有一個最合適的從 Redis 充當主 Redis 醋安。但是杂彭,當從 Redis 的數(shù)據(jù)“太老”了,與住 Redis 的標準數(shù)據(jù)偏差很大吓揪,為了保證數(shù)據(jù)一致性亲怠, Redis 會放棄 failover 。判別從 Redis 的的數(shù)據(jù)是不是“太老”有兩種方法:
(1)如果有多個從 Redis 可以接替主 Redis 的工作柠辞,則它們會交換信息团秽,選取“最佳復制偏移”(接受了原主 Redis 最多的數(shù)據(jù)同步)的從 Redis 作為下一任主 Redis 。
(2)每個從Redis計算與原主Redis最后一次數(shù)據(jù)同步的時間叭首,當最短的時間間隔大于某個臨界點的時候习勤,集群則放棄failover。
方法(2)當中的臨界點可以通過配置調(diào)節(jié)放棒,臨界點的計算規(guī)則為:
(node-timeout * slave-validity-factor)+ repl-ping-slave-period
如node-timeout為30秒姻报,slave-validity-factor為10秒,repl-ping-slave-period為10秒间螟,當與原主Redis最后一次對話的時間間隔超過310秒的時候,集群就會放棄failover损肛。
當slave-validity-factor太大會使一臺數(shù)據(jù)“太老”的從Redis充當主Redis厢破;而slave-validity-factor太小可能會造成找不到合適的從Redis繼任。
默認的slave-validity-factor為10治拿。
cluster-slave-validity-factor 10
考慮一種極端情況摩泪,集群有一臺主Redis和四臺從Redis,從Redis全部掛掉劫谅,failover機制有可能造成集群只有主Redis而無從Redis的尷尬境況见坑。為了保證集群的名副其實,可以規(guī)定捏检,當從Redis少于某個數(shù)量時荞驴,拒絕執(zhí)行failover。
cluster-migration-barrier 1
默認情況下贯城,當集群檢測到某個哈希槽(hash slot)沒有被覆蓋(沒有任何節(jié)點為此服務)會停止接受查詢服務熊楼,如果集群部分宕機最終會導致整個集群不可用,當哈希槽重新被全覆蓋的時候會自動變?yōu)榭捎媚芊浮H绻M切┕2郾桓采w的集群節(jié)點繼續(xù)接受查詢服務鲫骗,需要將cluster-require-full-coverage設置為no。
cluster-require-full-coverage yes

1.9 慢日志配置
Redis慢日志是指一個系統(tǒng)進行日志查詢超過了指定的時長踩晶。這個時長不包括IO操作执泰,比如與客戶端的交互、發(fā)送響應內(nèi)容等渡蜻,而僅包括實際執(zhí)行查詢命令的時間术吝。
針對慢日志可以設置兩個參數(shù),一個是執(zhí)行時長,單位是微秒顿苇,另一個是慢日志的長度峭咒。當一個新的命令被寫入日志時,最老的一條會從命令日志隊列中被移除纪岁。單位是微秒凑队,即1000000表示一秒。負數(shù)則會禁用慢日志功能幔翰,而0則表示強制記錄每一個命令漩氨。
slowlog-log-slower-than 10000
慢日志最大長度,可以隨便填寫數(shù)值遗增,沒有上限叫惊,但要注意它會消耗內(nèi)存∽鲂蓿可以使用SLOWLOG RESET來重設這個值霍狰。
slowlog-max-len 128

1.10 延遲監(jiān)控配置
Redis的延遲監(jiān)控子系統(tǒng)會在運行時對不同操作取樣,以此來收集與延遲相關的數(shù)據(jù)饰及,這些信息可以通過LATENCY命令以報表的形式呈現(xiàn)給用戶蔗坯。
系統(tǒng)只會記錄那些執(zhí)行時間等于或大于atency-monitor-threshold的操作,該值默認為0燎含,代表關閉監(jiān)控宾濒,因為收集延遲數(shù)據(jù)多少會影響Redis的性能。
latency-monitor-threshold 0

1.11事件通知配置
Redis可以向客戶端通知某些事件的發(fā)生屏箍。
例如绘梦,鍵空間(keyspace)時間通知如果開啟,一個客戶端對Database 0中的“foo”鍵執(zhí)行了DEL操作赴魁,兩條信息會通過Pub/Sub發(fā)布出去:
PUBLISH__keyspace@0__:foo del
PUBLISH__keyevent@0__:del foo
可以選擇需要發(fā)送哪種類型的通知卸奉,每種類型用一個字母代表:
K 鍵空間事件,發(fā)布到“keyspace@<db> prefix”頻道
E 鍵事件, 發(fā)布到“ keyevent@<db> prefix”頻道
g 通用事件,比如 DEL,EXPIRE, RENAME, ...等操作都屬于
$ String操作
l List操作
s Set操作
h Hash操作
z Sorted set操作
x 過期操作
e 驅逐操作(因為內(nèi)存不足數(shù)據(jù)被刪除)
A 代表“g$lshzxe”的組合, 所以“AKE”可以代表所有事件

notify-keyspace-events配置以上述的字母組合為參數(shù)尚粘,舉例說明:
(1)notify-keyspace-events Elg
當有List操作或通用操作择卦,發(fā)布通知到“ keyevent@<db> prefix”頻道
(2)notify-keyspace-events Ex
當有鍵的過期操作時,發(fā)布通知到“keyevent@0:expired”頻道
默認情況下郎嫁,notify-keyspace-events的參數(shù)為空字符串秉继,代表關閉通知。
notify-keyspace-events ""

1.12 高級配置
Hash 在條目數(shù)量較小的時候會使用一種高效的內(nèi)存數(shù)據(jù)結構編碼泽铛,當超過某個臨界點就會采用另一種存儲方式尚辑,該臨界點由下面的兩個配置決定:
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
與Hash類似,較小的List會以一種特殊的編碼方式來節(jié)省空間盔腔,只要List不超過下面的上限:
list-max-ziplist-entries 512
list-max-ziplist-value 64
Set只有在滿足下面的條件時才會采用特殊編碼方式:Set中存儲的恰好都是十進制的整數(shù)杠茬,而且長度不超過64位(有符號)月褥。數(shù)量上限為:
set-max-intset-entries 512
同樣,有序集合也會采用特殊編碼來節(jié)省空間瓢喉,只要不超過上限:
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
RedisHyperLogLog 是用來做基數(shù)統(tǒng)計的算法宁赤,HyperLogLog 的優(yōu)點是,在輸入元素的數(shù)量或者體積非常非常大時栓票,計算基數(shù)所需的空間總是固定并且很小的决左。當HyperLogLog用稀疏式表示法時所用內(nèi)存超過下面的限制,就會轉換成稠密式表示走贪,為了更高的內(nèi)存利用率佛猛,官方建議值為3000。
hll-sparse-max-bytes 3000
Redis 在每 100 毫秒時使用 1 毫秒的 CPU時間來對 Redis 的 hash 表進行重新 hash 坠狡。當使用場景中有非常嚴格的實時性需要继找,不能夠接受 Redis 時不時的對請求有 2 毫秒的延遲的話,把這項配置為 no 逃沿。
如果沒有這么嚴格的實時性要求婴渡,可以設置為 yes ,以便能夠盡可能快的釋放內(nèi)存感挥。
activerehashing yes
客戶端的輸出緩沖區(qū)的限制缩搅,因為某種原因客戶端從服務器讀取數(shù)據(jù)的速度不夠快,可用于強制斷開連接(一個常見的原因是一個發(fā)布 / 訂閱客戶端消費消息的速度無法趕上生產(chǎn)它們的速度)触幼。
可以三種不同客戶端的方式進行設置:
(1)normal -> 正常客戶端
(2)slave -> slave 和 MONITOR 客戶端
(3)pubsub -> 至少訂閱了一個 pubsub channel 或 pattern 的客戶端
每個client-output-buffer-limit 語法 :
client-output-buffer-limit<class> <hard limit> <soft limit> <soft seconds> 一旦達到硬限制客戶端會立即斷開究飞,或者達到軟限制并保持達成的指定秒數(shù)(連續(xù))置谦。
例如,如果硬限制為 32 兆字節(jié)和軟限制為 16 兆字節(jié) /10 秒亿傅,如果輸出緩沖區(qū)的大小達到 32 兆字節(jié)媒峡,客戶端將會立即斷開,客戶端達到 16 兆字節(jié)和連續(xù)超過了限制 10 秒葵擎,也將斷開連接谅阿。
默認 normal 客戶端不做限制,因為他們在一個請求后未要求時(以推的方式)不接收數(shù)據(jù)酬滤,只有異步客戶端可能會出現(xiàn)請求數(shù)據(jù)的速度比它可以讀取的速度快的場景签餐。
把硬限制和軟限制都設置為 0 來禁用該特性
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 會按照一定的頻率來執(zhí)行后臺任務,比如關閉超時的客戶端盯串,清除過期鍵等氯檐。不是所有的任務都會按照相同的頻率來執(zhí)行,但 Redis 依照指定的“ Hz ”值來執(zhí)行檢查任務体捏。
hz 10
aof rewrite 過程中冠摄,是否采取增量文件同步策略糯崎,默認為“yes”。 rewrite 過程中,每32M數(shù)據(jù)進行一次文件同步河泳,這樣可以減少 aof 大文件寫入對磁盤的操作次數(shù)沃呢。
aof-rewrite-incremental-fsync yes
最后編輯于
?著作權歸作者所有,轉載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市拆挥,隨后出現(xiàn)的幾起案子薄霜,更是在濱河造成了極大的恐慌,老刑警劉巖竿刁,帶你破解...
    沈念sama閱讀 222,183評論 6 516
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件黄锤,死亡現(xiàn)場離奇詭異,居然都是意外死亡食拜,警方通過查閱死者的電腦和手機鸵熟,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 94,850評論 3 399
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來负甸,“玉大人流强,你說我怎么就攤上這事∩氪” “怎么了打月?”我有些...
    開封第一講書人閱讀 168,766評論 0 361
  • 文/不壞的土叔 我叫張陵,是天一觀的道長蚕捉。 經(jīng)常有香客問我奏篙,道長,這世上最難降的妖魔是什么迫淹? 我笑而不...
    開封第一講書人閱讀 59,854評論 1 299
  • 正文 為了忘掉前任秘通,我火速辦了婚禮,結果婚禮上敛熬,老公的妹妹穿的比我還像新娘肺稀。我一直安慰自己,他們只是感情好应民,可當我...
    茶點故事閱讀 68,871評論 6 398
  • 文/花漫 我一把揭開白布话原。 她就那樣靜靜地躺著,像睡著了一般诲锹。 火紅的嫁衣襯著肌膚如雪繁仁。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 52,457評論 1 311
  • 那天辕狰,我揣著相機與錄音改备,去河邊找鬼。 笑死蔓倍,一個胖子當著我的面吹牛悬钳,可吹牛的內(nèi)容都是我干的盐捷。 我是一名探鬼主播,決...
    沈念sama閱讀 40,999評論 3 422
  • 文/蒼蘭香墨 我猛地睜開眼默勾,長吁一口氣:“原來是場噩夢啊……” “哼碉渡!你這毒婦竟也來了?” 一聲冷哼從身側響起母剥,我...
    開封第一講書人閱讀 39,914評論 0 277
  • 序言:老撾萬榮一對情侶失蹤滞诺,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后环疼,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體习霹,經(jīng)...
    沈念sama閱讀 46,465評論 1 319
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 38,543評論 3 342
  • 正文 我和宋清朗相戀三年炫隶,在試婚紗的時候發(fā)現(xiàn)自己被綠了淋叶。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 40,675評論 1 353
  • 序言:一個原本活蹦亂跳的男人離奇死亡伪阶,死狀恐怖煞檩,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情栅贴,我是刑警寧澤斟湃,帶...
    沈念sama閱讀 36,354評論 5 351
  • 正文 年R本政府宣布,位于F島的核電站檐薯,受9級特大地震影響凝赛,放射性物質發(fā)生泄漏。R本人自食惡果不足惜坛缕,卻給世界環(huán)境...
    茶點故事閱讀 42,029評論 3 335
  • 文/蒙蒙 一哄酝、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧祷膳,春花似錦、人聲如沸屡立。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,514評論 0 25
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽膨俐。三九已至勇皇,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間焚刺,已是汗流浹背敛摘。 一陣腳步聲響...
    開封第一講書人閱讀 33,616評論 1 274
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留乳愉,地道東北人兄淫。 一個月前我還...
    沈念sama閱讀 49,091評論 3 378
  • 正文 我出身青樓屯远,卻偏偏與公主長得像,于是被迫代替她去往敵國和親捕虽。 傳聞我的和親對象是個殘疾皇子慨丐,可洞房花燭夜當晚...
    茶點故事閱讀 45,685評論 2 360