Linux檔案控制代碼數調整
阿新 • • 發佈:2018-12-24
首先介紹下Linux系統中"一切都是檔案"。
1. Linux系統檔案控制代碼數概念
檔案控制代碼和檔案描述符
2. 查詢Linux系統檔案控制代碼數
# ulimit -a core file size (blocks, -c) 0 data seg size (kbytes, -d) unlimited scheduling priority (-e) 0 file size (blocks, -f) unlimited pending signals (-i) 7179max locked memory (kbytes, -l) 64 max memory size (kbytes, -m) unlimited open files (-n) 65535 pipe size (512 bytes, -p) 8 POSIX message queues (bytes, -q) 819200 real-time priority (-r) 0 stack size (kbytes, -s) 8192 cpu time(seconds, -t) unlimited max user processes (-u) 7179 virtual memory (kbytes, -v) unlimited file locks (-x) unlimited
3. 配置檔案
/etc/security/limits.conf * soft nofile 2048 * hard nofile 32768 * soft nofile 2048 * hard nofile 32768第一列表示域(domain),可以使用使用者名稱(root等),組名(以@開頭),通配置*和%,%可以用於%group引數。 第二列表示型別(type),值可以是soft或者hard 第三列表示專案(item),值可以是core, data, fsize, memlock, nofile, rss, stack, cpu, nproc, as, maxlogins, maxsyslogins, priority, locks, msgqueue, nie, rtprio. 第四列表示值.
4. 如何修改最大控制代碼數
臨時生效: ulimit -n 2048 或者 echo ulimit -n 2048>>/etc/profile
永久生效:修改/etc/security/limits.conf配置檔案
5. 如何查詢當前系統中檔案控制代碼數使用情況
1)統計各程序開啟控制代碼數:lsof -n|awk '{print $2}'|sort|uniq -c|sort -nr
2)統計各使用者開啟控制代碼數:lsof -n|awk '{print $3}'|sort|uniq -c|sort -nr
3)統計各命令開啟控制代碼數:lsof -n|awk '{print $1}'|sort|uniq -c|sort -nr