文章目錄
- Redis 配置詳解
- 網絡
- 持久化
- 復制
- 安全
- 客戶端
- 內存管理
- 延遲釋放
- 僅追加模式
- LUA
- 集群
- 慢指令
- 延遲監控
- 事件通知
- 高級配置
- 主動碎片整理
Redis 配置詳解
網絡
########################## NETWORK ##########################
bind:指定 Redis 只接收來自于特定 IP 地址的請求,默認處理所有請求。
bind 127.0.0.1
protected-mode:是否開啟保護模式,默認開啟。
- protected-mode yes
port:Redis 監聽的端口號。
port 6379
tcp-backlog:確定 TCP 連接中已完成隊列的長度。
- tcp-backlog 511
timeout:客戶端空閑超時時間。
- timeout 0
tcp-keepalive:TCP 保持存活參數。
- tcp-keepalive 300
daemonize:是否在后臺執行。
- daemonize yes
pidfile:Redis 的進程文件。
- pidfile /var/run/redis/redis.pid
loglevel:指定服務端日志的級別。
- loglevel notice
logfile:指定記錄日志的文件。
- logfile /usr/local/redis/var/redis.log
databases:數據庫的數量。
databases 16
持久化
########################## SNAPSHOTTING ##########################
save:RDB 核心規則配置,指定時間間隔和更新操作次數來同步數據到硬盤。
save 900
save 300 10
save 60 10000
stop-writes-on-bgsave-error:RDB 持久化出現錯誤后的處理方式。
stop-writes-on-bgsave-error yes
rdbcompression:存儲至本地數據庫時是否壓縮數據。
- rdbcompression yes
rdbchecksum:是否校驗 rdb 文件。
rdbchecksum yes
dbfilename:指定本地數據庫文件名。
- dbfilename dump.rdb
dir:數據目錄。
dir /usr/local/redis/var
復制
########################## REPLICATION ##########################
replica-serve-stale-data:從庫與主機失去連接或復制進行時的運行方式。
- replica-serve-stale-data yes
replica-read-only:從服務器是否只讀。
- replica-read-only yes
repl-diskless-sync:是否使用 socket 方式復制數據。
- repl-diskless-sync no
repl-diskless-sync-delay:diskless 復制的延遲時間。
- repl-diskless-sync-delay 5
repl-ping-slave-period:從庫向服務器發送 ping 請求的時間間隔。
- repl-ping-slave-period 10
repl-timeout:復制連接超時時間。
- repl-timeout 60
repl-disable-tcp-nodelay:是否禁止復制 tcp 鏈接的 tcp nodelay 參數。
- repl-disable-tcp-nodelay no
repl-backlog-size:復制緩沖區大小。
- repl-backlog-size 1mb
repl-backlog-ttl:master 沒有 slave 時釋放復制緩沖區內存的時間長度。
- repl-backlog-ttl 3600
replica-priority:當 master 不可用時,選舉 slave 為 master 的優先級。
- replica-priority 100
min-replicas-to-write:master 最少需要的健康 slave 個數才能執行寫命令。
- min-replicas-to-write 3
min-replicas-max-lag:健康 slave 的延遲判斷標準。
min-replicas-max-lag 10
安全
########################## SECURITY ##########################
requirepass:配置認證密碼。
- requirepass foobared
rename-command:修改危險命令的名稱或禁止命令。
客戶端
########################## CLIENTS ##########################
maxclients:能連上 Redis 的最大客戶端連接數量。
maxclients 10000
內存管理
########################## MEMORY MANAGEMENT ##########################
maxmemory:設置 Redis 使用的內存字節數。
- maxmemory <bytes>
maxmemory-policy:內存容量超過 maxmemory 后的處理策略。
volatile-lru
volatile-random
volatile-ttl
allkeys-lru
allkeys-random
noeviction
maxmemory-samples:lru 檢測的樣本數。
replica-ignore-maxmemory:是否開啟 slave 的最大內存。
延遲釋放
########################## LAZY FREEING ##########################
lazyfree-lazy-eviction:以非阻塞方式釋放內存。
- lazyfree-lazy-eviction no
lazyfree-lazy-expire
- lazyfree-lazy-expire no
lazyfree-lazy-server-del
- lazyfree-lazy-server-del no
replica-lazy-flush
replica-lazy-flush no
僅追加模式
########################## APPEND ONLY MODE ##########################
appendonly:是否開啟 Append Only 模式。
- appendonly no
appendfilename:指定本地數據庫文件名。
- appendfilename "appendonly.aof"
appendfsync:aof 持久化策略的配置。
- always
- everysec
- no
no-appendfsync-on-rewrite:rewrite 期間對新寫操作的處理。
- no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage:aof 自動重寫的條件。
- auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size:允許重寫的最小 aof 文件大小。
- auto-aof-rewrite-min-size 64mb
aof-load-truncated:處理不完整的 aof 文件的方式。
- aof-load-truncated yes
aof-use-rdb-preamble:加載 Redis 時對 AOF 文件的識別。
LUA
########################## LUA SCRIPTING ##########################
lua-time-limit:Lua 腳本的最大時間限制。
lua-time-limit 5000
集群
########################## REDIS CLUSTER ##########################
cluster-enabled:集群開關。
- cluster-enabled yes
cluster-config-file:集群配置文件的名稱。
cluster-config-file nodes-6379.conf
cluster-node-timeout:節點互連超時的閥值。
- cluster-node-timeout 15000
cluster-replica-validity-factor:判斷 slave 節點與 master 斷線時間是否過長的因子。
- cluster-replica-validity-factor 10
cluster-migration-barrier:master 的 slave 數量遷移條件。
- cluster-migration-barrier 1
cluster-require-full-coverage:集群提供服務的條件。
cluster-require-full-coverage yes
慢指令
########################## SLOW LOG ##########################
slowlog-log-slower-than:記錄慢命令的時間閾值。
- slowlog-log-slower-than 10000
slowlog-max-len:慢查詢日志長度。
延遲監控
########################## LATENCY MONITOR ##########################
latency-monitor-threshold:延遲監控的閾值。
事件通知
########################## EVENT NOTIFICATION ##########################
notify-keyspace-events:鍵空間通知的參數。
高級配置
########################## ADVANCED CONFIG ##########################
hash-max-ziplist-entries:hash 數據結構的相關配置。
- hash-max-ziplist-entries 512
hash-max-ziplist-value
- hash-max-ziplist-value 64
list-max-ziplist-size
- list-max-ziplist-size -2
list-compress-depth
- list-compress-depth 0
set-max-intset-entries
- set-max-intset-entries 512
zset-max-ziplist-entries
- zset-max-ziplist-entries 128
zset-max-ziplist-value
- zset-max-ziplist-value 64
hll-sparse-max-bytes
- hll-sparse-max-bytes 3000
stream-node-max-bytes
- stream-node-max-bytes 4096
stream-node-max-entries
- stream-node-max-entries 100
activerehashing:是否對 hash 表進行重新 hash 以釋放內存。
- activerehashing yes
client-output-buffer-limit:對客戶端輸出緩沖的限制。
- client-output-buffer-limit normal 0 0 0
- client-output-buffer-limit replica 256mb 64mb 60
- client-output-buffer-limit pubsub 32mb 8mb 60
client-query-buffer-limit:客戶端查詢的緩存極限值大小。
proto-max-bulk-len:Redis 協議中批量請求的限制。
hz:Redis 執行任務的頻率。
- hz 10
dynamic-hz:是否啟用動態赫茲。
aof-rewrite-incremental-fsync:aof 重寫時的 fsync 方式。
- aof-rewrite-incremental-fsync yes
rdb-save-incremental-fsync:rdb 保存時的 fsync 方式。
主動碎片整理
########################## ACTIVE DEFRAGMENTATION ##########################
activedefrag:是否啟用活動碎片整理。
- activedefrag yes
active-defrag-ignore-bytes:啟動活動碎片整理的最小碎片浪費量。
- active-defrag-ignore-bytes 100mb
active-defrag-threshold-lower:啟動活動碎片整理的最小碎片百分比。
- active-defrag-threshold-lower 10
active-defrag-threshold-upper:最大碎片百分比。
- active-defrag-threshold-upper 100
active-defrag-cycle-min:碎片整理的最小 CPU 工作量。
- active-defrag-cycle-min 5
active-defrag-cycle-max:碎片整理的最大 CPU 工作量。
- active-defrag-cycle-max 75
active-defrag-max-scan-fields:處理的 set/hash/zset/list 字段的最大數目。
active-defrag-max-scan-fields 1000