轉--Centos7創建LVM磁盤管理


轉--https://www.jianshu.com/p/accff9ea7b15

環境介紹
在centos7下需要掛載兩個新的磁盤。為了方便后續的擴容方便,決定將這其設置為LVM管理的方式。

查看一下當前有哪些新增的數據盤,如下:

[root@runsdata-test-0004 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/vda1 40G 1.4G 36G 4% /
devtmpfs 7.8G 0 7.8G 0% /dev
tmpfs 7.8G 0 7.8G 0% /dev/shm
tmpfs 7.8G 328K 7.8G 1% /run
tmpfs 7.8G 0 7.8G 0% /sys/fs/cgroup
tmpfs 1.6G 0 1.6G 0% /run/user/0
[root@runsdata-test-0004 ~]# fdisk -l

Disk /dev/vda: 42.9 GB, 42949672960 bytes, 83886080 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: 0x0008d73a

Device Boot Start End Blocks Id System
/dev/vda1 * 2048 83884031 41940992 83 Linux

Disk /dev/vdb: 53.7 GB, 53687091200 bytes, 104857600 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/vdc: 53.7 GB, 53687091200 bytes, 104857600 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

[root@runsdata-test-0004 ~]#
可以從上面看出,目前有三塊硬盤。
系統盤:40G
另外還有兩塊50G的硬盤,需要掛載。我以其中一塊硬盤作為示例。

LVM管理基本概念
LVM管理概念圖
1、 物理卷-----PV(Physical Volume)
物理卷在邏輯卷管理中處於最底層,它可以是實際物理硬盤上的分區,也可以是整個 物理硬盤。
2、 卷組--------VG(Volumne Group)
卷組建立在物理卷之上,一個卷組中至少要包括一個物理卷,在卷組建立之后可 動態添加物理卷到卷組中。一個邏輯卷管理系統工程中可以只有一個卷組,也可以 擁有多個卷組。
3、 邏輯卷-----LV(Logical Volume)
邏輯卷建立在卷組之上,卷組中的未分配空間可以用於建立新的邏輯卷,邏輯卷建立 后可以動態地擴展和縮小空間。系統中的多個邏輯卷要以屬於同一個卷組,也可以 屬於不同的多個卷組。
4、 物理區域--PE(Physical Extent)
物理區域是物理卷中可用於分配的最小存儲單元,物理區域的大小可根據實際情況在 建立物理卷時指定。物理區域大小一旦確定將不能更改,同一卷組中的所有物理卷 的物理區域大小需要一致。
5、 邏輯區域—LE(Logical Extent)
邏輯區域是邏輯卷中可用於分配的最小存儲單元,邏輯區域的大小取決於邏輯卷所在 卷組中的物理區域的大小。
6、 卷組描述區域-----(Volume Group Descriptor Area)
卷組描述區域存在於每個物理卷中,用於描述物理卷本身、物理卷所屬卷組、卷組中的 邏輯卷及邏輯卷中物理區域的分配等所有信息,卷組描述區域是在使用pvcreate 建立物理卷時建立的。
目標 - LVM管理拓撲

本篇章以此拓撲進行逐步部署。

給硬盤分區
選擇其中一塊50G的數據盤進行分區,只要將50G都設置一個分區即可,無需考慮設置多個分區。
配置步驟如下:

使用命令:fdisk -l |grep dev,查看添加的硬盤是否存在。
[root@runsdata-test-0004 ~]# fdisk -l | grep dev
Disk /dev/vda: 42.9 GB, 42949672960 bytes, 83886080 sectors
/dev/vda1 * 2048 83884031 41940992 83 Linux
Disk /dev/vdb: 53.7 GB, 53687091200 bytes, 104857600 sectors
Disk /dev/vdc: 53.7 GB, 53687091200 bytes, 104857600 sectors
[root@runsdata-test-0004 ~]#
fdisk是分區工具:fdisk /dev/vdb,進入分區工具設置。
[root@runsdata-test-0004 ~]# fdisk /dev/vdb
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 0x051e2cc7.

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):
輸入m命令,則是查看有哪些命令可以使用。其中可以先看看這個數據盤有什么分區了。

輸入p命令,查看該數據盤已經有哪些分區
Command (m for help): p

Disk /dev/vdb: 53.7 GB, 53687091200 bytes, 104857600 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: 0x051e2cc7

Device Boot Start End Blocks Id System

Command (m for help):
可以看出這塊數據盤暫時還沒有任何分區,那么下面我先來進行分區。

下面進入分區,‘n’選一個分區類型,如沒有其他設置可按默認下到返回m for help處。最后按'w'保存設置。

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): 1
First sector (2048-104857599, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-104857599, default 104857599):
Using default value 104857599
Partition 1 of type Linux and of size 50 GiB is set

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
[root@runsdata-test-0004 ~]#
此時,再次查看一下數據盤,應該已經有一個50G的分區了。那么下一步,將其改為Linux LVM格式分區。

設置磁盤分區為Linux LVM格式分區

Command (m for help): p

Disk /dev/vdb: 53.7 GB, 53687091200 bytes, 104857600 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: 0x051e2cc7

Device Boot Start End Blocks Id System
/dev/vdb1 2048 104857599 52427776 83 Linux

Command (m for help): t
Selected partition 1
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'

Command (m for help): p

Disk /dev/vdb: 53.7 GB, 53687091200 bytes, 104857600 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: 0x051e2cc7

Device Boot Start End Blocks Id System
/dev/vdb1 2048 104857599 52427776 8e Linux LVM

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
[root@runsdata-test-0004 ~]#
根據上面的步驟,再對另一個數據盤進行分區,執行如下:
分區:

[root@runsdata-test-0004 ~]# fdisk -l | grep dev
Disk /dev/vda: 42.9 GB, 42949672960 bytes, 83886080 sectors
/dev/vda1 * 2048 83884031 41940992 83 Linux
Disk /dev/vdb: 53.7 GB, 53687091200 bytes, 104857600 sectors
/dev/vdb1 2048 104857599 52427776 8e Linux LVM
Disk /dev/vdc: 53.7 GB, 53687091200 bytes, 104857600 sectors
[root@runsdata-test-0004 ~]#
[root@runsdata-test-0004 ~]# fdisk /dev/vdc
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 0x420d8007.

Command (m for help): p

Disk /dev/vdc: 53.7 GB, 53687091200 bytes, 104857600 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: 0x420d8007

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): 1
First sector (2048-104857599, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-104857599, default 104857599):
Using default value 104857599
Partition 1 of type Linux and of size 50 GiB is set

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
[root@runsdata-test-0004 ~]#
設置為LVM

[root@runsdata-test-0004 ~]# fdisk /dev/vdc
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): p

Disk /dev/vdc: 53.7 GB, 53687091200 bytes, 104857600 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: 0x420d8007

Device Boot Start End Blocks Id System
/dev/vdc1 2048 104857599 52427776 83 Linux

Command (m for help): t
Selected partition 1
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'

Command (m for help): p

Disk /dev/vdc: 53.7 GB, 53687091200 bytes, 104857600 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: 0x420d8007

Device Boot Start End Blocks Id System
/dev/vdc1 2048 104857599 52427776 8e Linux LVM

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
[root@runsdata-test-0004 ~]#
創建物理卷 PV
安裝pv系列命令, yum install lvm2 -y
阿里雲的服務器默認沒有安裝pv的相關命令的。

[root@runsdata-test-0004 ~]# pvcreate
-bash: pvcreate: command not found
[root@runsdata-test-0004 ~]#
需要安裝一下lvm2的工具如下:

[root@server81 ~]# rpm -qa | grep lvm
lvm2-2.02.171-8.el7.x86_64
lvm2-libs-2.02.171-8.el7.x86_64
[root@server81 ~]#
安裝如下:

[root@runsdata-test-0004 ~]# yum install lvm2 -y
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package lvm2.x86_64 7:2.02.180-10.el7_6.2 will be installed
.... 省略 ....

Installed:
lvm2.x86_64 7:2.02.180-10.el7_6.2

Dependency Installed:
device-mapper-event.x86_64 7:1.02.149-10.el7_6.2
device-mapper-event-libs.x86_64 7:1.02.149-10.el7_6.2
device-mapper-persistent-data.x86_64 0:0.7.3-3.el7
libaio.x86_64 0:0.3.109-13.el7
lvm2-libs.x86_64 7:2.02.180-10.el7_6.2

Dependency Updated:
device-mapper.x86_64 7:1.02.149-10.el7_6.2 device-mapper-libs.x86_64 7:1.02.149-10.el7_6.2

Complete!
[root@runsdata-test-0004 ~]#
[root@runsdata-test-0004 ~]# rpm -qa | grep lvm
lvm2-libs-2.02.180-10.el7_6.2.x86_64
lvm2-2.02.180-10.el7_6.2.x86_64
[root@runsdata-test-0004 ~]#
[root@runsdata-test-0004 ~]# pv
pv pvck pvdisplay pvremove pvs
pvchange pvcreate pvmove pvresize pvscan
[root@runsdata-test-0004 ~]# pv
從上面可以看出已經安裝好了lvm所需要的工具了。那么下面來繼續配置。

創建物理卷:選擇自己要創建的分區
[root@runsdata-test-0004 ~]# fdisk -l | grep dev
Disk /dev/vda: 42.9 GB, 42949672960 bytes, 83886080 sectors
/dev/vda1 * 2048 83884031 41940992 83 Linux
Disk /dev/vdb: 53.7 GB, 53687091200 bytes, 104857600 sectors
/dev/vdb1 2048 104857599 52427776 8e Linux LVM
Disk /dev/vdc: 53.7 GB, 53687091200 bytes, 104857600 sectors
[root@runsdata-test-0004 ~]#
[root@runsdata-test-0004 ~]# pvcreate /dev/vdb
vdb vdb1
[root@runsdata-test-0004 ~]# pvcreate /dev/vdb1
Physical volume "/dev/vdb1" successfully created.
[root@runsdata-test-0004 ~]#
[root@runsdata-test-0004 ~]#
查看創建好的物理卷
[root@runsdata-test-0004 ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/vdb1 lvm2 --- <50.00g <50.00g
[root@runsdata-test-0004 ~]#
[root@runsdata-test-0004 ~]# pvdisplay
"/dev/vdb1" is a new physical volume of "<50.00 GiB"
--- NEW Physical volume ---
PV Name /dev/vdb1
VG Name
PV Size <50.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID oMzorH-1mfB-0VEy-eZDB-HHU3-UM9C-0EoPTU

[root@runsdata-test-0004 ~]#
PE(physical extent):物理區域是物理卷中可用於分配的最小存儲單元,物理區域大小在建立卷組時指定,一旦確定不能更改,同一卷組所有物理卷的物理區域大小需一致,新的pv加入到vg后,pe的大小自動更改為vg中定義的pe大小。

LE(logical extent):邏輯區域是邏輯卷中可用於分配的最小存儲單元,邏輯區域的大小取決於邏輯卷所在卷組中的物理區域的大小。

卷組描述區域:卷組描述區域存在於每個物理卷中,用於描述物理卷本身、物理卷所屬卷組、卷組中邏輯卷、邏輯卷中物理區域的分配等所有信息,它是在使用pvcreate建立物理卷時建立的。

根據上面的步驟,再給另一個數據盤創建PV
[root@runsdata-test-0004 ~]# fdisk -l | grep dev
Disk /dev/vda: 42.9 GB, 42949672960 bytes, 83886080 sectors
/dev/vda1 * 2048 83884031 41940992 83 Linux
Disk /dev/vdb: 53.7 GB, 53687091200 bytes, 104857600 sectors
/dev/vdb1 2048 104857599 52427776 8e Linux LVM
Disk /dev/vdc: 53.7 GB, 53687091200 bytes, 104857600 sectors
/dev/vdc1 2048 104857599 52427776 8e Linux LVM
[root@runsdata-test-0004 ~]#
[root@runsdata-test-0004 ~]# pvcreate /dev/vdc1
Physical volume "/dev/vdc1" successfully created.
[root@runsdata-test-0004 ~]#
[root@runsdata-test-0004 ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/vdb1 vgdocker lvm2 a-- <50.00g <50.00g
/dev/vdc1 lvm2 --- <50.00g <50.00g
[root@runsdata-test-0004 ~]#
[root@runsdata-test-0004 ~]# pvdisplay
--- Physical volume ---
PV Name /dev/vdb1
VG Name vgdocker
PV Size <50.00 GiB / not usable 3.00 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 12799
Free PE 12799
Allocated PE 0
PV UUID oMzorH-1mfB-0VEy-eZDB-HHU3-UM9C-0EoPTU

"/dev/vdc1" is a new physical volume of "<50.00 GiB"
--- NEW Physical volume ---
PV Name /dev/vdc1
VG Name
PV Size <50.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID nzkwWq-h4KK-2g64-aAqT-3Ugz-qvrj-bq4GR3

[root@runsdata-test-0004 ~]#
創建卷組,用於管理PV以及LV
vg系列命令
[root@runsdata-test-0004 ~]# vg
vgcfgbackup vgconvert vgextend vgmknodes vgs
vgcfgrestore vgcreate vgimport vgreduce vgscan
vgchange vgdisplay vgimportclone vgremove vgsplit
vgck vgexport vgmerge vgrename
[root@runsdata-test-0004 ~]# vg
創建卷組VG,名字可以隨意起
這個卷組我是專門給docker以及data存儲數據使用的,那么就命名為vgdata。
下面就創建一個vgdata的卷組,然后使用vgs以及vgdisplay查看一下創建后的信息。

[root@runsdata-test-0004 ~]# vgcreate vgdocker /dev/vdb1 ## 測試創建一下
Volume group "vgdocker" successfully created
[root@runsdata-test-0004 ~]#
[root@runsdata-test-0004 ~]# vgremove vgdocker ## 刪除之前創建的
Volume group "vgdocker" successfully removed

將前面的兩個PV創建到vgdata的邏輯組中。

[root@runsdata-test-0004 ~]# vgcreate vgdata /dev/vdc1 /dev/vdb1
Volume group "vgdata" successfully created
[root@runsdata-test-0004 ~]#

查看vg的信息

[root@runsdata-test-0004 ~]# vgs
VG #PV #LV #SN Attr VSize VFree
vgdata 2 0 0 wz--n- 99.99g 99.99g
[root@runsdata-test-0004 ~]#

查看vg的詳細信息

[root@runsdata-test-0004 ~]# vgdisplay
--- Volume group ---
VG Name vgdata
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 99.99 GiB
PE Size 4.00 MiB
Total PE 25598
Alloc PE / Size 0 / 0
Free PE / Size 25598 / 99.99 GiB
VG UUID 52PHwY-0a16-1yPo-EYNE-YUv0-4LJx-CWZsZS

[root@runsdata-test-0004 ~]#
創建好了卷組之后,下面就要創建邏輯卷了。

創建邏輯卷LV
首先查看一下lvcreate的相關命令參數

[root@runsdata-test-0004 ~]# lvcreate --help
lvcreate - Create a logical volume
現在我打算給docker使用的邏輯卷使用50G左右,data目錄使用邏輯卷50G左右。那么就需要創建兩個50G大小的邏輯卷。

創建大小50G名稱docker的lv ,-L 指定大小,-n指定名稱

[root@runsdata-test-0004 ~]# lvcreate -L 50G -n docker vgdata
Logical volume "docker" created.
[root@runsdata-test-0004 ~]#

再創建一個50G的data邏輯卷報錯,提示空間不足了,因為邏輯組只有 < 99G 的大小

[root@runsdata-test-0004 ~]# lvcreate -L 50G -n data vgdata
Volume group "vgdata" has insufficient free space (12798 extents): 12800 required.
[root@runsdata-test-0004 ~]#

那么就創建一個49G的data邏輯卷LV

[root@runsdata-test-0004 ~]# lvcreate -L 49G -n data vgdata
Logical volume "data" created.
[root@runsdata-test-0004 ~]#
查看邏輯卷LV的信息
[root@runsdata-test-0004 ~]# lvdisplay
--- Logical volume ---
LV Path /dev/vgdata/docker
LV Name docker
VG Name vgdata
LV UUID XWcgud-iAYP-j2Mo-x8kq-SjQ2-edP2-Usa4RZ
LV Write Access read/write
LV Creation host, time runsdata-test-0004, 2018-12-10 13:57:01 +0800
LV Status available

open 0

LV Size 50.00 GiB
Current LE 12800
Segments 2
Allocation inherit
Read ahead sectors auto

  • currently set to 8192
    Block device 252:0

--- Logical volume ---
LV Path /dev/vgdata/data
LV Name data
VG Name vgdata
LV UUID HVfQpR-Zs81-RFiZ-rAFC-lBMk-bMhe-MTB1zl
LV Write Access read/write
LV Creation host, time runsdata-test-0004, 2018-12-10 13:58:36 +0800
LV Status available

open 0

LV Size 49.00 GiB
Current LE 12544
Segments 1
Allocation inherit
Read ahead sectors auto

  • currently set to 8192
    Block device 252:1

[root@runsdata-test-0004 ~]#
那么這時候已經有docker、data兩個邏輯卷了,下面就是進行格式化,目錄的掛載了。

邏輯卷格式化
執行lvdisplay查看邏輯卷信息,獲取邏輯卷LV的Path
對邏輯卷進行格式化mkfs.ext4 /dev/vgdata/docker

查看lv的詳細信息

[root@runsdata-test-0004 ~]# lvdisplay
--- Logical volume ---
LV Path /dev/vgdata/docker
LV Name docker
VG Name vgdata
LV UUID XWcgud-iAYP-j2Mo-x8kq-SjQ2-edP2-Usa4RZ
LV Write Access read/write
LV Creation host, time runsdata-test-0004, 2018-12-10 13:57:01 +0800
LV Status available

open 0

LV Size 50.00 GiB
Current LE 12800
Segments 2
Allocation inherit
Read ahead sectors auto

  • currently set to 8192
    Block device 252:0

--- Logical volume ---
LV Path /dev/vgdata/data
LV Name data
VG Name vgdata
LV UUID HVfQpR-Zs81-RFiZ-rAFC-lBMk-bMhe-MTB1zl
LV Write Access read/write
LV Creation host, time runsdata-test-0004, 2018-12-10 13:58:36 +0800
LV Status available

open 0

LV Size 49.00 GiB
Current LE 12544
Segments 1
Allocation inherit
Read ahead sectors auto

  • currently set to 8192
    Block device 252:1

對邏輯卷進行ext4格式化

[root@runsdata-test-0004 ~]# mkfs.ext4 /dev/vgdata/docker
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
3276800 inodes, 13107200 blocks
655360 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2162163712
400 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, 1605632, 2654208,
4096000, 7962624, 11239424

Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

對邏輯卷進行ext4格式化

[root@runsdata-test-0004 ~]# mkfs.ext4 /dev/vgdata/data
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
3211264 inodes, 12845056 blocks
642252 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2162163712
392 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, 1605632, 2654208,
4096000, 7962624, 11239424

Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

[root@runsdata-test-0004 ~]#
掛載文件目錄
[root@runsdata-test-0004 ~]# cd /
[root@runsdata-test-0004 /]# ls
bin dev home lib64 media opt root sbin sys usr
boot etc lib lost+found mnt proc run srv tmp var
[root@runsdata-test-0004 /]# mkdir docker
[root@runsdata-test-0004 /]#
[root@runsdata-test-0004 /]# mount /dev/vgdata/docker docker
[root@runsdata-test-0004 /]#
[root@runsdata-test-0004 /]# mkdir data
[root@runsdata-test-0004 /]#
[root@runsdata-test-0004 /]# mount /dev/vgdata/data data
[root@runsdata-test-0004 /]#
[root@runsdata-test-0004 /]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/vda1 40G 1.5G 36G 4% /
devtmpfs 7.8G 0 7.8G 0% /dev
tmpfs 7.8G 0 7.8G 0% /dev/shm
tmpfs 7.8G 352K 7.8G 1% /run
tmpfs 7.8G 0 7.8G 0% /sys/fs/cgroup
tmpfs 1.6G 0 1.6G 0% /run/user/0
/dev/mapper/vgdata-docker 50G 53M 47G 1% /docker
/dev/mapper/vgdata-data 49G 53M 46G 1% /data
[root@runsdata-test-0004 /]#
可以看到 /docker 和 /data 目錄已經使用上了。

測試寫入文件看看。

[root@runsdata-test-0004 /]# cd /docker/
[root@runsdata-test-0004 docker]# pwd
/docker
[root@runsdata-test-0004 docker]# ls
lost+found
[root@runsdata-test-0004 docker]#
[root@runsdata-test-0004 docker]# echo 123 > 1.txt
[root@runsdata-test-0004 docker]# ls
1.txt lost+found
[root@runsdata-test-0004 docker]# cat 1.txt
123
[root@runsdata-test-0004 docker]#
好了,寫到這里基本上已經可以了,但是如果服務器重啟的話,是無法自動掛載上/docker和/data目錄的。

下面來設置一下磁盤開機的自動掛載。

設置磁盤開機自動掛載,配置/etc/fstab文件
需要讓系統開機自動掛載,需要將掛載信息寫入到/etc/fstab文件中。

[root@runsdata-test-0004 docker]# vim /etc/fstab

/etc/fstab

Created by anaconda on Sun Oct 15 15:19:00 2017

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

UUID=eb448ab..省略...6a31 / ext4 defaults 1 1
/dev/mapper/vgdata-docker /docker ext4 defaults 1 1
/dev/mapper/vgdata-data /data ext4 defaults 1 1
然后進行重啟reboot測試一下。

reboot測試
LVM管理的好處就是靈活得擴容、管理磁盤,后續可以再寫一個擴容磁盤的篇章。

參考文獻
CentOS 7.2 添加磁盤並創建新區
CentOS7下LVM的簡單創建
LVM基礎詳細說明及動態擴容lvm邏輯卷的操作記錄

作者:DevOps海洋的漁夫
鏈接:https://www.jianshu.com/p/accff9ea7b15
來源:簡書
著作權歸作者所有。商業轉載請聯系作者獲得授權,非商業轉載請注明出處。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM