| | 20 | }}} |
| | 21 | |
| | 22 | * 如何調整每個使用者可以開啟的檔案個數 |
| | 23 | * [參考] [http://www.xenoclast.org/doc/benchmark/HTTP-benchmarking-HOWTO/node7.html Increasing the file descriptor limit] |
| | 24 | * 注意:修改 /etc/security/limits.conf 中間必須確定是 TAB ,如果有設定 vim 的 softwaretab 的話,得特別當心!!! |
| | 25 | * /proc/sys/fs/file-max - 核心預設最多可以開啟的檔案個數 |
| | 26 | {{{ |
| | 27 | ~$ cat /proc/sys/fs/file-max |
| | 28 | 743964 |
| | 29 | }}} |
| | 30 | * /etc/security/limits.conf - 每個程序(process)可以開啟檔案的個數(number limits of open files per process) - 像 HDFS 的 !DataNode 就需要調整這種參數([wiki:jazz/10-02-22#Hadoop:HDFS 2010-02-22]) |
| | 31 | {{{ |
| | 32 | #!diff |
| | 33 | --- /etc/security/limits.conf 2010-02-22 11:29:11.000000000 +0800 |
| | 34 | +++ /etc/security/limits.conf.new 2010-02-22 11:28:33.000000000 +0800 |
| | 35 | @@ -49,4 +49,6 @@ |
| | 36 | #ftp - chroot /ftp |
| | 37 | #@student - maxlogins 4 |
| | 38 | |
| | 39 | +* soft nofile 4096 |
| | 40 | +* hard nofile 743964 |
| | 41 | + |
| | 42 | # End of file |
| | 43 | }}} |
| | 44 | * /etc/pam.d/login - 告訴系統要用 /etc/security/limits.conf 來設定一些上限 |
| | 45 | {{{ |
| | 46 | # Sets up user limits according to /etc/security/limits.conf |
| | 47 | # (Replaces the use of /etc/limits in old login) |
| | 48 | session required pam_limits.so |
| | 49 | }}} |
| | 50 | * 指令: ulimit - 可以告訴你一些系統限制,並且設定想要的値 |
| | 51 | {{{ |
| | 52 | jazz@Wdebian:~$ ulimit -a |
| | 53 | core file size (blocks, -c) 0 |
| | 54 | data seg size (kbytes, -d) unlimited |
| | 55 | scheduling priority (-e) 0 |
| | 56 | file size (blocks, -f) unlimited |
| | 57 | pending signals (-i) 72704 |
| | 58 | max locked memory (kbytes, -l) 32 |
| | 59 | max memory size (kbytes, -m) unlimited |
| | 60 | open files (-n) 1024 |
| | 61 | pipe size (512 bytes, -p) 8 |
| | 62 | POSIX message queues (bytes, -q) 819200 |
| | 63 | real-time priority (-r) 0 |
| | 64 | stack size (kbytes, -s) 8192 |
| | 65 | cpu time (seconds, -t) unlimited |
| | 66 | max user processes (-u) 72704 |
| | 67 | virtual memory (kbytes, -v) unlimited |
| | 68 | file locks (-x) unlimited |
| | 69 | }}} |
| | 70 | * 假設 /proc/sys/fs/file-max 跟 /etc/security/limits.conf 都有設定上限為 743964,且 /etc/pam.d/login 也有打開,但是 ulimit -a 指令仍顯示 1024 (預設),可以修改 /etc/rc.local 或 /etc/profile 強制用 ulimit -n 743964 來提高開檔個數。 |
| | 71 | {{{ |
| | 72 | ~$ ulimit -n 743964 |
| | 73 | }}} |
| | 74 | * [備註] 如果 ulimit 超出可容許範圍,會顯示 Operation not permitted,此時請檢查相關設定値 |
| | 75 | {{{ |
| | 76 | ~$ ulimit -n 7439640 |
| | 77 | -bash: ulimit: open files: cannot modify limit: Operation not permitted |