如果客戶端訪問服務器提示“Too many open files”如何解決?
[root@proxy ~]# ab -n 2000 -c 2000 http://192.168.1.100/ #高並發訪問Nginx代理的網站,提示打開文件數量過多
Benchmarking 192.168.1.100 (be patient)
socket: Too many open files (24)
優化步驟:
1. 調整Nginx的主配置文件,增加並發量.
[root@proxy ~]# vim /usr/local/nginx/conf/nginx.conf
...
worker_processes 2; #調整到與CPU數量一致
events {
worker_connection 65535; #每個worker最大並發連接數
}
[root@proxy ~]#/usr/local/nginx/sbin/nginx -s reload
2. 調整內核參數
[root@proxy ~]# ulimit -a #查看所有的屬性值
[root@proxy ~]# ulimit -Hn 100000 #臨時設置硬限制
[root@proxy ~]# ulimit -Sn 100000 #設置軟限制
[root@proxy ~]# vim /etc/security/limits.conf
...
* soft nofile 100000
* hard nofile 100000
用戶/組 軟/硬限制 需要限制的項目 限制的值
3. 測試
[root@proxy ~]# ab -n 2000 -c 2000 http://192.168.1.100/ #自己訪問自己,測試一下配置效果
結束.