规划节点

Linux操作系统的单节点规划。
 节点规划

IP 主机名 节点
192.168.200.10    kvm Linux服务器节点

基础准备

 添加硬盘
  在VMwareWorkstation中的虚拟机设置界面,单击下方“添加”按钮,选择“硬盘”,然后单击右下角“下一步”按钮。
image.png
 1,选择SCSI(S)磁盘,单击右下角“下一步”按钮。
 image.png

               (选择磁盘类型)
2,选择“创建新虚拟磁盘(V)”选项,然后单击右下角“下一步”按钮。
image.png
               
               ( 选择磁盘)
3,指定磁盘大小为20 GB,选择“将虚拟磁盘存储为单个文件(O)
image.png
              ( 指定磁盘容量)
4,文件名不做修改,使用默认名称,然后单击右下角“完成”按钮。
image.png
              ( 指定磁盘文件)
5,添加完磁盘后,重启虚拟机。重启过后,使用命令查看磁盘,命令如下:
 

  1. //可以看到存在一块名叫sdb的块设备,大小为20 GB
  2. [root@kvm ~]# lsblk
  3. NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
  4. sda 8:0 0 20G 0 disk
  5. ├─sda1 8:1 0 500M 0 part /boot
  6. └─sda2 8:2 0 19.5G 0 part
  7. ├─centos-root 253:0 0 17.5G 0 lvm /
  8. └─centos-swap 253:1 0 2G 0 lvm [SWAP]
  9. sdb 8:16 0 20G 0 disk
  10. sr0 11:0 1 4G 0 rom

案例实施

 (1)创建物理卷

 在创建物理卷之前,需要对磁盘进行分区。首先使用fdisk命令对sdb进行分区操作,分出两个大小为5 GB的分区,命令如下:

  1. [root@kvm ~]# fdisk /dev/sdb
  2. Welcome to fdisk (util-linux 2.23.2).
  3. Changes will remain in memory only, until you decide to write them.
  4. Be careful before using the write command.
  5. Device does not contain a recognized partition table
  6. Building a new DOS disklabel with disk identifier 0x132a9cad.
  7. Command (m for help): p
  8. Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 sectors
  9. Units = sectors of 1 * 512 = 512 bytes
  10. Sector size (logical/physical): 512 bytes / 512 bytes
  11. I/O size (minimum/optimal): 512 bytes / 512 bytes
  12. Disk label type: dos
  13. Disk identifier: 0x132a9cad
  14. Device Boot Start End Blocks Id System
  15. Command (m for help): n
  16. Partition type:
  17. p primary (0 primary, 0 extended, 4 free)
  18. e extended
  19. Select (default p): p
  20. Partition number (1-4, default 1):
  21. First sector (2048-41943039, default 2048):
  22. Using default value 2048
  23. Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039): +5G
  24. Partition 1 of type Linux and of size 5 GiB is set
  25. Command (m for help): n
  26. Partition type:
  27. p primary (1 primary, 0 extended, 3 free)
  28. e extended
  29. Select (default p): p
  30. Partition number (2-4, default 2):
  31. First sector (10487808-41943039, default 10487808):
  32. Using default value 10487808
  33. Last sector, +sectors or +size{K,M,G} (10487808-41943039, default 41943039): +5G
  34. Partition 2 of type Linux and of size 5 GiB is set
  35. Command (m for help): p
  36. Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 sectors
  37. Units = sectors of 1 * 512 = 512 bytes
  38. Sector size (logical/physical): 512 bytes / 512 bytes
  39. I/O size (minimum/optimal): 512 bytes / 512 bytes
  40. Disk label type: dos
  41. Disk identifier: 0x132a9cad
  42. Device Boot Start End Blocks Id System
  43. /dev/sdb1 2048 10487807 5242880 83 Linux
  44. /dev/sdb2 10487808 20973567 5242880 83 Linux
  45. Command (m for help): w
  46. The partition table has been altered!
  47. Calling ioctl() to re-read partition table.
  48. Syncing disks.
  49. [root@kvm ~]# lsblk
  50. NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
  51. sda 8:0 0 20G 0 disk
  52. ├─sda1 8:1 0 500M 0 part /boot
  53. └─sda2 8:2 0 19.5G 0 part
  54. ├─centos-root 253:0 0 17.5G 0 lvm /
  55. └─centos-swap 253:1 0 2G 0 lvm [SWAP]
  56. sdb 8:16 0 20G 0 disk
  57. ├─sdb1 8:17 0 5G 0 part
  58. └─sdb2 8:18 0 5G 0 part
  59. sr0 11:0 1 4G 0 rom

分完分区后,对这两个分区进行创建物理卷操作,命令如下:

  1. [root@kvm ~]# pvcreate /dev/sdb1 /dev/sdb2
  2. Physical volume "/dev/sdb1" successfully created
  3. Physical volume "/dev/sdb2" successfully created
  4. [root@kvm ~]# pvs
  5. PV VG Fmt Attr PSize PFree
  6. /dev/sda2 centos lvm2 a-- 19.51g 40.00m
  7. /dev/sdb1 lvm2 --- 5.00g 5.00g
  8. /dev/sdb2 lvm2 --- 5.00g 5.00g
  9. [root@kvm ~]# pvdisplay
  10. --- Physical volume ---
  11. PV Name /dev/sda2
  12. VG Name centos
  13. PV Size 19.51 GiB / not usable 3.00 MiB
  14. Allocatable yes
  15. PE Size 4.00 MiB
  16. Total PE 4994
  17. Free PE 10
  18. Allocated PE 4984
  19. PV UUID O2nGDe-7kek-T7r5-FKTG-4PUm-RlAf-Ffra6L
  20. "/dev/sdb1" is a new physical volume of "5.00 GiB"
  21. --- NEW Physical volume ---
  22. PV Name /dev/sdb1
  23. VG Name
  24. PV Size 5.00 GiB
  25. Allocatable NO
  26. PE Size 0
  27. Total PE 0
  28. Free PE 0
  29. Allocated PE 0
  30. PV UUID BT2e34-cepq-nak7-3nB0-geDF-Ktoe-dOO5J7
  31. "/dev/sdb2" is a new physical volume of "5.00 GiB"
  32. --- NEW Physical volume ---
  33. PV Name /dev/sdb2
  34. VG Name
  35. PV Size 5.00 GiB
  36. Allocatable NO
  37. PE Size 0
  38. Total PE 0
  39. Free PE 0
  40. Allocated PE 0
  41. PV UUID 2iURqp-gTxm-rTcT-UlrY-cBqY-NFKQ-LC0XRq

(2)创建卷组

使用刚才创建好的两个物理卷,创建名为myvg的卷组,命令如下:

  1. [root@kvm ~]# vgcreate myvg /dev/sdb[1-2]
  2. Volume group "myvg" successfully created
  3. [root@kvm ~]# vgs
  4. VG #PV #LV #SN Attr VSize VFree
  5. centos 1 2 0 wz--n- 19.51g 40.00m
  6. myvg 2 0 0 wz--n- 9.99g 9.99g
  7. [root@kvm ~]# vgdisplay
  8. --- Volume group ---
  9. VG Name myvg
  10. System ID
  11. Format lvm2
  12. Metadata Areas 2
  13. Metadata Sequence No 1
  14. VG Access read/write
  15. VG Status resizable
  16. MAX LV 0
  17. Cur LV 0
  18. Open LV 0
  19. Max PV 0
  20. Cur PV 2
  21. Act PV 2
  22. VG Size 9.99 GiB
  23. PE Size 4.00 MiB
  24. Total PE 2558
  25. Alloc PE / Size 0 / 0
  26. Free PE / Size 2558 / 9.99 GiB
  27. VG UUID UKeX39-nfMB-dX2Q-axko-SJoY-9e2Q-h7C4nq
  28. --- Volume group ---
  29. VG Name centos
  30. System ID
  31. Format lvm2
  32. Metadata Areas 1
  33. Metadata Sequence No 3
  34. VG Access read/write
  35. VG Status resizable
  36. MAX LV 0
  37. Cur LV 2
  38. Open LV 2
  39. Max PV 0
  40. Cur PV 1
  41. Act PV 1
  42. VG Size 19.51 GiB
  43. PE Size 4.00 MiB
  44. Total PE 4994
  45. Alloc PE / Size 4984 / 19.47 GiB
  46. Free PE / Size 10 / 40.00 MiB
  47. VG UUID pQeQ2t-Ad5k-Gq1b-w8Ps-7Xof-SHAs-rnthvR
  48. //当多个物理卷组合成一个卷组后时,LVM会在所有的物理卷上做类似格式化的工作,将每个物理卷切成
  49. 一块一块的空间,这一块一块的空间就称为PEPhysical Extent),它的默认大小是4 MB
  50. 由于受内核限制的原因,一个逻辑卷(Logic Volume)最多只能包含65536PEPhysical Extent),
  51. 所以一个PE的大小就决定了逻辑卷的最大容量,4 MBPE决定了单个逻辑卷最大容量为256 GB,若希望使
  52. 用大于256 Gb的逻辑卷,则创建卷组时需要指定更大的PE
  53. 删除卷组,重新创建卷组,并指定PE大小为16 MB,命令如下:
  54. [root@kvm ~]# vgremove myvg
  55. Volume group "myvg" successfully removed
  56. [root@kvm ~]# vgcreate -s 16m myvg /dev/sdb[1-2]
  57. Volume group "myvg" successfully created
  58. [root@kvm ~]# vgdisplay
  59. --- Volume group ---
  60. VG Name myvg
  61. System ID
  62. Format lvm2
  63. Metadata Areas 2
  64. Metadata Sequence No 1
  65. VG Access read/write
  66. VG Status resizable
  67. MAX LV 0
  68. Cur LV 0
  69. Open LV 0
  70. Max PV 0
  71. Cur PV 2
  72. Act PV 2
  73. VG Size 9.97 GiB //可以查看到现在myvg卷组的PE大小为16 MB
  74. PE Size 16.00 MiB
  75. Total PE 638
  76. Alloc PE / Size 0 / 0
  77. Free PE / Size 638 / 9.97 GiB
  78. VG UUID iRozOD-XE6z-dDIR-O7G0-psnE-i6bn-Cq7azu
  79. --- Volume group ---
  80. VG Name centos
  81. System ID
  82. Format lvm2
  83. Metadata Areas 1
  84. Metadata Sequence No 3
  85. VG Access read/write
  86. VG Status resizable
  87. MAX LV 0
  88. Cur LV 2
  89. Open LV 2
  90. Max PV 0
  91. Cur PV 1
  92. Act PV 1
  93. VG Size 19.51 GiB
  94. PE Size 4.00 MiB
  95. Total PE 4994
  96. Alloc PE / Size 4984 / 19.47 GiB
  97. Free PE / Size 10 / 40.00 MiB
  98. VG UUID pQeQ2t-Ad5k-Gq1b-w8Ps-7Xof-SHAs-rnthvR
  99. //向卷组myvg中添加一个物理卷,在/dev/sdb上再分一个/dev/sdb3分区,把该分区加到卷组myvg中。命令如下:
  100. [root@kvm ~]# lsblk
  101. NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
  102. sda 8:0 0 20G 0 disk
  103. ├─sda1 8:1 0 500M 0 part /boot
  104. └─sda2 8:2 0 19.5G 0 part
  105. ├─centos-root 253:0 0 17.5G 0 lvm /
  106. └─centos-swap 253:1 0 2G 0 lvm [SWAP]
  107. sdb 8:16 0 20G 0 disk
  108. ├─sdb1 8:17 0 5G 0 part
  109. └─sdb2 8:18 0 5G 0 part
  110. sr0 11:0 1 4G 0 rom
  111. [root@kvm ~]# vgextend myvg /dev/sdb3
  112. Device /dev/sdb3 not found (or ignored by filtering).
  113. Unable to add physical volume '/dev/sdb3' to volume group 'myvg'.
  114. [root@kvm ~]# vgs
  115. VG #PV #LV #SN Attr VSize VFree
  116. centos 1 2 0 wz--n- 19.51g 40.00m
  117. myvg 2 0 0 wz--n- 9.97g 9.97g
  118. [root@kvm ~]# vgdisplay myvg
  119. --- Volume group ---
  120. VG Name myvg
  121. System ID
  122. Format lvm2
  123. Metadata Areas 2
  124. Metadata Sequence No 1
  125. VG Access read/write
  126. VG Status resizable
  127. MAX LV 0
  128. Cur LV 0
  129. Open LV 0
  130. Max PV 0
  131. Cur PV 2
  132. Act PV 2
  133. VG Size 9.97 GiB
  134. PE Size 16.00 MiB
  135. Total PE 638
  136. Alloc PE / Size 0 / 0
  137. Free PE / Size 638 / 9.97 GiB
  138. VG UUID iRozOD-XE6z-dDIR-O7G0-psnE-i6bn-Cq7azu

创建逻辑卷

创建逻辑卷,名称为mylv,大小为5 GB。

  1. [root@kvm ~]# lvcreate -L +5G -n mylv myvg
  2. Logical volume "mylv" created.
  3. [root@kvm ~]# lvs
  4. LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
  5. root centos -wi-ao---- 17.47g
  6. swap centos -wi-ao---- 2.00g
  7. mylv myvg -wi-a----- 5.00g
  8. [root@kvm ~]# lvscan
  9. ACTIVE '/dev/myvg/mylv' [5.00 GiB] inherit
  10. ACTIVE '/dev/centos/root' [17.47 GiB] inherit
  11. ACTIVE '/dev/centos/swap' [2.00 GiB] inherit
  12. [root@kvm ~]# mkfs.ext4 /dev/mapper/myvg-mylv
  13. mke2fs 1.42.9 (28-Dec-2013)
  14. Filesystem label=
  15. OS type: Linux
  16. Block size=4096 (log=2)
  17. Fragment size=4096 (log=2)
  18. Stride=0 blocks, Stripe width=0 blocks
  19. 327680 inodes, 1310720 blocks
  20. 65536 blocks (5.00%) reserved for the super user
  21. First data block=0
  22. Maximum filesystem blocks=1342177280
  23. 40 block groups
  24. 32768 blocks per group, 32768 fragments per group
  25. 8192 inodes per group
  26. Superblock backups stored on blocks:
  27. 32768, 98304, 163840, 229376, 294912, 819200, 884736
  28. Allocating group tables: done
  29. Writing inode tables: done
  30. Creating journal (32768 blocks): done
  31. Writing superblocks and filesystem accounting information: done
  32. [root@kvm ~]# mount /dev/mapper/myvg-mylv /mnt/
  33. [root@kvm ~]# df -h
  34. Filesystem Size Used Avail Use% Mounted on
  35. /dev/mapper/centos-root 18G 1.2G 17G 7% /
  36. devtmpfs 479M 0 479M 0% /dev
  37. tmpfs 489M 0 489M 0% /dev/shm
  38. tmpfs 489M 6.7M 483M 2% /run
  39. tmpfs 489M 0 489M 0% /sys/fs/cgroup
  40. /dev/sda1 497M 125M 373M 25% /boot
  41. tmpfs 98M 0 98M 0% /run/user/0
  42. /dev/mapper/myvg-mylv 4.8G 20M 4.6G 1% /mnt

创建的LVM卷扩容至1 GB

  1. [root@kvm ~]# lvextend -L +1G /dev/mapper/myvg-mylv
  2. Size of logical volume myvg/mylv changed from 5.00 GiB (320 extents) to 6.00 GiB (384 extents).
  3. Logical volume mylv successfully resized.
  4. [root@kvm ~]# lvs
  5. LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
  6. root centos -wi-ao---- 17.47g
  7. swap centos -wi-ao---- 2.00g
  8. mylv myvg -wi-ao---- 6.00g
  9. [root@kvm ~]# df -h
  10. Filesystem Size Used Avail Use% Mounted on
  11. /dev/mapper/centos-root 18G 1.2G 17G 7% /
  12. devtmpfs 479M 0 479M 0% /dev
  13. tmpfs 489M 0 489M 0% /dev/shm
  14. tmpfs 489M 6.7M 483M 2% /run
  15. tmpfs 489M 0 489M 0% /sys/fs/cgroup
  16. /dev/sda1 497M 125M 373M 25% /boot
  17. tmpfs 98M 0 98M 0% /run/user/0
  18. /dev/mapper/myvg-mylv 4.8G 20M 4.6G 1% /mnt
  19. [root@kvm ~]# resize2fs /dev/mapper/myvg-mylv
  20. resize2fs 1.42.9 (28-Dec-2013)
  21. Filesystem at /dev/mapper/myvg-mylv is mounted on /mnt; on-line resizing required
  22. old_desc_blocks = 1, new_desc_blocks = 1
  23. The filesystem on /dev/mapper/myvg-mylv is now 1572864 blocks long.
  24. [root@kvm ~]# df -h
  25. Filesystem Size Used Avail Use% Mounted on
  26. /dev/mapper/centos-root 18G 1.2G 17G 7% /
  27. devtmpfs 479M 0 479M 0% /dev
  28. tmpfs 489M 0 489M 0% /dev/shm
  29. tmpfs 489M 6.7M 483M 2% /run
  30. tmpfs 489M 0 489M 0% /sys/fs/cgroup
  31. /dev/sda1 497M 125M 373M 25% /boot
  32. tmpfs 98M 0 98M 0% /run/user/0
  33. /dev/mapper/myvg-mylv 5.8G 20M 5.5G 1% /mnt