1.回顾:

某在线主机深夜连续接到告警系统的disk Used 超限告警。

登陆主机查看却遇到了困惑:在检查磁盘使用量 df –h 出来的磁盘使用量确实和告警信息一样,已经被100%占用,但是查看目录大小 du 时,却显示实际目录大小并非这样,而是有很大空闲空间。

如图:磁盘用量 df –h 结果为100%Used,

目录实际总大小 du –h –max-depth=1,显示总目录大小为60k,几乎可以忽略的使用比例。

【知识准备】 [linux] lsof 命令了解:

lsof(list open files)是一个查看当前系统文件的工具。在linux环境下,任何事物都以文件的形式存在,通过文件不仅仅可以访问常规数据,还可以访问网络连接和硬件。如传输控制协议 (TCP) 和用户数据报协议 (UDP) 套接字等,系统在后台都为该应用程序分配了一个文件描述符,该文件描述符提供了大量关于这个应用程序本身的信息。

lsof打开的文件可以是:

  1. 普通文件

  2. 目录

  3. 网络文件系统的文件

  4. 字符或设备文件

  5. (函数)共享库

  6. 管道,命名管道

  7. 符号链接

  8. 网络文件(例如:NFS file、网络socket,unix域名socket)

  9. 还有其它类型的文件,等等

【man linux】结果:包含了大量的参数:

[root@demo1 local]# man lsof
LSOF(8)                                                                LSOF(8)

NAME
       lsof - list open files

SYNOPSIS
       lsof  [  -?abChlnNOPRtUvVX ] [ -A A ] [ -c c ] [ +c c ] [ +|-d d ] [ +|-D D ] [ +|-e s ] [ +|-f [cfgGn] ] [ -F [f] ] [
       -g [s] ] [ -i [i] ] [ -k k ] [ +|-L [l] ] [ +|-m m ] [ +|-M ] [ -o [o] ] [ -p s ] [ +|-r [t[m<fmt>]] ] [ -s [p:s] ]  [
       -S [t] ] [ -T [t] ] [ -u s ] [ +|-w ] [ -x [fl] ] [ -z [z] ] [ -Z [Z] ] [ -- ] [names]

命令参数

-a 列出打开文件存在的进程

-c<进程名> 列出指定进程所打开的文件

-g 列出GID号进程详情

-d<文件号> 列出占用该文件号的进程

+d<目录> 列出目录下被打开的文件

+D<目录> 递归列出目录下被打开的文件

-n<目录> 列出使用NFS的文件

-i<条件> 列出符合条件的进程。(4、6、协议、:端口、 @ip )

-p<进程号> 列出指定进程号所打开的文件

-u 列出UID号进程详情

-h 显示帮助信息

-v 显示版本信息

实际使用:

$lsof| more
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
init 1 root cwd DIR 253,0 4096 2 /
init 1 root rtd DIR 253,0 4096 2 /
init 1 root txt REG 253,0 150352 1310795 /sbin/init
init 1 root mem REG 253,0 65928 5505054 /lib64/libnss_files-2.12.so
init 1 root mem REG 253,0 1918016 5521405 /lib64/libc-2.12.so
init 1 root mem REG 253,0 93224 5521440 /lib64/libgcc_s-4.4.6-20120305.so.1
init 1 root mem REG 253,0 47064 5521407 /lib64/librt-2.12.so
init 1 root mem REG 253,0 145720 5521406 /lib64/libpthread-2.12.so
...

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

说明:

lsof输出各列信息的意义如下:

  • COMMAND:进程的名称

  • PID:进程标识符

  • PPID:父进程标识符(需要指定-R参数)

  • USER:进程所有者

  • PGID:进程所属组

  • FD:文件描述符,应用程序通过文件描述符识别该文件。如cwd、txt等:

(1)cwd:表示current work dirctory,即:应用程序的当前工作目录,这是该应用程序启动的目录,除非它本身对这个目录进行更改
(2)txt :该类型的文件是程序代码,如应用程序二进制文件本身或共享库,如上列表中显示的 /sbin/init 程序
(3)lnn:library references (AIX);
(4)er:FD information error (see NAME column);
(5)jld:jail directory (FreeBSD);
(6)ltx:shared library text (code and data);
(7)mxx :hex memory-mapped type number xx.
(8)m86:DOS Merge mapped file;
(9)mem:memory-mapped file;
(10)mmap:memory-mapped device;
(11)pd:parent directory;
(12)rtd:root directory;
(13)tr:kernel trace file (OpenBSD);
(14)v86 VP/ix mapped file;
(15)0:表示标准输入
(16)1:表示标准输出
(17)2:表示标准错误
一般在标准输出、标准错误、标准输入后还跟着文件状态模式:r、w、u等
(1)u:表示该文件被打开并处于读取/写入模式
(2)r:表示该文件被打开并处于只读模式
(3)w:表示该文件被打开并处于
(4)空格:表示该文件的状态模式为unknow,且没有锁定
(5)-:表示该文件的状态模式为unknow,且被锁定
同时在文件状态模式后面,还跟着相关的锁
(1)N:for a Solaris NFS lock of unknown type;
(2)r:for read lock on part of the file;
(3)R:for a read lock on the entire file;
(4)w:for a write lock on part of the file;(文件的部分写锁)
(5)W:for a write lock on the entire file;(整个文件的写锁)
(6)u:for a read and write lock of any length;
(7)U:for a lock of unknown type;
(8)x:for an SCO OpenServer Xenix lock on part of the file;
(9)X:for an SCO OpenServer Xenix lock on the entire file;
(10)space:if there is no lock.

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

  • TYPE:文件类型,如DIR、REG等,常见的文件类型:

    (1)DIR:表示目录
    (2)CHR:表示字符类型
    (3)BLK:块设备类型
    (4)UNIX: UNIX 域套接字
    (5)FIFO:先进先出 (FIFO) 队列
    (6)IPv4:网际协议 (IP) 套接字
  • DEVICE:指定磁盘的名称

  • SIZE:文件的大小

  • NODE:索引节点(文件在磁盘上的标识)

  • NAME:打开文件的确切名称

详细使用实例:http://linuxtools-rst.readthedocs.io/zh_CN/latest/tool/lsof.html

2.故障排查

lsof | grep -i delete 或者 lsof +d /tmp 或者 lsof +D /tmp

非常多的fpm进程在操作 /tmp 目录,重启fpm之后。空间释放:

几个资料:

https://mp.weixin.qq.com/s/bEhuc1PPGPuYuA2mQArHLQ

http://linuxtools-rst.readthedocs.io/zh_CN/latest/tool/lsof.html

最新文章

  1. 7个惊艳的HTML5 Canvas动画效果及源码
  2. POJ 3261 Milk Patterns (求可重叠的k次最长重复子串)+后缀数组模板
  3. golang.org/x/mobile/exp/gl/glutil/glimage.go 源码分析
  4. IE浏览器上传文件时本地路径变成”C:\fakepath\”的问题【转】
  5. Codeforces Round #185 (Div. 2) C. The Closest Pair 构造
  6. file_put_contents() failed to open stream: Permission denied 问题解决
  7. A - Wireless Network-poj2236(简单并查集)
  8. bootstrap base css 基本css
  9. 使用VC++压缩解压缩文件夹
  10. 详解一下网络广告cpc、cpm、cpl、cpa、cps、cpr的计费方法是什么
  11. cocos2d-x 定时器selector的使用 :schedule的使用
  12. HTML基础学习(二)&mdash;CSS
  13. javascript中函数声明与函数表达式的区别
  14. Filter 和 interceptor 的区别
  15. js 表单提交
  16. chrome浏览器中的百度搜索引擎总是先自动跳转到百度首页怎么办?
  17. 开源 JSON 库解析性能对比( Jackson / Json.simple / Gson )
  18. Java虚拟机(一):JVM简介
  19. docker 部署 redmine 项目管理软件
  20. zdump 命令查看时区和夏令时

热门文章

  1. jQuery事件-div的显示隐藏及鼠标的移入移出
  2. redis客户端hiredis
  3. JDBC连接数据库(一)
  4. 前端基础(JavaScript)
  5. Python笔记 #16# Pandas: Operations
  6. Python笔记 #07# NumPy 文档地址 &amp; Subsetting 2D Arrays
  7. # 20145106 《Java程序设计》第4周学习总结
  8. 20145326《Java程序设计》第二周学习总结
  9. HDU 2680 Choose the best route(多起点单终点最短路问题)题解
  10. [Pytorch]Pytorch 细节记录(转)