centos5.3 中 ulimit -n 爲1024, 當Nginx連接數超過1024時,error.log中就出現以下錯誤:
[alert] 12766#0: accept() failed (24: Too many open files)
使用 ulimit -n 655350 可以把打開文件數設置足夠大, 同時修改nginx.conf , 添加 worker_rlimit_nofile 655350; (與error_log同級別)
這樣就可以解決Nginx連接過多的問題,Nginx就可以支持高併發。<還要修改nginx>
另外, ulimit -n 還會影響到mysql 的併發連接數。把他提高,也就提高了mysql併發。
注意: 用ulimit -n 2048 修改只對當前的shell有效,退出後失效。
修改方法
若要令修改ulimits的數值永久生效,則必須修改配置文檔,可以給ulimit修改命令放入/etc/profile裏面,這個方法實在是不方便,
還有一個方法是修改/etc/security/limits.conf
/etc/security/limits.conf 格式,文件裏面有很詳細的註釋,比如
* soft nofile 655360
* hard nofile 655360
星號代表全局, soft爲軟件,hard爲硬件,nofile爲這裏指可打開文件數。
把以上兩行內容加到 limits.conf文件中即可。
另外,要使 limits.conf 文件配置生效,必須要確保 pam_limits.so 文件被加入到啓動文件中。查看 /etc/pam.d/login 文件中有:
session required /lib/security/pam_limits.so
修改完重新登錄就可以見到效果,可以通過 ulimit -n 查看。
轉至:http://blog.chinaunix.net/uid-25525723-id-363880.html