挂载新磁盘
故障
云服务器的业务出现故障,表现为上传图片失败,经过排查,由于磁盘的空间占满导致的文件写入失败。
服务器配置为8核心16GB,100GB系统盘和600GB数据盘。登录服务器查看,100GB挂载到/目录,600GB数据盘没有挂载没使用。
思路
解决思路,将600GB数据盘添加到逻辑卷,使用LVM方便以后扩容。挂载数据盘,迁移/OPT的数据到数据盘,移除/OPT目录,将数据盘挂载到/OPT,实现腾笼不换鸟。
注意事项
- 操作前备份数据/打快照
- 数据迁移操作需要业务停机,否则目录无法切换挂载。
- 记得在/etc/fstab添加数据分区的挂载。
- 谨慎操作,以防数据损坏。
查看磁盘容量
[root@ecs-3c08 images]# fdisk -l
Disk /dev/vda: 107.4 GB, 107374182400 bytes, 209715200 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000103c6
Device Boot Start End Blocks Id System
/dev/vda1 2048 8390655 4194304 82 Linux swap / Solaris
/dev/vda2 * 8390656 209715166 100662255+ 83 Linux
Disk /dev/vdb: 644.2 GB, 644245094400 bytes, 1258291200 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
/dev/vdb磁盘644.2GB
查看目录占用空间
[root@ecs-3c08 tcsf]# du -h --max-depth 1 ./ 2>/dev/null
20K ./nginx-server
4.8M ./nginx-wx
111M ./backend-service
9.7M ./nginx-manager
74G ./images
4.0K ./files
12K ./nginx-proxy
74G ./
[root@ecs-3c08 images]# pwd
/opt/project/tcsf/images
查看块存储设备
[root@localhost ~]# lsblk -pf
NAME FSTYPE LABEL UUID MOUNTPOINT
/dev/sda
├─/dev/sda1 xfs bd252330-2540-4705-bafa-0dc93532ab32 /boot
└─/dev/sda2 LVM2_member VYcAge-yo5K-QY8U-DcPD-VcMb-MbRq-IaLChR
├─/dev/mapper/centos-root xfs 68864fee-0b10-4e28-9a80-11c18b4899b7 /
└─/dev/mapper/centos-swap swap 385f00ee-abb2-4103-b13f-41fdc5b87123 [SWAP]
/dev/vdb
将物理磁盘初始化为物理卷PV
[root@localhost ~]# pvcreate /dev/vdb
Physical volume "/dev/vdb" successfully created.
[root@localhost ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/sda2 centos lvm2 a-- <19.00g 0
/dev/sdb lvm2 --- 1.00g 1.00g
创建卷组VG,将PV加入到VG中
[root@localhost ~]# vgcreate data /dev/vdb
Volume group "data" successfully created
[root@localhost ~]# vgs
VG #PV #LV #SN Attr VSize VFree
centos 1 2 0 wz--n- <19.00g 0
data 1 0 0 wz--n- 1020.00m 1020.00m
基于VG创建逻辑卷LV
-
-l:指定使用多少个VG中的LE创建LV,[%{VG|PVS|FREE}]
-
-L:指定LV大小
-
-n:指定LV名称
-
-p:指定权限,r为只读,rw为读写
[root@localhost ~]# lvcreate -n opt -l 100%vg data
Logical volume "opt" created.
[root@localhost ~]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
root centos -wi-ao---- <17.00g
swap centos -wi-ao---- 2.00g
opt data -wi-a----- 1020.00m
为逻辑卷创建文件系统
[root@localhost ~]# mkfs.xfs /dev/mapper/data-opt
meta-data=/dev/mapper/data-opt isize=512 agcount=4, agsize=65280 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=261120, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal log bsize=4096 blocks=855, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
[root@localhost ~]# lsblk -pf
NAME FSTYPE LABEL UUID MOUNTPOINT
/dev/sda
├─/dev/sda1 xfs bd252330-2540-4705-bafa-0dc93532ab32 /boot
└─/dev/sda2 LVM2_member VYcAge-yo5K-QY8U-DcPD-VcMb-MbRq-IaLChR
├─/dev/mapper/centos-root xfs 68864fee-0b10-4e28-9a80-11c18b4899b7 /
└─/dev/mapper/centos-swap swap 385f00ee-abb2-4103-b13f-41fdc5b87123 [SWAP]
/dev/sdb LVM2_member EczTmf-bTPk-rRIr-C85A-hvcT-WZSn-Vxwt74
└─/dev/mapper/data-opt xfs 94b7ad5c-8e3a-4b5e-865a-4eb1fe717284
创建挂载点,挂载LV
[root@localhost /]# mkdir opt1
[root@localhost /]# mount /dev/mapper/data-opt /opt1
[root@localhost /]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 20G 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 19G 0 part
├─centos-root 253:0 0 17G 0 lvm /
└─centos-swap 253:1 0 2G 0 lvm [SWAP]
sdb 8:16 0 1G 0 disk
└─data-opt 253:2 0 1020M 0 lvm /opt1
迁移文件
cp -aR /opt/* /opt1/
迁移挂载目录
[root@localhost /]# mv /opt /opt2
[root@localhost /]# umount /opt1/
[root@localhost /]# ls /opt1/
[root@localhost /]# mkdir /opt
[root@localhost /]# mount /dev/mapper/data-opt /opt
[root@localhost /]# ls /opt/
1 2
[root@localhost /]# cat /opt/1
new
开机自动挂载
在/etc/fstab添加自动挂载
#
# /etc/fstab
# Created by anaconda on Fri Mar 6 22:31:53 2020
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/centos-root / xfs defaults 0 0
UUID=bd252330-2540-4705-bafa-0dc93532ab32 /boot xfs defaults 0 0
/dev/mapper/centos-swap swap swap defaults 0 0
/dev/mapper/data-opt /opt xfs defaults 0 0
网友评论