Linux-Can't create socket: Too many open files

一、问题

在使用redis-benchmark进行redis基准测试时,模拟了10万的客户端请求,然后报错提示:

Can't create socket: Too many open files
./redis-benchmark -h 192.168.0.60 -c 100000 -n 1000000 -d 50
 

二、原因

linux系统默认open file是1024,程序打开的文件/socket连接数量超过系统设定值。可以用命令查看:ulimit -a,如下图

三、解决方法

临时生效方法(仅当前会话有效):

ulimit -n 2048

永久生效方法:

vim /etc/security/limits.conf

在文件最后加上以下代码,然后重新打开会话即可:

* soft nofile 40960
* hard nofile 40960

openfile 最大数:655350

unlimited 是一个特殊值,用于表示不限制。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章