首先介绍LVM的几个概念:
1. 物理卷Physical volume (PV):可以在上面建立卷组的媒介,可以是硬盘分区,也可以是硬盘本身或者回环文件(loopback file)。物理卷包括一个特殊的header,其余部分被切割为一块块物理区域(physical extents)。 Think of physical volumes as big building blocks which can be used to build your hard drive.
2. 卷组Volume group (VG):将一组物理卷收集为一个管理单元。Group of physical volumes that are used as storage volume (as one disk). They contain logical volumes. Think of volume groups as hard drives.
3. 逻辑卷Logical volume (LV):虚拟分区,由物理区域(physical extents)组成。A "virtual/logical partition" that resides in a volume group and is composed of physical extents. Think of logical volumes as normal partitions.
4. 物理区域Physical extent (PE):硬盘可供指派给逻辑卷的最小单位(通常为4MB)。A small part of a disk (usually 4MB) that can be assigned to a logical Volume. Think of physical extents as parts of disks that can be allocated to any partition.
查看服务器当前磁盘:
fdisk -l
安装LVM所需的命令:
yum install lvm2
创建PV #/dev/vdb需要挂载的磁盘
pvcreate /dev/vdb
查看pv
Pvs
创建VG #vnumvg创建的VG名称
vgcreate vnumvg /dev/vdb
查看vg
Vgs
创建lv #vnumvg指定的VG名称,vnumlv 创建的LV名称
lvcreate -l +100%VG -n vnumlv vnumvg
查看文件系统名称
df -h
格式话指定的文件系统
mkfs.ext4 /dev/mapper/vnumvg-vnumlv
指定文件系统挂载的目录
mount /dev/mapper/vnumvg-vnumlv vnum
配置当前文件系统开机自启
vi /etc/fstab
#/dev/mapper/vnumvg-vnumlv /vnum ext4 defaults 1 1
配置当前主机的映射关系
vi /etc/hosts
#127.0.0.1 localhost vm192-168-5-14 vnum
#192.168.5.16 vm192-168-5-16