典型的,提供大量靜態(tài)文件訪問(wèn)的web服務(wù)器,緩存服務(wù)器(如squid), 均要注意這個(gè)問(wèn)題
網(wǎng)上的教程,大約只是簡(jiǎn)單說(shuō)明了如何設(shè)置ulimit和file-max, 但并沒(méi)有說(shuō)清楚這兩者之間的差別,讓人一頭霧水
1. file-max的含義
man proc,可得到file-max的描述:
/proc/sys/fs/file-max
This file defines a system-wide limit on the number of open files for all processes. (See
also setrlimit(2), which can be used by a process to set the per-process limit,
RLIMIT_NOFILE, on the number of files it may open.) If you get lots of error messages
about running out of file handles, try increasing this value:
即file-max是設(shè)置系統(tǒng)所有進(jìn)程一共可以打開(kāi)的文件數(shù)量 。同時(shí)一些程序可以通過(guò)setrlimit調(diào)用,設(shè)置每個(gè)進(jìn)程的限制。如果得到大量使用完文件句柄的錯(cuò)誤信息,是應(yīng)該增加這個(gè)值。
也就是說(shuō),這項(xiàng)參數(shù)是系統(tǒng)級(jí)別的。
echo 6553560 > /proc/sys/fs/file-max
或修改 /etc/sysctl.conf, 加入
fs.file-max = 6553560 重啟生效
2. ulimit的
Provides control over the resources available to the shell and to processes started by it, on systems that allow such control.
即設(shè)置當(dāng)前shell以及由它啟動(dòng)的進(jìn)程的資源限制。
顯然,對(duì)服務(wù)器來(lái)說(shuō),file-max, ulimit都需要設(shè)置,否則就可能出現(xiàn)文件描述符用盡的問(wèn)題,為了讓機(jī)器在重啟之后仍然有效,強(qiáng)烈建立作以下配置,以確保file-max, ulimit的值正確無(wú)誤:
1. 修改/etc/sysctl.conf, 加入
fs.file-max = 6553560
2.系統(tǒng)默認(rèn)的ulimit對(duì)文件打開(kāi)數(shù)量的限制是1024,修改/etc/security/limits.conf并加入以下配置,永久生效
* soft nofile 65535
* hard nofile 65535
修改完之后,重啟即可生效
聯(lián)系客服