在 CentOS 上配置 Redis 的连接数,核心是通过 redis.conf 中的 maxclients 参数来控制,同时还要注意 系统级别的限制(如文件描述符限制),否则配置可能不生效。
下面按步骤说明:
常见位置:
/etc/redis.conf
或
/etc/redis/redis.conf
vim /etc/redis.conf
找到并修改:
maxclients 10000
默认一般是 10000
如果 Redis 以redis用户运行,受系统 ulimit 限制
systemctl restart redis
或
systemctl restart redis-server
Redis 连接数受 文件描述符(fd) 限制。
ulimit -n
编辑:
vim /etc/security/limits.conf
添加:
* soft nofile 65535
* hard nofile 65535
redis soft nofile 65535
redis hard nofile 65535
vim /usr/lib/systemd/system/redis.service
在 [Service] 下添加:
LimitNOFILE=65535
重载 systemd:
systemctl daemon-reload
systemctl restart redis
redis-cli
CONFIG GET maxclients
INFO clients
输出示例:
connected_clients:12
maxclients:10000
原因通常是:
nofile 限制太小LimitNOFILE说明:
maxclientsmaxclients 20000
系统:
nofile = 65535
如果你愿意,可以告诉我:
我可以给你更精确的配置方案。