规划节点
Linux操作系统的单节点规划。
节点规划
IP | 主机名 | 节点 |
---|---|---|
192.168.200.10 | kvm | Linux服务器节点 |
基础准备
添加硬盘
在VMwareWorkstation中的虚拟机设置界面,单击下方“添加”按钮,选择“硬盘”,然后单击右下角“下一步”按钮。
1,选择SCSI(S)磁盘,单击右下角“下一步”按钮。
(选择磁盘类型)
2,选择“创建新虚拟磁盘(V)”选项,然后单击右下角“下一步”按钮。
( 选择磁盘)
3,指定磁盘大小为20 GB,选择“将虚拟磁盘存储为单个文件(O)
( 指定磁盘容量)
4,文件名不做修改,使用默认名称,然后单击右下角“完成”按钮。
( 指定磁盘文件)
5,添加完磁盘后,重启虚拟机。重启过后,使用命令查看磁盘,命令如下:
//可以看到存在一块名叫sdb的块设备,大小为20 GB。
[root@kvm ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 20G 0 disk
├─sda1 8:1 0 500M 0 part /boot
└─sda2 8:2 0 19.5G 0 part
├─centos-root 253:0 0 17.5G 0 lvm /
└─centos-swap 253:1 0 2G 0 lvm [SWAP]
sdb 8:16 0 20G 0 disk
sr0 11:0 1 4G 0 rom
案例实施
(1)创建物理卷
在创建物理卷之前,需要对磁盘进行分区。首先使用fdisk命令对sdb进行分区操作,分出两个大小为5 GB的分区,命令如下:
[root@kvm ~]# 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.
Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0x132a9cad.
Command (m for help): p
Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 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: 0x132a9cad
Device Boot Start End Blocks Id System
Command (m for help): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p
Partition number (1-4, default 1):
First sector (2048-41943039, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039): +5G
Partition 1 of type Linux and of size 5 GiB is set
Command (m for help): n
Partition type:
p primary (1 primary, 0 extended, 3 free)
e extended
Select (default p): p
Partition number (2-4, default 2):
First sector (10487808-41943039, default 10487808):
Using default value 10487808
Last sector, +sectors or +size{K,M,G} (10487808-41943039, default 41943039): +5G
Partition 2 of type Linux and of size 5 GiB is set
Command (m for help): p
Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 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: 0x132a9cad
Device Boot Start End Blocks Id System
/dev/sdb1 2048 10487807 5242880 83 Linux
/dev/sdb2 10487808 20973567 5242880 83 Linux
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@kvm ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 20G 0 disk
├─sda1 8:1 0 500M 0 part /boot
└─sda2 8:2 0 19.5G 0 part
├─centos-root 253:0 0 17.5G 0 lvm /
└─centos-swap 253:1 0 2G 0 lvm [SWAP]
sdb 8:16 0 20G 0 disk
├─sdb1 8:17 0 5G 0 part
└─sdb2 8:18 0 5G 0 part
sr0 11:0 1 4G 0 rom
分完分区后,对这两个分区进行创建物理卷操作,命令如下:
[root@kvm ~]# pvcreate /dev/sdb1 /dev/sdb2
Physical volume "/dev/sdb1" successfully created
Physical volume "/dev/sdb2" successfully created
[root@kvm ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/sda2 centos lvm2 a-- 19.51g 40.00m
/dev/sdb1 lvm2 --- 5.00g 5.00g
/dev/sdb2 lvm2 --- 5.00g 5.00g
[root@kvm ~]# pvdisplay
--- Physical volume ---
PV Name /dev/sda2
VG Name centos
PV Size 19.51 GiB / not usable 3.00 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 4994
Free PE 10
Allocated PE 4984
PV UUID O2nGDe-7kek-T7r5-FKTG-4PUm-RlAf-Ffra6L
"/dev/sdb1" is a new physical volume of "5.00 GiB"
--- NEW Physical volume ---
PV Name /dev/sdb1
VG Name
PV Size 5.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID BT2e34-cepq-nak7-3nB0-geDF-Ktoe-dOO5J7
"/dev/sdb2" is a new physical volume of "5.00 GiB"
--- NEW Physical volume ---
PV Name /dev/sdb2
VG Name
PV Size 5.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID 2iURqp-gTxm-rTcT-UlrY-cBqY-NFKQ-LC0XRq
(2)创建卷组
使用刚才创建好的两个物理卷,创建名为myvg的卷组,命令如下:
[root@kvm ~]# vgcreate myvg /dev/sdb[1-2]
Volume group "myvg" successfully created
[root@kvm ~]# vgs
VG #PV #LV #SN Attr VSize VFree
centos 1 2 0 wz--n- 19.51g 40.00m
myvg 2 0 0 wz--n- 9.99g 9.99g
[root@kvm ~]# vgdisplay
--- Volume group ---
VG Name myvg
System ID
Format lvm2
Metadata Areas 2
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 2
Act PV 2
VG Size 9.99 GiB
PE Size 4.00 MiB
Total PE 2558
Alloc PE / Size 0 / 0
Free PE / Size 2558 / 9.99 GiB
VG UUID UKeX39-nfMB-dX2Q-axko-SJoY-9e2Q-h7C4nq
--- Volume group ---
VG Name centos
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 3
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 19.51 GiB
PE Size 4.00 MiB
Total PE 4994
Alloc PE / Size 4984 / 19.47 GiB
Free PE / Size 10 / 40.00 MiB
VG UUID pQeQ2t-Ad5k-Gq1b-w8Ps-7Xof-SHAs-rnthvR
//当多个物理卷组合成一个卷组后时,LVM会在所有的物理卷上做类似格式化的工作,将每个物理卷切成
一块一块的空间,这一块一块的空间就称为PE(Physical Extent),它的默认大小是4 MB。
由于受内核限制的原因,一个逻辑卷(Logic Volume)最多只能包含65536个PE(Physical Extent),
所以一个PE的大小就决定了逻辑卷的最大容量,4 MB的PE决定了单个逻辑卷最大容量为256 GB,若希望使
用大于256 Gb的逻辑卷,则创建卷组时需要指定更大的PE。
删除卷组,重新创建卷组,并指定PE大小为16 MB,命令如下:
[root@kvm ~]# vgremove myvg
Volume group "myvg" successfully removed
[root@kvm ~]# vgcreate -s 16m myvg /dev/sdb[1-2]
Volume group "myvg" successfully created
[root@kvm ~]# vgdisplay
--- Volume group ---
VG Name myvg
System ID
Format lvm2
Metadata Areas 2
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 2
Act PV 2
VG Size 9.97 GiB //可以查看到现在myvg卷组的PE大小为16 MB。
PE Size 16.00 MiB
Total PE 638
Alloc PE / Size 0 / 0
Free PE / Size 638 / 9.97 GiB
VG UUID iRozOD-XE6z-dDIR-O7G0-psnE-i6bn-Cq7azu
--- Volume group ---
VG Name centos
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 3
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 19.51 GiB
PE Size 4.00 MiB
Total PE 4994
Alloc PE / Size 4984 / 19.47 GiB
Free PE / Size 10 / 40.00 MiB
VG UUID pQeQ2t-Ad5k-Gq1b-w8Ps-7Xof-SHAs-rnthvR
//向卷组myvg中添加一个物理卷,在/dev/sdb上再分一个/dev/sdb3分区,把该分区加到卷组myvg中。命令如下:
[root@kvm ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 20G 0 disk
├─sda1 8:1 0 500M 0 part /boot
└─sda2 8:2 0 19.5G 0 part
├─centos-root 253:0 0 17.5G 0 lvm /
└─centos-swap 253:1 0 2G 0 lvm [SWAP]
sdb 8:16 0 20G 0 disk
├─sdb1 8:17 0 5G 0 part
└─sdb2 8:18 0 5G 0 part
sr0 11:0 1 4G 0 rom
[root@kvm ~]# vgextend myvg /dev/sdb3
Device /dev/sdb3 not found (or ignored by filtering).
Unable to add physical volume '/dev/sdb3' to volume group 'myvg'.
[root@kvm ~]# vgs
VG #PV #LV #SN Attr VSize VFree
centos 1 2 0 wz--n- 19.51g 40.00m
myvg 2 0 0 wz--n- 9.97g 9.97g
[root@kvm ~]# vgdisplay myvg
--- Volume group ---
VG Name myvg
System ID
Format lvm2
Metadata Areas 2
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 2
Act PV 2
VG Size 9.97 GiB
PE Size 16.00 MiB
Total PE 638
Alloc PE / Size 0 / 0
Free PE / Size 638 / 9.97 GiB
VG UUID iRozOD-XE6z-dDIR-O7G0-psnE-i6bn-Cq7azu
创建逻辑卷
创建逻辑卷,名称为mylv,大小为5 GB。
[root@kvm ~]# lvcreate -L +5G -n mylv myvg
Logical volume "mylv" created.
[root@kvm ~]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
root centos -wi-ao---- 17.47g
swap centos -wi-ao---- 2.00g
mylv myvg -wi-a----- 5.00g
[root@kvm ~]# lvscan
ACTIVE '/dev/myvg/mylv' [5.00 GiB] inherit
ACTIVE '/dev/centos/root' [17.47 GiB] inherit
ACTIVE '/dev/centos/swap' [2.00 GiB] inherit
[root@kvm ~]# mkfs.ext4 /dev/mapper/myvg-mylv
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
327680 inodes, 1310720 blocks
65536 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=1342177280
40 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736
Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
[root@kvm ~]# mount /dev/mapper/myvg-mylv /mnt/
[root@kvm ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 18G 1.2G 17G 7% /
devtmpfs 479M 0 479M 0% /dev
tmpfs 489M 0 489M 0% /dev/shm
tmpfs 489M 6.7M 483M 2% /run
tmpfs 489M 0 489M 0% /sys/fs/cgroup
/dev/sda1 497M 125M 373M 25% /boot
tmpfs 98M 0 98M 0% /run/user/0
/dev/mapper/myvg-mylv 4.8G 20M 4.6G 1% /mnt
创建的LVM卷扩容至1 GB
[root@kvm ~]# lvextend -L +1G /dev/mapper/myvg-mylv
Size of logical volume myvg/mylv changed from 5.00 GiB (320 extents) to 6.00 GiB (384 extents).
Logical volume mylv successfully resized.
[root@kvm ~]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
root centos -wi-ao---- 17.47g
swap centos -wi-ao---- 2.00g
mylv myvg -wi-ao---- 6.00g
[root@kvm ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 18G 1.2G 17G 7% /
devtmpfs 479M 0 479M 0% /dev
tmpfs 489M 0 489M 0% /dev/shm
tmpfs 489M 6.7M 483M 2% /run
tmpfs 489M 0 489M 0% /sys/fs/cgroup
/dev/sda1 497M 125M 373M 25% /boot
tmpfs 98M 0 98M 0% /run/user/0
/dev/mapper/myvg-mylv 4.8G 20M 4.6G 1% /mnt
[root@kvm ~]# resize2fs /dev/mapper/myvg-mylv
resize2fs 1.42.9 (28-Dec-2013)
Filesystem at /dev/mapper/myvg-mylv is mounted on /mnt; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 1
The filesystem on /dev/mapper/myvg-mylv is now 1572864 blocks long.
[root@kvm ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 18G 1.2G 17G 7% /
devtmpfs 479M 0 479M 0% /dev
tmpfs 489M 0 489M 0% /dev/shm
tmpfs 489M 6.7M 483M 2% /run
tmpfs 489M 0 489M 0% /sys/fs/cgroup
/dev/sda1 497M 125M 373M 25% /boot
tmpfs 98M 0 98M 0% /run/user/0
/dev/mapper/myvg-mylv 5.8G 20M 5.5G 1% /mnt