You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
61 lines
1.5 KiB
61 lines
1.5 KiB
# --- 基础网络配置 --- |
|
# 生产环境务必绑定内网 IP,不要仅监听 0.0.0.0 |
|
bind 0.0.0.0 |
|
port 6379 |
|
tcp-backlog 511 |
|
timeout 0 |
|
tcp-keepalive 300 |
|
|
|
# --- 安全配置 --- |
|
# 生产环境必须设置强密码 |
|
requirepass "phLoaoPLWx9h" |
|
# 禁用或重命名高危命令 |
|
rename-command FLUSHALL "" |
|
rename-command FLUSHDB "" |
|
rename-command DEBUG "" |
|
|
|
# --- 运行模式 --- |
|
daemonize no |
|
pidfile /var/run/redis_6379.pid |
|
loglevel notice |
|
logfile "" |
|
databases 16 |
|
|
|
# --- RDB 持久化配置 --- |
|
# 开启 RDB,设置合理的快照频率 |
|
# 格式:save <seconds> <changes> |
|
save 900 1 |
|
save 300 10 |
|
save 60 10000 |
|
|
|
stop-writes-on-bgsave-error yes |
|
rdbcompression yes |
|
rdbchecksum yes |
|
dbfilename dump.rdb |
|
dir /data |
|
|
|
# --- AOF 持久化配置 (显式关闭) --- |
|
appendonly no |
|
|
|
# --- 内存管理 --- |
|
# 根据服务器实际可用内存设置,建议保留 20-30% 给系统和 BGSAVE 进程 |
|
maxmemory 2gb |
|
# 达到内存上限时的淘汰策略:使用最少使用的 key (LRU) |
|
maxmemory-policy allkeys-lru |
|
# Redis 8 优化了内存碎片处理 |
|
activedefrag yes |
|
|
|
# --- 性能优化与限制 --- |
|
maxclients 10000 |
|
# 慢查询日志:执行时间超过 10 毫秒的记录 |
|
slowlog-log-slower-than 10000 |
|
slowlog-max-len 128 |
|
|
|
# --- 线程 IO (Redis 6.0+ 特性,Redis 8 依然适用) --- |
|
# 根据 CPU 核心数调整,通常 8 核设为 3,16 核设为 6 |
|
io-threads 4 |
|
io-threads-do-reads yes |
|
|
|
# --- 保护机制 --- |
|
# 避免因为 Swap 导致的性能抖动 |
|
# 请在操作系统层面设置 vm.swappiness=0 |