103 views

在linux系统lvm中,lv使用空间的调整以及其优化

By | 2019年2月27日

云漫网络致力于高防CDN,网站加速等服务,有着丰富的高防经验,今天由我们的技术小张给大家分享一些必备干货:

一、环境配置
操作系统: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

三、卸载/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

三、缩减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

今天的分享就到这了,感谢大家,希望对大伙有帮助。

本文转载于:http://win-man.com
本文关键词:高防CDN    加速CDN     免备案CDN
作者:网站高防专家

发表评论

电子邮件地址不会被公开。 必填项已用*标注