Tomcat 空间占用增长异常分析一例

博客围绕RHEL AS 3.0系统中/opt空间不断增长,而/home空间无变化的问题展开。排除df和du命令显示差异因素后,分析/proc信息无果。猜测是tomcat打开文件描述符未关闭所致,用lsof分析确认/opt/tomcat/logs/catalina.out (deleted)项占用空间疯长,还提及可能是Tomcat的Bug。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

有朋友问:

RHEL AS 3.0 上,df -k发现 /opt 在不断增长,而在 /home 里面 du -sh 却发现空间大小没有变化, /opt 下面是一个网站,把 tomcat 停了就不会增长了。这是怎么回事?

第一个感觉以为是 df 和 du 这两个命令显示的有差异。没错,的确有差异。但是,现在的主要问题是 df -k 命令显示的空间在增长。分析研究了 /proc 下相关进程对应的目录下的信息,未发现异常。图劳无功。

猜测tomcat 打开了某些文件描述符,虽然文件已经修改了,但是文件描述符如果没有关闭的话,一样会占用空间甚至增大空间的占用。用 lsof(LiSt Opened File) 进行分析。

注:对一些特定的路径进行了一点处理。首先获取/opt 对应的设备名字。

# lsof /dev/sdb2 | sort +6nr | head -5
java      21247 root    1w   REG  104,6 96538188 917506 /opt/tomcat/logs/catalina.out (deleted)
java      21247 root    2w   REG  104,6 96538188 917506 /opt/tomcat/logs/catalina.out (deleted)
java      21247 root  mem    REG  104,6  1394764 901145 /opt/tomcat/common/lib/nls_charset12.jar
java      21247 root  mem    REG  104,6  1394295 901143 /opt/tomcat/common/lib/nls_charset11.jar
java      21247 root  mem    REG  104,6  1159907 901140 /opt/tomcat/common/lib/classes12dms.jar
[root@stat root]#

经确认,/opt/tomcat/logs/catalina.out (deleted) 项占用的空间在疯狂增长。建议跟踪该文件的变化。

# tail -f /opt/tomcat/logs/catalina.out
java.net.UnknownHostException: auto at
java.net.InetAddress.getAllByName0(InetAddress.java:1016) at
java.net.InetAddress.getAllByName0(InetAddress.java:981) at
java.net.InetAddress.getAllByName(InetAddress.java:975) at
java.net.InetAddress.getByName(InetAddress.java:889)
org.apache.catalina.cluster.mcast.McastMember.getData(McastMember.jav a:122) at
org.apache.catalina.cluster.mcast.McastServiceImpl.send(McastServiceI mpl.java:221) at
org.apache.catalina.cluster.mcast.McastServiceImpl$SenderThread.run(M castServiceImpl.java:259)

注意到

java.net.InetAddress.getAllByName0(InetAddress.java:1016

测试可能是 Tomcat 的 Bug,把 java.net.InetAddress.getAllByName0(InetAddress.java:1016 作为搜索短语查找一下,果不其然:

http://issues.apache.org/bugzilla/show_bug.cgi?id=27259

Updated:2005/12/12 . 空间不释放的问题:

When you open a file, you get a pointer. Subsequent writes to this file
references this file pointer. The write call does not check to see if the file
is there or not. It just writes to the specified number of characters starting
at a predetermined location. Regardless of whether the file exist or not, disk
blocks are used by the write operation.
The df command reports the number of disk blocks used while du goes through the
file structure and and reports the number of blocks used by each directory. As
far as du is concerned, the file used by the process does not exist, so it does
not report blocks used by this phantom file. But df keeps track of disk blocks
used, and it reports the blocks used by this phantom file.

下载 LSOF 工具的使用文档

EOF

Google+
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值