本篇文章主要给需要对指定文件目录进行扩容或者创建LV的小白提供参考。
最近测试环境的RocketMQ总是报磁盘不足,测试环境的机器是我们自己玩的,运维不管,业务团队每次找我解决,我就使用du -h --max-depth=1尝试着删除一些无用的大文件,但是治标不治本,于是,不懂运维的开发,不是好的产品,我决定来一次扩容!
经过一阵子在知识的海洋里扑腾之后,初步了解了LVM(Logical Volume Manager)相关的一些知识:磁盘(Disk)、分区(Partition)、物理卷PV(Physical Volume)、卷组VG(Volume Group)、逻辑卷LV(Logical Volume)等等,详细的含义请自行查找专业的资料。
扩容LV
最后挂载到文件目录的存储其实是LV,所以对LV进行扩容即可,步骤大概是:
1、基于磁盘剩余的空间创建分区;
2、根据创建好的分区,创建PV;
3、将PV扩展到目标VG;
4、扩展VG中的LV;
演示如下:
先看看各个文件目录容量的使用情况:可以看到经常报磁盘满的目录neworiental使用了81%,接下来就是针对该目录进行扩容。
[root@XXGL-T-TJSYZ-REDIS-01 ~]# df -lh
Filesystem Size Used Avail Use% Mounted on
devtmpfs 16G 0 16G 0% /dev
tmpfs 16G 113M 16G 1% /dev/shm
tmpfs 16G 1.6G 15G 10% /run
tmpfs 16G 0 16G 0% /sys/fs/cgroup
/dev/mapper/vg_root-lvall 31G 12G 19G 39% /
/dev/mapper/vg_root-lvusr 10G 6.8G 3.3G 68% /usr
/dev/mapper/vg_root-lvtmp 5.0G 43M 5.0G 1% /tmp
/dev/mapper/vg_new-lvnew 60G 48G 12G 81% /neworiental
/dev/mapper/vg_new-lvbackup 5.0G 33M 5.0G 1% /backup
/dev/mapper/vg_root-lvvar 5.0G 2.2G 2.9G 43% /var
/dev/sda1 497M 219M 279M 44% /boot
tmpfs 3.2G 0 3.2G 0% /run/user/0
[root@XXGL-T-TJSYZ-REDIS-01 ~]#
查看系统中的磁盘使用情况
[root@XXGL-T-TJSYZ-REDIS-01 ~]# fdisk -l
Disk /dev/sda: 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: 0x00011297
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 1026047 512000 83 Linux
/dev/sda2 1026048 74434559 36704256 8e Linux LVM
/dev/sda3 74434560 128960511 27262976 8e Linux LVM
/dev/sda4 128960512 209715199 40377344 5 Extended
/dev/sda5 128962560 170905599 20971520 8e Linux LVM
/dev/sda6 170907648 209715199 19403776 8e Linux LVM
Disk /dev/mapper/vg_root-lvall: 33.2 GB, 33181138944 bytes, 64806912 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 /dev/mapper/vg_root-lvusr: 10.7 GB, 10737418240 bytes, 20971520 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 /dev/mapper/vg_root-lvvar: 5368 MB, 5368709120 bytes, 10485760 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 /dev/mapper/vg_root-lvtmp: 5368 MB, 5368709120 bytes, 10485760 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 /dev/sdb: 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: 0xa646c2a2
Device Boot Start End Blocks Id System
/dev/sdb1 2048 41945087 20971520 8e Linux LVM
[root@XXGL-T-TJSYZ-REDIS-01 ~]#
看这条信息:Disk /dev/sdb: 107.4 GB, 107374182400 bytes, 209715200 sectors,总共107.4G,该磁盘已经有了一个pv:/dev/sdb1,我们继续在该磁盘上建立分区。(sectors是扇面,一个扇面大小是 1* 512 = 512个字节)
[root@XXGL-T-TJSYZ-REDIS-01 ~]# fdisk /dev/sdb
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): m //先看看帮助信息
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
g create a new empty GPT partition table
G create an IRIX (SGI) partition table
l list known partition types
m print this menu
n add a new partition //正是我要使用的
o create a new empty DOS partition table
p print the partition table
q quit without saving changes
s create a new empty Sun disklabel
t change a partition's system id
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only)
Command (m for help): n //新建分区
Partition type:
p primary (1 primary, 0 extended, 3 free)
e extended
Select (default p): p //选择默认的p
Partition number (2-4, default 2): 2//定义分区编号,因为分区1已经使用了,所以默认从2开始
First sector (41945088-209715199, default 41945088): //使用默认的 直接回车
Using default value 41945088
Last sector, +sectors or +size{K,M,G} (41945088-209715199, default 209715199): +40G //定义分区的大小,别忘了加号
Partition 2 of type Linux and of size 40 GiB is set //提示分区2已设置
Command (m for help): t //创建完之后,还需要对分区进行修改
Partition number (1,2, default 2): 2 //选择刚刚创建的2
Hex code (type L to list all codes): 8e //修改分区的类型为8e,对应Linux LVM类型
Changed type of partition 'Linux' to 'Linux LVM'
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.
[root@XXGL-T-TJSYZ-REDIS-01 ~]# partprobe //刷新分区表
[root@XXGL-T-TJSYZ-REDIS-01 ~]#
经过上边的操作,使用fdisk -l 可以看到刚刚创建的分区信息:/dev/sdb2
[root@XXGL-T-TJSYZ-REDIS-01 /]# fdisk -l
...
...
Disk /dev/sdb: 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: 0xa646c2a2
Device Boot Start End Blocks Id System
/dev/sdb1 2048 41945087 20971520 8e Linux LVM
/dev/sdb2 41945088 125831167 41943040 8e Linux LVM
/dev/sdb2就是刚刚创建的分区,接下来创建PV
[root@XXGL-T-TJSYZ-REDIS-01 ~]# pvcreate /dev/sdb2 //创建pv:pvcreate 分区名
Physical volume "/dev/sdb2" successfully created.
[root@XXGL-T-TJSYZ-REDIS-01 ~]# pvdisplay //显示当前的所有pv
--- Physical volume ---
PV Name /dev/sda2
VG Name vg_root
PV Size 35.00 GiB / not usable 4.00 MiB
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 8960
Free PE 0
Allocated PE 8960
PV UUID yC67Cm-Hvxr-aXde-ovxA-1qME-UEIa-hmkzgq
--- Physical volume ---
PV Name /dev/sdb1
VG Name vg_root
PV Size 20.00 GiB / not usable 4.00 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 5119
Free PE 24
Allocated PE 5095
PV UUID GSGymp-CDjX-wkra-1kCn-b3fj-upgx-PQHf4X
--- Physical volume ---
PV Name /dev/sda3
VG Name vg_new
PV Size <26.00 GiB / not usable 3.00 MiB
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 6655
Free PE 0
Allocated PE 6655
PV UUID NTfuir-ISnX-Z3n0-EW4K-lVO8-dW6W-92Qrsx
--- Physical volume ---
PV Name /dev/sda5
VG Name vg_new
PV Size 20.00 GiB / not usable 4.00 MiB
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 5119
Free PE 0
Allocated PE 5119
PV UUID KnrJ1f-FyYN-ThU6-BqTK-VX17-sNbE-gmbzDr
--- Physical volume ---
PV Name /dev/sda6
VG Name vg_new
PV Size 18.50 GiB / not usable 0
Allocatable yes
PE Size 4.00 MiB
Total PE 4737
Free PE 24
Allocated PE 4713
PV UUID Tc7uLW-dDHC-bELB-Rvlf-GNeQ-w26P-c0w1OK
"/dev/sdb2" is a new physical volume of "40.00 GiB"
--- NEW Physical volume ---
PV Name /dev/sdb2
VG Name
PV Size 40.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID 3CMhqd-SZr6-V9bQ-ofKV-C3TC-DUhP-9qB8Wv
[root@XXGL-T-TJSYZ-REDIS-01 ~]#
看上面的最后一条NEW Physical volume,就是新创建好的PV
这一步如果出现这个错误,执行一下命令:partprobe即可(问题所在: 内核没有成功同步分区信息,所有才需要使用"partprobe"命令来手动同步)
[root@mq03 ~]# pvcreate /dev/sdb2
File descriptor 3 (socket:[421941890]) leaked on pvcreate invocation. Parent PID 197714: -bash
Device /dev/sdb2 not found.
接下来扩展VG:如果不知道你的目录对应的LV属于哪个VG,使用df -h 目录名查看:
[root@XXGL-T-TJSYZ-REDIS-01 /]# df -h /neworiental/
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_new-lvnew 100G 51G 50G 51% /neworiental
[root@XXGL-T-TJSYZ-REDIS-01 /]#
看该目录的Filesystem对应的信息:/dev/mapper/vg_new-lvnew,后面的vg_new-lvnew命名规则是:VG名称-LV名称,所以定位到neworiental目录对应的VG是vg_new
[root@XXGL-T-TJSYZ-REDIS-03 ~]# vgs //查看当前的所有vg
VG #PV #LV #SN Attr VSize VFree
vg_new 1 2 0 wz--n- 64.50g 4.00m
vg_root 2 5 0 wz--n- <55.00g 96.00m
[root@XXGL-T-TJSYZ-REDIS-03 ~]# vgdisplay -v vg_new //指定vg查看信息
--- Volume group ---
VG Name vg_new
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 5
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 1
Act PV 1
VG Size 64.50 GiB
PE Size 4.00 MiB
Total PE 16513
Alloc PE / Size 16512 / 64.50 GiB
Free PE / Size 1 / 4.00 MiB
VG UUID UOiRzY-x5yr-4ZCn-JtWw-hNIg-SgSc-etx1kO
--- Logical volume ---
LV Path /dev/vg_new/lvnew
LV Name lvnew
VG Name vg_new
LV UUID 0M2v3T-LHZs-8lkR-ocbC-v0bs-eRz2-BjRsf2
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2017-06-15 10:23:32 +0800
LV Status available
# open 1
LV Size 59.50 GiB
Current LE 15232
Segments 2
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:3
--- Logical volume ---
LV Path /dev/vg_new/lvbackup
LV Name lvbackup
VG Name vg_new
LV UUID Z0QEKs-Io1j-yqOw-Uipq-IDHL-zRNH-DlElyp
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2017-06-15 10:23:32 +0800
LV Status available
# open 1
LV Size 5.00 GiB
Current LE 1280
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:4
--- Physical volumes ---
PV Name /dev/sda3
PV UUID NTfuir-ISnX-Z3n0-EW4K-lVO8-dW6W-92Qrsx
PV Status allocatable
Total PE / Free PE 16513 / 1
可以看到目录neworiental对应的VG:vg_new的大小为64.50 GiB;对应的LV:lvnew的大小为59.5G,路径(LV Path)为:/dev/vg_new/lvnew
下面开始扩容:
[root@XXGL-T-TJSYZ-REDIS-03 ~]# vgextend vg_new /dev/sdb2 //扩容VG:vgextend VG名称 PV名称
Volume group "vg_new" successfully extended
提示扩容成功,下面看看VG信息
[root@XXGL-T-TJSYZ-REDIS-03 ~]# vgdisplay -v vg_new
--- Volume group ---
VG Name vg_new
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 6
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 2
Act PV 2
VG Size 104.50 GiB
PE Size 4.00 MiB
Total PE 26752
Alloc PE / Size 16512 / 64.50 GiB
Free PE / Size 10240 / 40.00 GiB
VG UUID UOiRzY-x5yr-4ZCn-JtWw-hNIg-SgSc-etx1kO
可以看到VG Size 104.50 GiB,已经加了40G,下面扩LV:lvextend -L +扩容大小 LV路径
[root@XXGL-T-TJSYZ-REDIS-03 ~]# lvextend -L +20G /dev/vg_new/lvnew //扩容LV
Size of logical volume vg_new/lvnew changed from 59.50 GiB (15232 extents) to 79.50 GiB (20352 extents).
Logical volume vg_new/lvnew successfully resized.
[root@XXGL-T-TJSYZ-REDIS-03 ~]#
[root@XXGL-T-TJSYZ-REDIS-03 ~]# xfs_growfs /dev/vg_new/lvnew //这一步不要忘记,同步文件系统
meta-data=/dev/mapper/vg_new-lvnew isize=512 agcount=12, agsize=1310720 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=15597568, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 15597568 to 20840448
[root@XXGL-T-TJSYZ-REDIS-03 ~]#
注意:xfs_growfs是针对xfs类型的,如果是ext4,需要使用resize2fs命令,使用df -Th可以看文件系统类型
这样,LV就扩容成功了(本来是想扩40G的,操作失误了,不过无所谓,后面还可以再扩LV)
看看扩容后的文件目录信息:已经变成80G了
[root@XXGL-T-TJSYZ-REDIS-03 ~]# df -lh
Filesystem Size Used Avail Use% Mounted on
devtmpfs 16G 0 16G 0% /dev
tmpfs 16G 202M 16G 2% /dev/shm
tmpfs 16G 1.6G 15G 10% /run
tmpfs 16G 0 16G 0% /sys/fs/cgroup
/dev/mapper/vg_root-lvall 31G 22G 9.5G 70% /
/dev/mapper/vg_root-lvusr 10G 7.1G 3.0G 71% /usr
/dev/sda1 497M 219M 279M 44% /boot
/dev/mapper/vg_new-lvbackup 5.0G 33M 5.0G 1% /backup
/dev/mapper/vg_root-lvvar 5.0G 1.2G 3.9G 23% /var
/dev/mapper/vg_new-lvnew 80G 47G 34G 58% /neworiental
/dev/mapper/vg_root-lvtmp 5.0G 80M 5.0G 2% /tmp
tmpfs 3.2G 0 3.2G 0% /run/user/0
把剩下的20G再加上
[root@XXGL-T-TJSYZ-REDIS-03 ~]# lvextend -L +20G /dev/vg_new/lvnew
Size of logical volume vg_new/lvnew changed from 79.50 GiB (20352 extents) to 99.50 GiB (25472 extents).
Logical volume vg_new/lvnew successfully resized.
[root@XXGL-T-TJSYZ-REDIS-03 ~]#
[root@XXGL-T-TJSYZ-REDIS-03 ~]# xfs_growfs /dev/vg_new/lvnew
meta-data=/dev/mapper/vg_new-lvnew isize=512 agcount=16, agsize=1310720 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=20840448, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 20840448 to 26083328
[root@XXGL-T-TJSYZ-REDIS-03 ~]#
[root@XXGL-T-TJSYZ-REDIS-03 ~]# df -lh
Filesystem Size Used Avail Use% Mounted on
devtmpfs 16G 0 16G 0% /dev
tmpfs 16G 202M 16G 2% /dev/shm
tmpfs 16G 1.6G 15G 10% /run
tmpfs 16G 0 16G 0% /sys/fs/cgroup
/dev/mapper/vg_root-lvall 31G 22G 9.5G 70% /
/dev/mapper/vg_root-lvusr 10G 7.1G 3.0G 71% /usr
/dev/sda1 497M 219M 279M 44% /boot
/dev/mapper/vg_new-lvbackup 5.0G 33M 5.0G 1% /backup
/dev/mapper/vg_root-lvvar 5.0G 1.2G 3.9G 23% /var
/dev/mapper/vg_new-lvnew 100G 47G 54G 47% /neworiental
/dev/mapper/vg_root-lvtmp 5.0G 80M 5.0G 2% /tmp
tmpfs 3.2G 0 3.2G 0% /run/user/0
[root@XXGL-T-TJSYZ-REDIS-03 ~]#
OK,完成扩容,已经是100G了。
简单的总结一下步骤:
fdisk -l //查看磁盘列表
fdisk /dev/sdb //进入磁盘
...
...
...
partprobe //刷新
pvcreate /dev/sdb4 //创建PV:pvcreate 分区名
vgextend vg0 /dev/sdb4 // 扩容vg:vgextend vg名 分区名
lvextend -L +50G /dev/vg0/lv_root //扩展lv lvextend -L +size{单位} lv具体路径
resize2fs /dev/vg0/lv_root //刷新文件系统,ext4类型用resize2fs,xfs类型用xfs_growfs
创建LV
如果要创建新的LV,前两步和扩容是一样的:都是创建分区、创建PV,所以从第三步讲:
3、根据PV创建VG
4、根据VG创建LV
5、挂载到目录
6、开机自动挂载
注意,以下操作是在另一台机器上进行的,PV还是/dev/sdb2,并不是之前使用过的。
创建新的VG:vgcreate VG名称 PV路径
[root@XXGL-T-TJSYZ-REDIS-01 ~]# vgcreate vg_rmq /dev/sdb2
Volume group "vg_rmq" successfully created
[root@XXGL-T-TJSYZ-REDIS-01 ~]# vgdisplay
--- Volume group ---
VG Name vg_root
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 9
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 5
Open LV 5
Max PV 0
Cur PV 2
Act PV 2
VG Size <55.00 GiB
PE Size 4.00 MiB
Total PE 14079
Alloc PE / Size 14055 / 54.90 GiB
Free PE / Size 24 / 96.00 MiB
VG UUID OGWFcu-Tl5c-mMUM-mGvr-zfre-krJb-O354MX
--- Volume group ---
VG Name vg_rmq
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 1
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 0
Open LV 0
Max PV 0
Cur PV 1
Act PV 1
VG Size <40.00 GiB
PE Size 4.00 MiB
Total PE 10239
Alloc PE / Size 0 / 0
Free PE / Size 10239 / <40.00 GiB
VG UUID arB9H1-eHeS-3inJ-Ukle-hyQ2-p4Oe-6z41Wj
--- Volume group ---
VG Name vg_new
System ID
Format lvm2
Metadata Areas 3
Metadata Sequence No 12
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 3
Act PV 3
VG Size <64.50 GiB
PE Size 4.00 MiB
Total PE 16511
Alloc PE / Size 16487 / 64.40 GiB
Free PE / Size 24 / 96.00 MiB
VG UUID UOiRzY-x5yr-4ZCn-JtWw-hNIg-SgSc-etx1kO
[root@XXGL-T-TJSYZ-REDIS-01 ~]#
可以看到新的VG:vg_rmq已创建成功
接下来创建LV,创建LV之前,需要先确认VG所剩余的容量,因为VG真正的剩余容量是不足40G的,可以直接使用:lvcreate -L 39G -n LV名称 VG名称创建,即容量比40G少一点,也可先查看VG剩余的容量,再精确创建,使用命令:vgs -o +vg_free_count,vg_extent_count查看所有VG的容量剩余情况。
[root@XXGL-T-TJSYZ-REDIS-01 ~]# vgs -o +vg_free_count,vg_extent_count
VG #PV #LV #SN Attr VSize VFree Free #Ext
vg_new 3 2 0 wz--n- <64.50g 96.00m 24 16511
vg_rmq 1 0 0 wz--n- <40.00g <40.00g 10239 10239
vg_root 2 5 0 wz--n- <55.00g 96.00m 24 14079
[root@XXGL-T-TJSYZ-REDIS-01 ~]#
可以看到还剩10239,为什么是这么些呢?具体需要看一下PE、LE相关知识,这里不做介绍,接下来使用命令精确创建:lvcreate -l大小 -n LV名称 VG名称(注意:小写的“l”别忘了)
[root@XXGL-T-TJSYZ-REDIS-01 ~]# lvcreate -l10239 -n lv_rmq_01 vg_rmq
Logical volume "lv_rmq_01" created.
[root@XXGL-T-TJSYZ-REDIS-01 ~]#
可以看到,LV:lv_rmq_01创建成功,接下来需要创建LV对应的文件系统:mkfs.xfs LV路径,LV的路径可以通过命令lvdisplay查看:
[root@XXGL-T-TJSYZ-REDIS-01 /]# lvdisplay
...
...
...
--- Logical volume ---
LV Path /dev/vg_rmq/lv_rmq_01
LV Name lvnew
VG Name vg_new
LV UUID 0M2v3T-LHZs-8lkR-ocbC-v0bs-eRz2-BjRsf2
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2017-06-15 10:23:32 +0800
LV Status available
# open 1
LV Size 99.40 GiB
Current LE 25447
Segments 5
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:5
...
...
...
[root@XXGL-T-TJSYZ-REDIS-01 /]#
创建文件系统(Filesystem)
mkfs.xfs lv路径( LV Path)
[root@XXGL-T-TJSYZ-REDIS-01 ~]# mkfs.xfs /dev/vg_rmq/lv_rmq_01
meta-data=/dev/vg_rmq/lv_rmq_01 isize=512 agcount=4, agsize=2621184 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=10484736, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal log bsize=4096 blocks=5119, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
[root@XXGL-T-TJSYZ-REDIS-01 ~]#
挂载文件系统到新的文件目录:mount LV路径 文件夹路径
[root@XXGL-T-TJSYZ-REDIS-01 ~]# mkdir /zhurunhua
[root@XXGL-T-TJSYZ-REDIS-01 ~]# mount /dev/vg_rmq/lv_rmq_01 /zhurunhua
[root@XXGL-T-TJSYZ-REDIS-01 ~]#
检查:
[root@XXGL-T-TJSYZ-REDIS-01 /]# df -lh
Filesystem Size Used Avail Use% Mounted on
devtmpfs 16G 0 16G 0% /dev
tmpfs 16G 113M 16G 1% /dev/shm
tmpfs 16G 1.6G 15G 10% /run
tmpfs 16G 0 16G 0% /sys/fs/cgroup
/dev/mapper/vg_root-lvall 31G 13G 19G 39% /
/dev/mapper/vg_root-lvusr 10G 6.8G 3.3G 68% /usr
/dev/mapper/vg_root-lvtmp 5.0G 43M 5.0G 1% /tmp
/dev/mapper/vg_root-lvvar 5.0G 2.2G 2.9G 43% /var
/dev/mapper/vg_rmq-lv_rmq_01 100G 52G 49G 52% /zhurunhua
[root@XXGL-T-TJSYZ-REDIS-01 /]#
开机自动挂载
修改/etc/fstab文件,添加以下信息
/dev/mapper/vg_rmq-lv_rmq_01 /zhurunhua xfs defaults 1 1
第1列是设备名或者卷标(可通过df -lh查看:Filesystem列对应的信息)
第2列是挂载点(也就是挂载目录)
第3列是所要挂载设备的文件系统或者文件系统类型
第4列是挂载选项,通常使用defaults就可以
第5列设置是否使用dump备份,置0为不备份,置1,2为备份,但2的备份重要性比1小
第6列设置是否开机的时候使用fsck检验所挂载的磁盘,置0为不检验,置1,2为检验,但置2盘比置1的盘晚检验。
后记:由于是第一次操作,也遇到一些问题,比如刚开始是想扩容的,但是操作成了创建,然后把新创建的LV挂到了文件目录上,导致一进去目录是空的,给我吓的,后来查了一下,把目录挂载到之前的文件系统就行了,然后又把新创建的LV、VG删掉,删LV的时候需要先从文件目录上卸载,卸载之前要把所有使用该目录的进程干掉,删完新创建的VG之后,又把PV重新扩展到需要扩容的VG中,才重新回到扩容的正轨,总之,纸上得来终觉浅,觉知此事要躬行,实践是检验真理的唯一标准,学习到很多,收获很多,路漫漫其修远兮,吾将上下而求索。
The End.