Centos 8.2 lvm配置与扩容

一、安装Centos8.2:

VMWare安装centos8.2

个人习惯配置
在这里插入图片描述

二、修改镜像源:

备份镜像源配置文件:

[root@STEM-Centos ~]# cd /etc/yum.repos.d
[root@STEM-Centos yum.repos.d]# cp CentOS-Base.repo CentOS-Base.repo.bak
[root@STEM-Centos yum.repos.d]# cp CentOS-AppStream.repo CentOS-AppStream.repo.bak
[root@STEM-Centos yum.repos.d]# cp CentOS-Extras.repo CentOS-Extras.repo.bak

修改镜像源配置文件:

[root@STEM-Centos yum.repos.d]# sed -i 's|mirrorlist=|#mirrorlist=|g' CentOS-Base.repo CentOS-AppStream.repo CentOS-Extras.repo
[root@STEM-Centos yum.repos.d]# sed -i 's|#baseurl=|baseurl=|g' CentOS-Base.repo CentOS-AppStream.repo CentOS-Extras.repo
[root@STEM-Centos yum.repos.d]# sed -i 's|http://mirror.centos.org|https://mirrors.aliyun.com|g' CentOS-Base.repo CentOS-AppStream.repo CentOS-Extras.repo

设置http代理:

[root@STEM-Centos yum.repos.d]# export http_proxy=10.10.20.58:3128
[root@STEM-Centos yum.repos.d]# export https_proxy=10.10.20.58:3128

三、Centos升级:

[root@STEM-Centos ~]# dnf -y update
Last metadata expiration check: 14:46:55 ago on Thu 17 Sep 2020 05:58:00 PM CST.
Dependencies resolved.
Nothing to do.
Complete!

四、创建LVM分区:

查看磁盘:

[root@STEM-Centos ~]# fdisk -l
Disk /dev/sdb: 50 GiB, 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/sdc: 50 GiB, 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/sda: 100 GiB, 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
Disklabel type: dos
Disk identifier: 0x998d4abe
......

#发现新挂载磁盘 sdb和sdc
#/dev/sdb: 50 GiB 
#/dev/sdc: 50 GiB

创建lvm格式磁盘(sdb):

[root@STEM-Centos ~]# fdisk /dev/sdb

Welcome to fdisk (util-linux 2.32.1).
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.
Created a new DOS disklabel with disk identifier 0x20465fca.

#新建分区
Command (m for help): n 
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
#选择新建主分区
Select (default p): p
Partition number (1-4, default 1): 
First sector (2048-104857599, default 2048): 
Last sector, +sectors or +size{K,M,G,T,P} (2048-104857599, default 104857599): 

Created a new partition 1 of type 'Linux' and of size 50 GiB.
#修改分区格式
Command (m for help): t
Selected partition 1
#显示分区格式列表
Hex code (type L to list all codes): L

......   
 8  AIX             4e  QNX4.x 2nd part 8e  Linux LVM       df  BootIt         
...... 
#选择 8e
Hex code (type L to list all codes): 8e
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.
Syncing disks.

新建pv:

#查看新建磁盘
[root@STEM-Centos ~]# fdisk -l /dev/sdb
Disk /dev/sdb: 50 GiB, 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
Disklabel type: dos
Disk identifier: 0x20465fca

Device     Boot Start       End   Sectors Size Id Type
/dev/sdb1        2048 104857599 104855552  50G 8e Linux LVM
#用新建磁盘创建PV
[root@STEM-Centos ~]# pvcreate /dev/sdb1
  Physical volume "/dev/sdb1" successfully created.
#查看pv
[root@STEM-Centos ~]# pvdisplay
  --- Physical volume ---
  PV Name               /dev/sda2
  VG Name               cl
  PV Size               <99.00 GiB / not usable 3.00 MiB
  Allocatable           yes 
  PE Size               4.00 MiB
  Total PE              25343
  Free PE               1
  Allocated PE          25342
  PV UUID               GgFkci-0Mpm-2XW3-YPSx-0sG3-RcSR-jP7wfd
   
  "/dev/sdb1" is a new physical volume of "<50.00 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/sdb1
  VG Name               
  PV Size               <50.00 GiB
  Allocatable           NO
  PE Size               0   
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               bYi0ek-0dMT-gRgG-fLog-4x5P-tput-ajFugL
#找到新建PV  /dev/sdb1
#新建pv /dev/sdb1 未划入VG组

创建vg组:

[root@STEM-Centos ~]# vgcreate vg_data /dev/sdb1
  Volume group "vg_data" successfully created
[root@STEM-Centos ~]# vgdisplay
  --- Volume group ---
  VG Name               vg_data
  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               <50.00 GiB
  PE Size               4.00 MiB
  Total PE              12799
  Alloc PE / Size       0 / 0   
  Free  PE / Size       12799 / <50.00 GiB
  VG UUID               e7Xahv-JR52-urzN-do1c-b9HH-Ocdc-b1dATx
   
 ......

创建lv:

#分配vg组 vg_data所有剩余空间
[root@STEM-Centos ~]# lvcreate -l 100%free -n lv_data vg_data
  Logical volume "lv_data" created.
[root@STEM-Centos ~]# lvdisplay
  --- Logical volume ---
  LV Path                /dev/vg_data/lv_data
  LV Name                lv_data
  VG Name                vg_data
  LV UUID                ZnPdkg-kyqG-Pu9B-V52v-nlqa-KCVD-3c3lNW
  LV Write Access        read/write
  LV Creation host, time STEM-Centos, 2020-09-18 09:07:45 +0800
  LV Status              available
  # open                 0
  LV Size                <50.00 GiB
  Current LE             12799
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:4
   
  ......

格式化lv分区:

[root@STEM-Centos ~]# fdisk -l
Disk /dev/sdb: 50 GiB, 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
Disklabel type: dos
Disk identifier: 0x20465fca

Device     Boot Start       End   Sectors Size Id Type
/dev/sdb1        2048 104857599 104855552  50G 8e Linux LVM

.......
Disk /dev/mapper/vg_data-lv_data: 50 GiB, 53682896896 bytes, 104849408 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

#用xfs格式化新建lv
[root@STEM-Centos ~]# mkfs.xfs /dev/mapper/vg_data-lv_data
meta-data=/dev/mapper/vg_data-lv_data isize=512    agcount=4, agsize=3276544 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=1, sparse=1, rmapbt=0
         =                       reflink=1
data     =                       bsize=4096   blocks=13106176, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0, ftype=1
log      =internal log           bsize=4096   blocks=6399, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0

创建目录挂载lv分区:

[root@STEM-Centos ~]# mkdir /app
[root@STEM-Centos ~]# mount /dev/mapper/vg_data-lv_data /app
[root@STEM-Centos ~]# df -h
Filesystem                   Size  Used Avail Use% Mounted on
devtmpfs                     7.8G     0  7.8G   0% /dev
tmpfs                        7.8G     0  7.8G   0% /dev/shm
tmpfs                        7.8G  8.7M  7.8G   1% /run
tmpfs                        7.8G     0  7.8G   0% /sys/fs/cgroup
/dev/mapper/cl-root           20G  1.6G   19G   8% /
/dev/mapper/cl-home           20G  175M   20G   1% /home
/dev/mapper/cl-Data           43G  340M   43G   1% /Data
/dev/sda1                    976M  198M  711M  22% /boot
tmpfs                        1.6G     0  1.6G   0% /run/user/0
/dev/mapper/vg_data-lv_data   50G  390M   50G   1% /app

修改开机自动挂载:

[root@STEM-Centos ~]# vi /etc/fstab

#添加如下内容
/dev/mapper/vg_data-lv_data     /app            xfs     defaults        0 0

五、LVM扩容

查看磁盘:

[root@STEM-Centos ~]# fdisk -l
Disk /dev/sda: 100 GiB, 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
Disklabel type: dos
Disk identifier: 0x998d4abe

Device     Boot   Start       End   Sectors Size Id Type
/dev/sda1  *       2048   2099199   2097152   1G 83 Linux
/dev/sda2       2099200 209715199 207616000  99G 8e Linux LVM


Disk /dev/sdc: 50 GiB, 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/sdb: 50 GiB, 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
Disklabel type: dos
Disk identifier: 0x20465fca

Device     Boot Start       End   Sectors Size Id Type
/dev/sdb1        2048 104857599 104855552  50G 8e Linux LVM

......

#发现新挂载磁盘 sdc
#/dev/sdc: 50 GiB

创建lvm格式磁盘(sdc):

[root@STEM-Centos ~]# fdisk /dev/sdc

Welcome to fdisk (util-linux 2.32.1).
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.
Created a new DOS disklabel with disk identifier 0xcc5a7c93.

Command (m for help): n       
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p): p
Partition number (1-4, default 1): 
First sector (2048-104857599, default 2048): 
Last sector, +sectors or +size{K,M,G,T,P} (2048-104857599, default 104857599): 

Created a new partition 1 of type 'Linux' and of size 50 GiB.

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/sdc: 50 GiB, 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
Disklabel type: dos
Disk identifier: 0xcc5a7c93

Device     Boot Start       End   Sectors Size Id Type
/dev/sdc1        2048 104857599 104855552  50G 8e Linux LVM

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

新建pv:

[root@STEM-Centos ~]# fdisk -l /dev/sdc
Disk /dev/sdc: 50 GiB, 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
Disklabel type: dos
Disk identifier: 0xcc5a7c93

Device     Boot Start       End   Sectors Size Id Type
/dev/sdc1        2048 104857599 104855552  50G 8e Linux LVM
[root@STEM-Centos ~]# pvcreate /dev/sdc1
  Physical volume "/dev/sdc1" successfully created.
[root@STEM-Centos ~]# pvdisplay
  --- Physical volume ---
  PV Name               /dev/sdb1
  VG Name               vg_data
  PV Size               <50.00 GiB / not usable 3.00 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              12799
  Free PE               0
  Allocated PE          12799
  PV UUID               bYi0ek-0dMT-gRgG-fLog-4x5P-tput-ajFugL
   
  --- Physical volume ---
  PV Name               /dev/sda2
  VG Name               cl
  PV Size               <99.00 GiB / not usable 3.00 MiB
  Allocatable           yes 
  PE Size               4.00 MiB
  Total PE              25343
  Free PE               1
  Allocated PE          25342
  PV UUID               GgFkci-0Mpm-2XW3-YPSx-0sG3-RcSR-jP7wfd
   
  "/dev/sdc1" is a new physical volume of "<50.00 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/sdc1
  VG Name               
  PV Size               <50.00 GiB
  Allocatable           NO
  PE Size               0   
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               5BwRRE-xsFO-0hId-e7Wx-1mJw-pCxn-RUTaew

#找到新建PV  /dev/sdc1
#新建pv /dev/sdc1 未加入vg组

扩展vg(将/dev/sdc1 加入 vg_data):

#新建pv /dev/sdc1 扩展vg_data组
[root@STEM-Centos ~]# vgextend vg_data /dev/sdc1
  Volume group "vg_data" successfully extended
[root@STEM-Centos ~]# vgdisplay
  --- Volume group ---
  VG Name               vg_data
  System ID             
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  3
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                1
  Open LV               1
  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       12799 / <50.00 GiB
  Free  PE / Size       12799 / <50.00 GiB
  VG UUID               e7Xahv-JR52-urzN-do1c-b9HH-Ocdc-b1dATx
   
  --- Volume group ---
  VG Name               cl
  System ID             
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  5
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                4
  Open LV               4
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               <99.00 GiB
  PE Size               4.00 MiB
  Total PE              25343
  Alloc PE / Size       25342 / 98.99 GiB
  Free  PE / Size       1 / 4.00 MiB
  VG UUID               rSkqAV-uU68-0xNn-xZrW-CNzJ-754y-sexNfu

刷新文件系统,使扩展生效:

#刷新前
[root@STEM-Centos ~]# df -h
Filesystem                   Size  Used Avail Use% Mounted on
devtmpfs                     7.8G     0  7.8G   0% /dev
tmpfs                        7.8G     0  7.8G   0% /dev/shm
tmpfs                        7.8G  8.7M  7.8G   1% /run
tmpfs                        7.8G     0  7.8G   0% /sys/fs/cgroup
/dev/mapper/cl-root           20G  1.6G   19G   8% /
/dev/mapper/vg_data-lv_data   50G  390M   50G   1% /app
/dev/mapper/cl-Data           43G  340M   43G   1% /Data
/dev/mapper/cl-home           20G  175M   20G   1% /home
/dev/sda1                    976M  198M  711M  22% /boot
tmpfs                        1.6G     0  1.6G   0% /run/user/0

#刷新扩展lv容量(lvm格式)
[root@STEM-Centos ~]# xfs_growfs /dev/mapper/vg_data-lv_data
meta-data=/dev/mapper/vg_data-lv_data isize=512    agcount=4, agsize=3276544 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=1, sparse=1, rmapbt=0
         =                       reflink=1
data     =                       bsize=4096   blocks=13106176, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0, ftype=1
log      =internal log           bsize=4096   blocks=6399, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 13106176 to 26212352

[root@STEM-Centos ~]# df -h
Filesystem                   Size  Used Avail Use% Mounted on
devtmpfs                     7.8G     0  7.8G   0% /dev
tmpfs                        7.8G     0  7.8G   0% /dev/shm
tmpfs                        7.8G  8.7M  7.8G   1% /run
tmpfs                        7.8G     0  7.8G   0% /sys/fs/cgroup
/dev/mapper/cl-root           20G  1.6G   19G   8% /
/dev/mapper/vg_data-lv_data  100G  747M  100G   1% /app
/dev/mapper/cl-Data           43G  340M   43G   1% /Data
/dev/mapper/cl-home           20G  175M   20G   1% /home
/dev/sda1                    976M  198M  711M  22% /boot
tmpfs                        1.6G     0  1.6G   0% /run/user/0

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值