Linux ãµã¼ãã§ã®ãToo many open filesã対çã«ã¤ãã¦
Linux ãµã¼ãã§ã®ãToo many open filesãã¨ã©ã¼å¯¾çã«ã¤ãã¦èª¿ã¹ãã®ã§ã¾ã¨ãã¦ã¿ã¾ããã
確èªãã OS 㯠CentOS 5.9 㨠CentOS 6.3 ã§ãã
ãToo many open filesã㯠Linux ã§ããã»ã¹ãéãããã¡ã¤ã«ãã£ã¹ã¯ãªãã¿ã®ä¸éã«éãã¦ãã¾ãã¨çºçããã¨ã©ã¼ã§ãã
ããã¡ã¤ã«ãã£ã¹ã¯ãªãã¿ãã¨ããååã§ããã Linux ã§ã¯ã½ã±ããããã¡ã¤ã«ãã£ã¹ã¯ãªãã¿ãªã®ã§ããã¡ã¤ã«ãéããå ´åã ãã§ãªããã½ã±ããã使ã£ã¦éä¿¡ãè¡ãå ´åã«ããã¡ã¤ã«ãã£ã¹ã¯ãªãã¿ã使ç¨ããã¾ãã
ãã®ãããApache ã Tomcat ãªã©ã§é«è² è·ãªãµã¤ããéç¨ãã¦ããå ´åãªã©ã«ã¯ãæ¯è¼çééãã確çã®é«ãã¨ã©ã¼ã§ã¯ãªãã§ããããã
ãã®ã¨ã©ã¼ãåé¿ãããããããã»ã¹ããªã¼ãã³ã§ãããã¡ã¤ã«ãã£ã¹ã¯ãªãã¿ã®ä¸éãå¤æ´ãã¾ãã
ã¾ãã¯ä»¥ä¸ã®ã³ãã³ããå®è¡ããç¾å¨ãã°ã¤ã³ä¸ã®ã¦ã¼ã¶ã® open files ã®å¤ã確èªãã¾ãã
# ulimit -n 1024
ããã©ã«ãã§ã¯ 1024 ã«è¨å®ããã¦ããããã§ããã
ããã ã¨è² è·ãé«ãã®ãµã¼ãã§ã¯ä½¿ãåã£ã¦ãã¾ãäºãããããã§ãã
ãã®å¶éå¤ãä¸ããããã«ã¯ã/etc/security/limits.conf ãã¡ã¤ã«ãç·¨éãã¾ãã
# vi /etc/security/limits.conf
ã¨ããããããã§ã¯
- ä¸é㯠65536
- å ¨ã¦ã¼ã¶ã対象
- ã½ãããªãããããã¼ããªãããå ±ã«åãå¤
ã¨ããäºã§ã以ä¸ã®è¨å®ã追è¨ãã¾ããã
* soft nofile 65536 * hard nofile 65536
limits.conf 㯠PAM èªè¨¼ã®ã¢ã¸ã¥ã¼ã«ã§ãã pam_limits.so ã®è¨å®ãã¡ã¤ã«ã§ããã°ã¤ã³ã®éã«èªã¿è¾¼ã¾ãããã¡ã¤ã«ã§ãã
ãªã®ã§ãä¸æ¦ su - ãã¦åèªã¿è¾¼ã¿ãããå¾ã«å度å¤ã確èªãã¦ã¿ã¾ãã
# su - # ulimit -n 65536
è¨å®ãåæ ããã¾ãããã
次ã«ãã¼ã¢ã³ããã»ã¹ã®è¨å®ã確èªãã¾ãã
ããã§ã¯ Apache ãä¾ã«èª¿ã¹ã¦ã¿ã¾ããã
ããã»ã¹ã®å ´åã¯è¨å®å¤æ´å¾ã«ããã»ã¹ãåèµ·åããã¨åæ ããã¾ãã
# service httpd restart
Apache ã®å ´åãããã»ã¹æ¯ã®ãªã¼ãã³å¯è½ãªãã¡ã¤ã«ãã£ã¹ã¯ãªãã¿ã®æ°ã¯ä»¥ä¸ã®ããã«ãã¦ç¢ºèªã§ãã¾ãã
# cat /proc/`pgrep httpd | head -1`/limits | grep 'open files' Max open files 65536 65536 files
ç¡äºå¢ãã¦ãã¾ããã
ããã§çµããã»ã»ã»ãªã話ã¯ç°¡åãªã®ã§ãããå®éã«éç¨ãã¦ãã㨠OS ãåèµ·åããªããã°ãªããªããªããã¨ãããã¾ãã
ã¨ãããã㧠OS èªä½ãåèµ·åãã¦ãèªåèµ·åã«ãªã£ã¦ãããã¼ã¢ã³ããã»ã¹ã® Max open files ãã¡ããã¨å¢å ãã¦ãããã確èªãã¦ã¿ã¾ããã
# reboot
åèµ·åãå®äºãããå度確èªã³ãã³ããå®è¡ã
# cat /proc/`pgrep httpd | head -1`/limits | grep 'open files' Max open files 1024 1024 files
ããï¼
ä½æ
ãå¤ãæ»ã£ã¦ãã¾ã£ã¦ãã¾ããã
ã©ããã OS èµ·åæã®ãã¼ã¢ã³ã¯ PAM èªè¨¼ãéããªããããlimits.conf ã®è¨å®ãåæ ãããªããã¨ããäºã®ããã§ãã
ãã®ç¾è±¡ãåé¿ããããã«ã¯ init.d 以ä¸ã®èµ·åã¹ã¯ãªããå
ã§åå¥ã«ãulimit -n 65536ããæå®ããã°ããã®ã§ãããè¤æ°ã®ããã»ã¹ã«æå®ããå¿
è¦ãããå ´åãªã©ãè¨å®å¤æ´ã®åº¦ã«ãã¡ãã¡åå¥ã®ãã¡ã¤ã«ãç·¨éããã®ã¯é¢åã§ãã
ä½ãè¯ãæ¹æ³ã¯ãªããã¨æã£ã¦ããããã¨èª¿ã¹ã¦ã¿ãã¨ãããèªåèµ·åããå ¨ã¦ã®ãã¼ã¢ã³ã«è¨å®ãåæ ããããã®æ¹æ³ãã¡ããã¨ç¨æããã¦ãã¾ããã
Man page of INITSCRIPT
http://linuxjm.sourceforge.jp/html/SysVinit/man5/initscript.5.html
ããã¯æ£ã«ç®çã«åãããã§ãã
ã¨ããããã§ãããã§ã¯ /etc/initscript ãã¡ã¤ã«ãä½æãããã¡ãã«ä»¥ä¸ã®ããã«è¨è¿°ãã¾ããã
ããã©ã«ãã§ã¯ãã¡ã¤ã«èªä½ãåå¨ããªããããªã®ã§ä½æãã¾ãã
# vi /etc/initscript
å 容ã¯ä»¥ä¸ã
ulimit -n 65536 eval exec "$4"
ä¿åãããå度 OS ãåèµ·åãã¾ãã
# reboot
åèµ·åå¾ã«ç¢ºèªããã¨ãä»åº¦ã¯ç¡äºã«åæ ããã¦ãã¾ããï¼
# cat /proc/`pgrep httpd | head -1`/limits | grep 'open files' Max open files 65536 65536 files
ãã㧠CentOS 5.9 ã§ã¯ OS åèµ·åæã«ããã¡ã¤ã«ãã£ã¹ã¯ãªãã¿ã®æ大æ°ãå¤æ´ãã¦ãããã¨ãåºæ¥ãããã«ãªãã¾ããã
è² è·ãã¹ããªã©ãè¡ãã°åãã¾ããããToo many open filesãã¨ã©ã¼ã¯ã»ã¼çºçããªããªã£ããã¨ãåãããã¨æãã¾ãã
ããããå®ã¯ CentOS 6.3 ã§ã¯ä¸è¨ã®æé ã§ã¯ OS èµ·åæã®ãã¼ã¢ã³ã®è¨å®ãå¤æ´ãããã¨ãã§ãã¾ããã
RHEL6 ããã¯ãã¼ã¢ã³ã®èµ·åã« Upstart ã使ãããããã«ãªã£ãã®ã§ãããããã«ããã©ããã /etc/initscript ã使ç¨ãããªããªã£ã¦ãã¾ã£ãããã§ãã
ä½ãæ¹æ³ã¯ãªããããã°ããæ¤ç´¢ãã¦ã¿ãã¨ãulimit ã®è¨å®ã« /etc/sysconfig/init ã使ç¨ãã¦ããã¨ããè¨äºãããã¾ããã
[RHEL][Upstart] Upstartã«ãããulimitè¨å®ã¨core dump | åè¢éé blog.hansode.org
http://blog.hansode.org/archives/52521158.html
ã¨ãããã¨ã§ /etc/sysconfig/init ã使ç¨ãã¦ã¿ã¾ãã
# vi /etc/sysconfig/init
ãã¡ã¤ã«ã®æ«å°¾ã«ä»¥ä¸ã追è¨ãã¾ããã
ulimit -n 65536
ãã㧠OS ãåèµ·åãã¦ã¿ãã¨ãä»åº¦ã¯ç¡äº ulimit ã®è¨å®ãåæ ããã¦ãã¾ããï¼
ãã ãæ¤ç´¢ãã¦ãä»ã«ããã¨ãã£ãæ
å ±ãåºã¦ããªãã®ã§ãUpstart ã®ãä½æ³çã«ãã®æ¹æ³ãé©åããã¨ããã®ã¯ã¯ã£ããã¨ã¯ãããã¾ããã§ããã
Upstart ã§ã® /etc/initscript ã«ç¸å½ãããã¡ã¤ã«ã£ã¦åå¨ããªããã§ããããï¼
ã¨ããããæå
ã®ç°å¢ã§ã¯ä»ã®ã¨ãããã®è¨å®ã§å
¨ãåé¡ãªãåä½ãã¦ãã¾ãã
åè
ãã¡ã¤ã«ãã£ã¹ã¯ãªãã¿æ°ã®ä¸éå¤æ´ã¨limits.confã®ç½ (ããæï¼ããã¿ã¹ã¿ããããã°)
http://yumewaza.yumemi.co.jp/2010/07/limitsconf.html
ulimitãå¹ããªãä¸å®ãç¡ããè¨å® | å¤éç¶ã®å
http://blog.father.gedow.net/2012/08/08/ulimit-configuration/