前言:最近部署一个项目,甲方使用虚拟化平台,给的服务器都是虚拟化克隆的机器,操作系统安装时默认的分区,现状是根分区只有50G,部署的时候使用软连接创建的部署目录,但是后续升级的同事没有注意,就把部署直接放在根分区,导致近期数据同步时log文件大,使用的log日志删除脚本任务计划未到执行执行时间服务日志文件就把磁盘占满了,处理如下。

 一、系统环境:
操作系统:Centos_x64 6.5
内核版本:2.6.32-431.el6.X86_64
磁盘格式:EXT4

二、现有分区情况与说明

df -h #查看当前分区 Filesystem Size Used Avail Use% Mounted on /dev/mapper/VolGroup-lv_root 50G 17G 31G 36% / tmpfs 7.8G 0 7.8G 0% /dev/shm /dev/sda1 485M 33M 427M 8% /boot /dev/mapper/VolGroup-lv_home 435G 9.7G 404G 3% /home

  说明:可以清楚的看到两个lv卷的分区VolGroup-lv_root挂载为了根分区50G,VolGroup-lv_home挂载为了/home分区,home分区比较大,却没有被使用。

三、释放/home分区的占用并卸载/home分区
1、以为使用fuser -m /home就可以完成但是执行后卸载仍提示/home有占用。情况如下:

# fuser -m /home /home: 24033ce 
# umount /home umount: /home: device is busy. (In some cases useful info about processes that use the device is found by lsof(8) or fuser(1))

2、检查占用的文件,发现甲方提供的系统里有金山的防护软件,将软件进程杀掉后卸载/home分区正常:

# lsof | grep /home --检查发现占用的是金山的防护软件直接运行了kiil -9 24033 KANLinuxC 24033 root cwd DIR 253,2 4096 5636103 /home/kingsoft/kavnet KANLinuxC 24033 root txt REG 253,2 1645332 5636130 /home/kingsoft/kavnet/KANMainModule KANLinuxC 24033 root mem REG 253,2 1369600 5636263 /home/kingsoft/kavnet/libcrypto.so.6 KANLinuxC 24033 root mem REG 253,2 323320 5636276 /home/kingsoft/kavnet/libssl.so.6 KANLinuxC 24033 root mem REG 253,2 34487 5636129 /home/kingsoft/kavnet/KANLocalComm.so KANLinuxC 24033 root mem REG 253,2 626402 5636131 /home/kingsoft/kavnet/KANNetComm.so KANLinuxC 24033 root mem REG 253,2 163342 5636265 /home/kingsoft/kavnet/libjson.so KANLinuxC 24033 root 3w REG 253,2 789537 5636280 /home/kingsoft/kavnet/neterror.log KANLinuxC 24033 root 10w REG 253,2 789537 5636280 /home/kingsoft/kavnet/neterror.log KANLinuxC 24033 root 11w REG 253,2 789537 5636280 /home/kingsoft/kavnet/neterror.log KANLinuxC 24033 root 13w REG 253,2 789537 5636280 /home/kingsoft/kavnet/neterror.log KANLinuxC 24033 root 20w REG 253,2 789537 5636280 /home/kingsoft/kavnet/neterror.log
# umount /home --重新卸载未在报错 未在报错。

三、缩减VolGroup-lv_home这个LV的空间
1、检查这个LV分区的信息是否正常;

# e2fsck -f /dev/mapper/VolGroup-lv_home e2fsck 1.41.12 (17-May-2010) 第一步: 检查inode,块,和大小 第二步: 检查目录结构 第3步: 检查目录连接性 Pass 4: Checking reference counts 第5步: 检查簇概要信息 /dev/mapper/VolGroup-lv_home: 5779/28950528 files (2.2% non-contiguous), 4334183/115775488 blocks

2、调整VolGroup-lv_home分区大小;

#resize2fs -p /dev/mapper/VolGroup-lv_home 80G resize2fs 1.41.12 (17-May-2010) Resizing the filesystem on /dev/mapper/VolGroup-lv_home to 20971520 (4k) blocks. Begin pass 2 (max = 50904) 正在重定位块 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX Begin pass 3 (max = 3534) 正在扫描inode表 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX Begin pass 4 (max = 838) 正在更新inode引用 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX The filesystem on /dev/mapper/VolGroup-lv_home is now 20971520 blocks long.

3、重新挂载home分区并检查空间大小,可以发现/home的空间已经变小;

# mount /home # df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/VolGroup-lv_root 50G 17G 31G 36% / tmpfs 7.8G 0 7.8G 0% /dev/shm /dev/sda1 485M 33M 427M 8% /boot /dev/mapper/VolGroup-lv_home 79G 9.6G 66G 13% /home

4、将VolGroup-lv_home缩减出来的分区设置为空闲分区;

# lvreduce -L 80G /dev/mapper/VolGroup-lv_home WARNING: Reducing active and open logical volume to 80.00 GiB THIS MAY DESTROY YOUR DATA (filesystem etc.) Do you really want to reduce lv_home? [y/n]: y Reducing logical volume lv_home to 80.00 GiB Logical volume lv_home successfully resized

5、检查空闲出的空间Free PE已经空出了361G;

# vgdisplay --- Volume group --- VG Name VolGroup System ID Format lvm2 Metadata Areas 1 Metadata Sequence No 5 VG Access read/write VG Status resizable MAX LV 0 Cur LV 3 Open LV 3 Max PV 0 Cur PV 1 Act PV 1 VG Size 499.51 GiB PE Size 4.00 MiB Total PE 127874 Alloc PE / Size 35292 / 137.86 GiB Free PE / Size 92582 / 361.65 GiB VG UUID Ur7bJ4-hQKi-xx4R-f9Qt-INvG-fjBf-zcvJ4n

四、将缩减出的空间增加给VolGroup-lv_root这个LV
1、给VolGroup-lv_root增加空间;

# lvresize --size +361G /dev/VolGroup/lv_root Extending logical volume lv_root to 410.71 GiB Logical volume lv_root successfully resized

2、让系统重新识别VolGroup-lv_root增加的空间;

# resize2fs -p /dev/mapper/VolGroup-lv_root resize2fs 1.41.12 (17-May-2010) Filesystem at /dev/mapper/VolGroup-lv_root is mounted on /; on-line resizing required old desc_blocks = 4, new_desc_blocks = 26 Performing an on-line resize of /dev/mapper/VolGroup-lv_root to 107665408 (4k) blocks. The filesystem on /dev/mapper/VolGroup-lv_root is now 107665408 blocks long.

3、检查最终结果,确认操作成功;

# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/VolGroup-lv_root 405G 23G 362G 6% / tmpfs 7.8G 0 7.8G 0% /dev/shm /dev/sda1 485M 33M 427M 8% /boot /dev/mapper/VolGroup-lv_home 79G 3.5G 72G 5% /home