zoukankan      html  css  js  c++  java
  • 生产磁盘故障案例

    1、Inode被占满,导致磁盘有可用的剩余空间也无法继续使用

    • 使用dd if=/dev/zero of=/root/disk bs=1K count=1024创建1M的文件

    [root@localhost ~]# dd if=/dev/zero of=/root/disk bs=1K count=1024
    1024+0 records in
    1024+0 records out
    1048576 bytes (1.0 MB, 1.0 MiB) copied, 0.00748152 s, 140 MB/s
    [root@localhost ~]# du -sh /root/disk 
    1.0M	/root/disk
    • 格式化disk,文件系统类型为ext4,指定inode大小为1024

    [root@localhost ~]# mkfs.ext4 -i 1024 /root/disk 
    mke2fs 1.44.6 (5-Mar-2019)
    
    Filesystem too small for a journal
    Discarding device blocks: done                            
    Creating filesystem with 1024 1k blocks and 1024 inodes
    
    Allocating group tables: done                            
    Writing inode tables: done                            
    Writing superblocks and filesystem accounting information: done
    
    [root@localhost ~]# blkid /root/disk
    /root/disk: UUID="920104f4-4f3b-4dfa-aae3-134f1af4494f" TYPE="ext4"
    • 创建挂载目录,挂载disk

     //创建挂载目录
     [root@localhost ~]# mkdir /date
    
     //挂载disk
    [root@localhost ~]# mount -t ext4 -o loop /root/disk /date/     // -t:指定文件系统格式;-o loop :把一个文件当成硬盘分区挂接上系统
    • 查看挂载信息

    [root@localhost ~]# df -ihT
    Filesystem            Type     Inodes IUsed IFree IUse% Mounted on
    devtmpfs              devtmpfs   222K   372  222K    1% /dev
    tmpfs                 tmpfs      226K     1  226K    1% /dev/shm
    tmpfs                 tmpfs      226K   586  226K    1% /run
    tmpfs                 tmpfs      226K    17  226K    1% /sys/fs/cgroup
    /dev/mapper/rhel-root xfs         25M   36K   25M    1% /
    /dev/nvme0n1p1        xfs        512K   301  512K    1% /boot
    /dev/sr0              iso9660       0     0     0     - /mnt
    /dev/mapper/rhel-home xfs         34M     3   34M    1% /home
    tmpfs                 tmpfs      226K     5  226K    1% /run/user/0
    /dev/loop0            ext4       1.0K    11  1013    2% /date
    
    • 在date目录里面创建10000个文件,测试inode被占满,空间却没使用完

    [root@localhost ~]# cd /date 
    [root@localhost date]# touch {1..10000}
    ..........
    touch: cannot touch '9990': No space left on device
    touch: cannot touch '9991': No space left on device
    touch: cannot touch '9992': No space left on device
    touch: cannot touch '9993': No space left on device
    touch: cannot touch '9994': No space left on device
    touch: cannot touch '9995': No space left on device
    touch: cannot touch '9996': No space left on device
    touch: cannot touch '9997': No space left on device
    touch: cannot touch '9998': No space left on device
    touch: cannot touch '9999': No space left on device
    touch: cannot touch '10000': No space left on device
    
    • 查看inode使用量

    [root@localhost date]# df -i
    Filesystem              Inodes IUsed    IFree IUse% Mounted on
    devtmpfs                226829   372   226457    1% /dev
    tmpfs                   231191     1   231190    1% /dev/shm
    tmpfs                   231191   586   230605    1% /run
    tmpfs                   231191    17   231174    1% /sys/fs/cgroup
    /dev/mapper/rhel-root 26214400 35956 26178444    1% /
    /dev/nvme0n1p1          524288   301   523987    1% /boot
    /dev/sr0                     0     0        0     - /mnt
    /dev/mapper/rhel-home 35100672     3 35100669    1% /home
    tmpfs                   231191     5   231186    1% /run/user/0
    /dev/loop0                1024  1024        0  100% /date           //空间已经占满
    
    • 查看空间使用量

    [root@localhost date]# df -h
    Filesystem             Size  Used Avail Use% Mounted on
    devtmpfs               887M     0  887M   0% /dev
    tmpfs                  904M     0  904M   0% /dev/shm
    tmpfs                  904M  8.7M  895M   1% /run
    tmpfs                  904M     0  904M   0% /sys/fs/cgroup
    /dev/mapper/rhel-root   50G  1.8G   49G   4% /
    /dev/nvme0n1p1        1014M  173M  842M  18% /boot
    /dev/sr0               7.4G  7.4G     0 100% /mnt
    /dev/mapper/rhel-home   67G  511M   67G   1% /home
    tmpfs                  181M     0  181M   0% /run/user/0
    /dev/loop0             891K   26K  794K   4% /date            //剩余794K
    

    2、Block空间即将被占满,但删除大文件也没有释放空间

    1、案例

    假设现在线上正在运行Nginx服务, Nginx产生的日志已经达到了20个G,磁盘眼看就看沾满了,请问不重启Nginx的方式如何处理

    • 删除文件,但Nginx持续占用着文件, 所以空间并不会被释放
      • rm -rf access. log
    • 正确做法如下,清空该文件即可释放文件内容
      • > access. log
  • 相关阅读:
    中位数相关
    带权并查集
    组合数相关、多重集组合数
    LIS最长上升子序列
    提高你css技能的css开发技巧
    如何让搜索引擎抓取AJAX内容?
    Javascript异步编程的4种方法
    前端自动化构建工具gulp
    前端自动化构建工具
    git使用
  • 原文地址:https://www.cnblogs.com/itwangqiang/p/13531896.html
Copyright © 2011-2022 走看看