2020-07-03 10:29
38.21.226Web服务器磁盘满故障
问题:
硬盘显示被写满,但是用du -sh /*查看时占用硬盘空间之和还远小于硬盘大小,即找不到硬盘分区是怎么被写满的。
今天下午接到同事紧急求助,说生产线服务器硬盘满了。该删的日志都删掉了。可空间还是满的,情况危急啊。这个问题,在多年以前直接和间接的遇到过1-2次。以前太懒惰了,这次记录下来和大家分享。
相关日志如下:
█ 查看硬盘分区大小
1 [root@www ~]# cat /etc/redhat-release 2 CentOS release 6.4 (Final) 3 [root@www ~]# df -h 4 Filesystem Size Used Avail Use% Mounted on 5 /dev/sda3 117G 111G 0 100% / 6 /dev/sda1 145M 12M 126M 9% /boot 7 tmpfs 3.0G 0 3.0G 0% /dev/shm
这是一台web服务器(apache+tomcat+mysql)
通过dh -h命令查看 总大小117G,使用了111G
1 [root@www /]# fdisk -l 2 3 Disk /dev/sda: 146.8 GB, 146815733760 bytes 4 255 heads, 63 sectors/track, 17849 cylinders 5 Units = cylinders of 16065 * 512 = 8225280 bytes 6 7 Device Boot Start End Blocks Id System 8 /dev/sda1 * 1 19 152586 83 Linux 9 /dev/sda2 20 2108 16779892+ 82 Linux swap / Solaris 10 /dev/sda3 2109 17849 126439582+ 83 Linux 11 [root@www /]# fdisk -l /dev/sda3 12 13 Disk /dev/sda3: 129.4 GB, 129474132480 bytes 14 255 heads, 63 sectors/track, 15741 cylinders 15 Units = cylinders of 16065 * 512 = 8225280 bytes 16 17 Disk /dev/sda3 doesn't contain a valid partition table
==========================================================================================
█ 使用du命令查看到底哪些目录占用了空间
[root@www /]# du -sh /* 8.6M /bin 6.1M /boot 2.8G /data ===》这里是DB目录 124K /dev 60M /etc 1.6G /home ===》这里是日志目录 120M /lib 24M /lib64 16K /lost+found 8.0K /media 0 /misc 12K /mnt 0 /net 8.0K /opt 0 /proc 614M /root 35M /sbin 8.0K /selinux 24K /server 8.0K /srv 0 /sys 24K /tmp 2.5G /usr 29G /var ==》这里是www目录
可以看出,上面所有目录之和 远小于总的空间占用111G,是什么占用了硬盘,还查不到呢?
38.21.226.1
38.21.226.2
38.21.226.3
38.21.226.4
38.21.226.5
38.21.226.6
38.21.226.7
38.21.226.8
38.21.226.9
38.21.226.10
38.21.226.11
38.21.226.12
38.21.226.13
38.21.226.14
38.21.226.15
38.21.226.16
38.21.226.17
38.21.226.18
38.21.226.19
38.21.226.20
38.21.226.21
38.21.226.22
38.21.226.23
38.21.226.24
38.21.226.25
38.21.226.26
38.21.226.27
38.21.226.28
38.21.226.29
38.21.226.30
38.21.226.31
38.21.226.32
38.21.226.33
38.21.226.34
38.21.226.35
38.21.226.36
38.21.226.37
38.21.226.38
38.21.226.39
38.21.226.40
38.21.226.41
38.21.226.42
38.21.226.43
38.21.226.44
38.21.226.45
38.21.226.46
38.21.226.47
38.21.226.48
38.21.226.49
38.21.226.50
38.21.226.51
38.21.226.52
38.21.226.53
38.21.226.54
38.21.226.55
38.21.226.56
38.21.226.57
38.21.226.58
38.21.226.59
38.21.226.60
38.21.226.61
38.21.226.62
38.21.226.63
38.21.226.64
38.21.226.65
38.21.226.66
38.21.226.67
38.21.226.68
38.21.226.69
38.21.226.70
38.21.226.71
38.21.226.72
38.21.226.73
38.21.226.74
38.21.226.75
38.21.226.76
38.21.226.77
38.21.226.78
38.21.226.79
38.21.226.80
38.21.226.81
38.21.226.82
38.21.226.83
38.21.226.84
38.21.226.85
38.21.226.86
38.21.226.87
38.21.226.88
38.21.226.89
38.21.226.90
38.21.226.91
38.21.226.92
38.21.226.93
38.21.226.94
38.21.226.95
38.21.226.96
38.21.226.97
38.21.226.98
38.21.226.99
38.21.226.100
38.21.226.101
38.21.226.102
38.21.226.103
38.21.226.104
38.21.226.105
38.21.226.106
38.21.226.107
38.21.226.108
38.21.226.109
38.21.226.110
38.21.226.111
38.21.226.112
38.21.226.113
38.21.226.114
38.21.226.115
38.21.226.116
38.21.226.117
38.21.226.118
38.21.226.119
38.21.226.120
38.21.226.121
38.21.226.122
38.21.226.123
38.21.226.124
38.21.226.125
38.21.226.126
38.21.226.127
38.21.226.128
38.21.226.129
38.21.226.130
38.21.226.131
38.21.226.132
38.21.226.133
38.21.226.134
38.21.226.135
38.21.226.136
38.21.226.137
38.21.226.138
38.21.226.139
38.21.226.140
38.21.226.141
38.21.226.142
38.21.226.143
38.21.226.144
38.21.226.145
38.21.226.146
38.21.226.147
38.21.226.148
38.21.226.149
38.21.226.150
38.21.226.151
38.21.226.152
38.21.226.153
38.21.226.154
38.21.226.155
38.21.226.156
38.21.226.157
38.21.226.158
38.21.226.159
38.21.226.160
38.21.226.161
38.21.226.162
38.21.226.163
38.21.226.164
38.21.226.165
38.21.226.166
38.21.226.167
38.21.226.168
38.21.226.169
38.21.226.170
38.21.226.171
38.21.226.172
38.21.226.173
38.21.226.174
38.21.226.175
38.21.226.176
38.21.226.177
38.21.226.178
38.21.226.179
38.21.226.180
38.21.226.181
38.21.226.182
38.21.226.183
38.21.226.184
38.21.226.185
38.21.226.186
38.21.226.187
38.21.226.188
38.21.226.189
38.21.226.190
38.21.226.191
38.21.226.192
38.21.226.193
38.21.226.194
38.21.226.195
38.21.226.196
38.21.226.197
38.21.226.198
38.21.226.199
38.21.226.200
38.21.226.201
38.21.226.202
38.21.226.203
38.21.226.204
38.21.226.205
38.21.226.206
38.21.226.207
38.21.226.208
38.21.226.209
38.21.226.210
38.21.226.211
38.21.226.212
38.21.226.213
38.21.226.214
38.21.226.215
38.21.226.216
38.21.226.217
38.21.226.218
38.21.226.219
38.21.226.220
38.21.226.221
38.21.226.222
38.21.226.223
38.21.226.224
38.21.226.225
38.21.226.226
38.21.226.227
38.21.226.228
38.21.226.229
38.21.226.230
38.21.226.231
38.21.226.232
38.21.226.233
38.21.226.234
38.21.226.235
38.21.226.236
38.21.226.237
38.21.226.238
38.21.226.239
38.21.226.240
38.21.226.241
38.21.226.242
38.21.226.243
38.21.226.244
38.21.226.245
38.21.226.246
38.21.226.247
38.21.226.248
38.21.226.249
38.21.226.250
38.21.226.251
38.21.226.252
38.21.226.253
38.21.226.254
解答:
出现上面问题原因:
在apache/tomcat服务在运行状态下,清空了运行服务的日志,这里是清理了当天或正在写入的apache及tomcat的日志文件,从而导致了上面问题。(有关原理细节见下文)引申下:一般情况下,大多数服务(包括脚本)在运行时,是不能删除当前正在写入的日志文件的。这点请大家要记牢。
本文的解决办法:
查找机器自身的服务,然后重起apache和tomcat。
重起apache后:
1 [root@www ]# df -h 2 Filesystem Size Used Avail Use% Mounted on 3 /dev/sda3 117G 109G 2.3G 98% / 4 /dev/sda1 145M 12M 126M 9% /boot 5 tmpfs 3.0G 0 3.0G 0% /dev/shm
重起tomcat后:
[root@www ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/sda3 117G 38G 74G 34% / /dev/sda1 145M 12M 126M 9% /boot tmpfs 3.0G 0 3.0G 0% /dev/shm
上面问题原理分析:
1、这是一个文件系统层面的技术 2、当前 access.log 日志正被 apache 进程占用。通过 rm 命令删除 access.log,实际只删除了文件名(该日志文件应用记数不 0,因此空间不会被释放) 3、rm 命令删除了 access.log 后 apache 依然写日志到 access.log 中,当开启 apache 进程是,已经通过 access.log 定位到文件的 inode 了就是说再写日志是不通过 access.log,因此,即使删除了 access.log,apache 依然写日志到 access.log 所在的 inode 节点,所以导致硬盘空间增加。 4、因为删除了 access.log,所以,我们人类就看不到相关文件了,也就是说找不到该文件,du 也查不到。所以就会发现磁盘满而看不到什么文
阅读本文的人还阅读: