磁盘空间不足
block空间满了
原因:文件内容过大
排错流程
1.df -h:查看整体情况
[root@yuyingqian ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/sda3 20G 1.9G 18G 10% / devtmpfs 980M 0 980M 0% /dev tmpfs 991M 0 991M 0% /dev/shm tmpfs 991M 9.6M 981M 1% /run tmpfs 991M 0 991M 0% /sys/fs/cgroup /dev/sdb1 98M 5.3M 93M 6% /mnt /dev/sda1 197M 105M 93M 54% /boot tmpfs 199M 0 199M 0% /run/user/0
2.du -sh 一层一层查找查找到某个文件或目录(比较大)
[root@yuyingqian ~]# du -sh /usr/lib/* 0 /usr/lib/binfmt.d 0 /usr/lib/cpp 0 /usr/lib/debug 1.4M /usr/lib/dracut 816K /usr/lib/firewalld 273M /usr/lib/firmware
du 查看目录占用空间
sort
sort -n 按照数字顺序排列[root@yuyingqian ~]# seq 10|sort -n 1 2 3 4 5 6 7 8 9 10
sort -r 逆序
[root@yuyingqian ~]# seq 10|sort -rn 10 9 8 7 6 5 4 3 2 1
3.du -sh /* |sort -h
[root@yuyingqian ~]# du -sh /* |sort -rh 1.4G /usr 298M /var 95M /boot 91M /root 32M /opt 32M /etc
4.确认无误后再删除
故障模拟
[root@yuyingqian ~]# dd if=/dev/zero of=/tmp/100k bs=1k count=100 100+0 records in 100+0 records out 102400 bytes (102 kB) copied, >0.000404326 s, 253 MB/s [root@yuyingqian ~]# mkfs.ext4 /tmp/100k mke2fs 1.42.9 (28-Dec-2013) /tmp/100k is not a block special device. Proceed anyway? (y,n) y [root@yuyingqian ~]# mount /tmp/100k /app/log/
inode空间满了
[root@yuyingqian /app/log]# touch {1..10}.txt touch: cannot touch ‘6.txt’: No space left on device touch: cannot touch ‘7.txt’: No space left on device touch: cannot touch ‘8.txt’: No space left on device touch: cannot touch ‘9.txt’: No space left on device touch: cannot touch ‘10.txt’: No space left on device [root@yuyingqian /app/log]# df -h /app/log/ Filesystem Size Used Avail Use% Mounted on /dev/loop0 93K 14K 72K 17% /app/log [root@yuyingqian /app/log]# df -i /app/log/ Filesystem Inodes IUsed IFree IUse% Mounted on /dev/loop0 16 16 0 100% /app/log
Linux彻底删除一个文件的条件:
1.没有入口(rm硬连接数为0)
2.没有人使用这个文件(进程调用数为0) lsof 查看进程[root@yuyingqian ~]# lsof |grep alex.txt tail 12775 root 3r REG 8,3 0 33579581 /root/alex.txt [root@yuyingqian ~]# lsof |grep alex.txt vim 12803 root 4u REG 8,3 4096 33579602 /root/.alex.txt.swp
彻底删除进程:systemctl restart rsyslog.service abrtd.service
[root@yuyingqian ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/sda3 20G 6.5G 13G 34% / [root@yuyingqian ~]# systemctl restart rsyslog.service abrtd.service [root@yuyingqian ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/sda3 20G 1.9G 18G 10% /
block满了 文件没有彻底删除 磁盘空间不足
原因:
文件彻底删除条件
1.文件的硬连接数为0(没有入口)
2.文件进程调用数为0(重启服务)
df -h满了 du -sh /* 没有满
lsof标记表示:硬连接数为0 进程调用数不为0
lsof |grep delete
解决:重启服务systemctl restart rsyslog.service abrtd.service
JAVA故障案例
Java大量占用内存,占用swap
添加swap
创建指定大小文件200mdd if=/dev/zero of=/tmp/200m bs=1M count=200 200+0 records in 200+0 records out 209715200 bytes (210 MB) copied, 0.802388 s, 261 MB/s
将文件转变为swap文件
[root@yuyingqian ~]# mkswap /tmp/500m mkswap: /tmp/500m: warning: wiping old xfs signature. Setting up swapspace version 1, size = 102396 KiB no label, UUID=585a818c-54cb-4d37-b473-c7e144dc8cc8
激活swap(挂载)(修改权限为600)
[root@yuyingqian ~]# swapon /tmp/500MM swapon: /tmp/500MM: insecure permissions 0644, 0600 suggested.
关闭swap
[root@yuyingqian ~]# free -h total used free shared buff/cache available Mem: 1.9G 232M 540M 2.3M 1.2G 1.5G Swap: 1.1G 8.0M 1.1G [root@yuyingqian ~]# swapoff /tmp/500m [root@yuyingqian ~]# free -h total used free shared buff/cache available Mem: 1.9G 232M 540M 2.3M 1.2G 1.5G Swap: 999M 8.0M 991M
显示系统的swap由什么组成 swapon -s
[root@yuyingqian ~]# swapon -s Filename Type Size Used Priority /dev/sda2 partition 819196 8228 -2 /tmp/200m file 204796 0 -3
永久挂载swap
vim /etc/rc.local
写入 swapon /tmp/500m
文件系统:文件在磁盘中如何存放,存放规则
CentOS 7 默认的文件系统xfs
CentOS 6 默认的文件系统ext4
CentOS 5 默认的文件系统ext3
交换分区 swap
内存文件系统 tmpfs 存放的数据是在内存中 用于加速或存放缓存
SUSE reiserFS
应用场景
reiserfs大量小文件业务首选reiserfs(100K以内), 单独安装。
xfs有的门户的数据库MySQL业务会选择xfs。
ext4 视频下载,流媒体,数据库,小文件业务也OK,可以用默认的。
ext2 没有日志(不是messages cron secure),蓝汛、网宿的cache业务,CDN 网站加速服务的。
swap 交换分区 内存不足临时充当内存
tmpfs 用于加速或存放缓存