目录
目录
今天发现服务器好多服务停掉了,登陆服务器也提示设备上没有空间 df -h 查看一下系统空间
[root@bd tmp]# df -h
文件系统 容量 已用 可用 已用% 挂载点
devtmpfs 63G 0 63G 0% /dev
tmpfs 63G 28K 63G 1% /dev/shm
tmpfs 63G 368M 63G 1% /run
tmpfs 63G 0 63G 0% /sys/fs/cgroup
/dev/mapper/centos-root 50G 50G 20K 100% /
/dev/sda2 1014M 181M 834M 18% /boot
/dev/sda1 200M 12M 189M 6% /boot/efi
/dev/mapper/centos-home 17T 3.3G 17T 1% /home
tmpfs 13G 0 13G 0% /run/user/0
发现centos-root目录50G已经用完,只剩下20k了。。。
可通过
du -h -x --max-depth=1
查看对应文件占用情况
可以调整depth大小深入查看
我这里显示/tmp/logs 占用比较大,可以先清除一下日志等
二、root目录扩容
备份home分区文件
tar cvf /tmp/home.tar /home
卸载/home
如果无法卸载,先终止使用/home文件系统的进程
[root@bd logs]# umount /home
umount: /home:目标忙。
(有些情况下通过 lsof(8) 或 fuser(1) 可以
找到有关使用该设备的进程的有用信息)
[root@bd logs]# fuser -km /home/
/home: 243026
再次执行 umount /home,成功!
删除/home所在的lv
lvremove /dev/mapper/centos-home
[root@bd logs]# lvremove /dev/mapper/centos-home
Do you really want to remove active logical volume centos/home? [y/n]: y
Logical volume "home" successfully removed
扩展/root所在的lv
lvextend -L +5T /dev/mapper/centos-root(根据实际扩展空间决定)
[root@bd logs]# lvextend -L +5T /dev/mapper/centos-root
Size of logical volume centos/root changed from 50.00 GiB (12800 extents) to <5.05 TiB (1323520 extents).
Logical volume centos/root successfully resized.
扩展/root文件系统
xfs_growfs /dev/mapper/centos-root
[root@bd logs]# xfs_growfs /dev/mapper/centos-root
meta-data=/dev/mapper/centos-root isize=512 agcount=16, agsize=819200 blks
= sectsz=4096 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=13107200, imaxpct=25
= sunit=64 swidth=192 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal bsize=4096 blocks=6400, version=2
= sectsz=4096 sunit=1 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 13107200 to 1355284480
重新创建home lv
(创建时计算好剩余的磁盘容量,建议比剩余小1G左右)
[root@bd ~]# lvcreate -L 11.2T -n /dev/mapper/centos-home
Rounding up size to full physical extent 11.20 TiB
Logical volume "home" created.
创建文件系统
mkfs.xfs /dev/mapper/centos-home
[root@bd ~]# mkfs.xfs /dev/mapper/centos-home
meta-data=/dev/mapper/centos-home isize=512 agcount=32, agsize=93952448 blks
= sectsz=4096 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=3006477312, imaxpct=5
= sunit=64 swidth=192 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal log bsize=4096 blocks=521728, version=2
= sectsz=4096 sunit=1 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
挂载home
mount /dev/mapper/centos-home
home文件恢复
tar xvf /tmp/home.tar -C /home/
再次查看
[root@bd ~]# df -h
文件系统 容量 已用 可用 已用% 挂载点
devtmpfs 63G 0 63G 0% /dev
tmpfs 63G 28K 63G 1% /dev/shm
tmpfs 63G 11M 63G 1% /run
tmpfs 63G 0 63G 0% /sys/fs/cgroup
/dev/mapper/centos-root 5.1T 18G 5.1T 1% /
/dev/sda2 1014M 194M 821M 20% /boot
/dev/sda1 200M 12M 189M 6% /boot/efi
tmpfs 13G 0 13G 0% /run/user/0
/dev/mapper/centos-home 12T 3.6G 12T 1% /home
三、lvm 在线扩容
如果是lvm的话,磁盘有余量可以直接在线扩容,如下vda磁盘有1T容量,但是现在实际用起来只有100G
[root@m72 ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
fd0 2:0 1 4K 0 disk
sr0 11:0 1 18M 0 rom
vda 252:0 0 1T 0 disk
├─vda1 252:1 0 500M 0 part /boot
└─vda2 252:2 0 119.5G 0 part
├─centos-swap 253:0 0 16G 0 lvm
└─centos-root 253:1 0 103.5G 0 lvm /
[root@m72 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 104G 104G 20K 100% /
devtmpfs 32G 0 32G 0% /dev
tmpfs 32G 0 32G 0% /dev/shm
tmpfs 32G 11M 32G 1% /run
tmpfs 32G 0 32G 0% /sys/fs/cgroup
/dev/vda1 497M 159M 339M 32% /boot
tmpfs 6.3G 0 6.3G 0% /run/user/0
首先给vda增加新分区
1.将硬盘分区,基本默认即可
[root@m72 ~]# fdisk /dev/vda
Welcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help): n
Partition type:
p primary (2 primary, 0 extended, 2 free)
e extended
Select (default p): p
Partition number (3,4, default 3): 3
First sector (251658240-2147483647, default 251658240):
Using default value 251658240
Last sector, +sectors or +size{K,M,G} (251658240-2147483647, default 2147483647):
Using default value 2147483647
Partition 3 of type Linux and of size 904 GiB is set
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
需要 partprobe 重新加载
[root@m72 ~]# partprobe
可以看到增加了vda3分区
[root@m72 ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
fd0 2:0 1 4K 0 disk
sr0 11:0 1 18M 0 rom
vda 252:0 0 1T 0 disk
├─vda1 252:1 0 500M 0 part /boot
├─vda2 252:2 0 119.5G 0 part
│ ├─centos-swap 253:0 0 16G 0 lvm
│ └─centos-root 253:1 0 103.5G 0 lvm /
└─vda3 252:3 0 904G 0 part
将新的分区卷做成PV物理卷
[root@m72 ~]# pvcreate /dev/vda3
Physical volume "/dev/vda3" successfully created.
将新的物理卷加入到现有逻辑卷的卷组中
##1.查看当前逻辑卷的卷组
[root@m72 log]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
root centos -wi-ao---- <103.51g
swap centos -wi-a----- 16.00g
[root@m72 log]# vgs
VG #PV #LV #SN Attr VSize VFree
centos 1 2 0 wz--n- <119.51g 0
##2.将新物理卷加入到centos的vg卷组中
[root@m72 log]# vgextend centos /dev/vda3
Volume group "centos" successfully extended
## 3.从VFree中可以看到当前空余空间大小,下面就可以给逻辑卷扩容了。
[root@m72 log]# lvextend -l +100%FREE /dev/centos/root
Size of logical volume centos/root changed from <103.51 GiB (26498 extents) to 1007.50 GiB (257921 extents).
Logical volume centos/root successfully resized.
执行xfs_growfs / ,重新加载挂载分区的大小(xfs_growfs 为xfs文件系统使用,mount里可以看到)
[root@m72 ops]# xfs_growfs /
再次查看
[root@m72 ops]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 1008G 22G 987G 3% /
devtmpfs 32G 0 32G 0% /dev
tmpfs 32G 0 32G 0% /dev/shm
tmpfs 32G 11M 32G 1% /run
tmpfs 32G 0 32G 0% /sys/fs/cgroup
/dev/vda1 497M 159M 339M 32% /boot
tmpfs 6.3G 0 6.3G 0% /run/user/0