文章目錄
- 單位
- 包含
- 網絡 NETWORK
- 通用 GENERAL
- 快照 SNAPSHOTTING
- 主從復制 REPLICATION
- 安全 SECURITY
- 客戶端 CLIENTS
- 內存設置 MEMORY MANAGEMENT
- APPEND ONLY MODE 模式(aof 的配置)
單位
配置文件對大小寫不敏感(unit單位)。
包含
可以把多個配置文件包含進來。
網絡 NETWORK
bind 127.0.0.1 -::1 # 綁定的 ipprotected-mode yes # 保護模式port 6379 # 端口
通用 GENERAL
daemonize yes # 是否以守護進程開啟,默認為 no,pidfile /var/run/redis_6379.pid # 如果以后臺方式運行,我們就需要指定一個 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)
# nothing (nothing is logged)
loglevel notice # 日志級別logfile "" # 日志輸出的文件位置databases 16 # 數據庫數量,默認 16 個數據庫always-show-logo no # 是否顯示 logo
快照 SNAPSHOTTING
- 持久化:在規定時間內,執行了多少次操作,則會持久化到文件 .rdb & .aof。
- Redis 是內存數據庫,如果沒有持久化,則數據斷電即失。
# Unless specified otherwise, by default Redis will save the DB:
# * After 3600 seconds (an hour) if at least 1 change was performed
# * After 300 seconds (5 minutes) if at least 100 changes were performed
# * After 60 seconds if at least 10000 changes were performed
#
# You can set these explicitly by uncommenting the following line.
## 如果 3600s 內,至少有 1 個 key 進行了修改,就進行持久化操作
# 如果 300s 內,至少有 100 個 key 進行了修改,就進行持久化操作
save 3600 1 300 100 60 10000stop-writes-on-bgsave-error yes # 如果持久化出錯了,Redis 是否還需要持續工作。(默認開啟)rdbcompression yes # 是否壓縮 rdb 文件,需要消耗 CPU 資源rdbchecksum yes # 保存 rdb 文件的時候,進行錯誤的檢查校驗dir ./ # rdb 文件保存的目錄
主從復制 REPLICATION
安全 SECURITY
設置 Redis 密碼(默認沒有密碼):
127.0.0.1:6379> ping
PONG
127.0.0.1:6379> config get requirepass # 獲取密碼
1) "requirepass"
2) ""
127.0.0.1:6379> config set requirepass 123456 # 設置密碼
OK
127.0.0.1:6379> exit # 需要退出重新登錄才生效
(base) [src]$ ./redis-cli
127.0.0.1:6379> ping
(error) NOAUTH Authentication required.
127.0.0.1:6379> config get requirepass
(error) NOAUTH Authentication required.
127.0.0.1:6379> auth 123456 # 使用密碼進行登錄
OK
127.0.0.1:6379> config get requirepass
1) "requirepass"
2) "123456"
客戶端 CLIENTS
maxclients 10000 # 設置 Redis 客戶端的最大連接數
內存設置 MEMORY MANAGEMENT
maxmemory <bytes> # Redis 最大內存容量設置# volatile-lru -> Evict using approximated LRU, only keys with an expire set.
# allkeys-lru -> Evict any key using approximated LRU.
# volatile-lfu -> Evict using approximated LFU, only keys with an expire set.
# allkeys-lfu -> Evict any key using approximated LFU.
# volatile-random -> Remove a random key having 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 evict anything, just return an error on write operations.
maxmemory-policy noeviction # 內存達到上限后的處理策略
APPEND ONLY MODE 模式(aof 的配置)
appendonly no # 默認不開啟 aof 模式,默認是使用 rdb 方式持久化的,大部分情況下 rdb 完全夠用。appendfilename "appendonly.aof" # 持久化的文件的名字# appendfsync always # 每次修改都會同步
# appendfsync no # 不執行同步,這時候操作系統自己同步數據
appendfsync everysec # 每秒執行一次持久化數據的同步,可能會丟失者 1s 的數據