在 CentOS 上调整 Redis 参数,通常有两种方式:修改配置文件(推荐) 和 命令行动态修改(临时)。下面按常见场景一步步说明。
常见位置:
/etc/redis.conf
# 或
/etc/redis/redis.conf
查看 Redis 是否使用哪个配置:
ps -ef | grep redis
bind 127.0.0.1
bind 127.0.0.1bind 0.0.0.0(需配合防火墙)port 6379
daemonize yes
CentOS 上通常设为 yes
maxmemory 2gb
建议:
maxmemory-policy allkeys-lru
常用策略:
noeviction(默认,写报错)allkeys-lru(推荐)volatile-lrusave 900 1
save 300 10
save 60 10000
appendonly yes
appendfsync everysec
maxclients 10000
注意:受系统 ulimit -n 限制
slowlog-log-slower-than 10000
slowlog-max-len 128
vi /etc/redis.conf
修改后保存,重启 Redis:
systemctl restart redis
或
service redis restart
redis-cli
CONFIG SET maxmemory 2gb
CONFIG SET maxmemory-policy allkeys-lru
查看当前配置:
CONFIG GET maxmemory
⚠️ 重启后失效
ulimit -n 65535
永久修改:
vi /etc/security/limits.conf
* soft nofile 65535
* hard nofile 65535
echo never > /sys/kernel/mm/transparent_hugepage/enabled
firewall-cmd --add-port=6379/tcp --permanent
firewall-cmd --reload
redis-cli ping
redis-cli info memory
redis-cli info clients
如果你能告诉我:
我可以给你一套 针对性调优参数模板。