如何精准调优Redis,关注哪些关键参数?

摘要:背景 在一台未经过任何调优的 Linux 服务器上部署 Redis,在 Redis 启动过程中,可能会碰到以下警告信息。 1363410:M 15 Jan 2026 13:07:34.879 # WARNING:
背景 在一台未经过任何调优的 Linux 服务器上部署 Redis,在 Redis 启动过程中,可能会碰到以下警告信息。 1363410:M 15 Jan 2026 13:07:34.879# WARNING: The TCP backlog setting of 512 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128. 1363410:M 15 Jan 2026 13:07:34.879# Server initialized 1363410:M 15 Jan 2026 13:07:34.879# WARNING Memory overcommit must be enabled! Without it, a background save or replication may fail under low memory condition. Being disabled, it can can also cause failures without low memory condition, see https://github.com/jemalloc/jemalloc/issues/1328. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect. 1363410:M 15 Jan 2026 13:07:34.879# WARNING You have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo madvise > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled (set to 'madvise' or 'never'). 这些警告信息实际上是在提醒我们,操作系统的某些参数设置得不合理,需要调整,否则会影响 Redis 的性能和稳定性。 除此之外,Redis 还提供了多个参数,用于在进程或连接级别进行内核参数优化,例如: tcp-backlog:设置 TCP 服务器中listen()的 backlog 参数。 disable-thp:在进程级别关闭透明大页(THP)。 tcp-keepalive:在连接级别设置 TCP Keepalive 参数。 server_cpulist、bio_cpulist:可将 Redis 进程或后台 I/O 线程绑定到指定 CPU。 oom-score-adj、oom-score-adj-values:调整进程的 oom_score。oom_score 是 Linux 内核为每个进程计算的一个整数值(位于/proc/[pid]/oom_score),分数越高,进程在内存不足时越容易被 OOM Killer 杀死。 下面,我们看看这些参数的实现细节和设置建议。 tcp-backlog createIntConfig("tcp-backlog",NULL, IMMUTABLE_CONFIG,0, INT_MAX, server.tcp_backlog,511, INTEGER_CONFIG,NULL,NULL),/* TCP listen backlog. */ tcp-backlog 用于设置 TCP 服务器在调用listen()时使用的 backlog 参数。该参数用于指定已完成三次握手、但尚未被accept()处理的连接队列长度。
阅读全文