2016-07-01

Linux Open Files

1. 查看kernal open files 上限

[root@xxx fd]# cat /proc/sys/fs/file-max
2000000

2. 查看有多少個kernal files被開啟
[root@xxx fd]# sysctl fs.file-nr
fs.file-nr = 2144       0       2000000

3. 修改max open files
vi /etc/sysctl.conf 加入 fs.file-max = xx,
執行sysctl -p 讓設定生效

4. ulimit -a 查看每個user的使用上限
可以修改設定檔 /etc/security/limits.conf 來設定
* soft nofile 655360
* hard nofile 655360
ulimit -n
ulimit -n 655360

5. 寫了一個shellscript 每分鐘log下來。

#!/bin/bash
while :
do
# cd /proc/<PID>/fd
 today=$(date +"%m-%d-%Y")
 filename="/tmp/${today}.log"
 tt=$(date +"%T")
# echo "$tt" >> "${filename}"
 #lsof | wc -l >> "${filename}"
 ss=$(lsof | wc -l)
 echo ${tt}" "${ss}  >> "${filename}"
sleep 60

done