CentOS 7 下的LVM 實戰

一、背景

    前段時間收到zabbix的報警信息 PROBLEM: Free disk space is less than 20% on volume /

    

    通過df h可以得知,我們做了一個VGname爲centos的LVM ,並且在/home下還有46G可用,但是centos 7的LVM 文件系統格式爲xfs,而xfs文件系統只能增加VG的大小,不能減少。

    通過vgdisplay查看只有16M可用的PE 。

    


    因此這裏爲解決這個問題,我選擇新增一塊硬盤,通過LVM  加入VG  centos中來擴大 目錄 / 的容量

二、增加硬盤

    插入硬盤後可通過fdisk l來查看,這裏的sdb就是我新增加的硬盤。

    


三、LVM

    具體步驟如下

        1. 用 fdisk 設定新的具有 8e system ID 的 partition

        2. 利用 pvcreate 建置 PV

        3. 利用 vgextend 將 PV 加入VG centos

        4. 利用 lvresize 將新加入的 PV 內的 PE 加入 root 中

        5. 透過 xfs_growfs 將文件系統的容量確實增加


    3.1用 fdisk 設定新的具有 8e system ID 的 partition


    [root@zabbix-server dev]# 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 0xf93c2ab9.


    Command (m for help): p


    Disk /dev/sdb: 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: 0xf93c2ab9


      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): p


    Disk /dev/sdb: 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: 0xf93c2ab9


      Device Boot      Start         End      Blocks   Id  System

    /dev/sdb1            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/sdb: 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: 0xf93c2ab9


      Device Boot      Start         End      Blocks   Id  System

    /dev/sdb1            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@zabbix-server dev]#partprobe  不要忘記這一步

    格式化 mkfs.xfs /dev/sdb1


3.2利用 pvcreate 建置 PV

    [root@zabbix-server dev]#pvcreate  /dev/sdb1


    3.3利用 vgextend 將 PV 加入VG  centos

    [root@zabbix-server dev]#vgextend  centos /dev/sdb1


3.4利用 lvresize 將新加入的 PV 內的 PE 加入 root 中

    [root@zabbix-server dev]# lvextend -L +50G /dev/centos/root


3.5透過 xfs_growfs 將文件系統的容量確實增加

    [root@zabbix-server dev]#xfs_growfs  /dev/mapper/centos-root

    

  

    3.6通過dh –hT來驗證結果

        wKioL1fuIpWw9iHgAACqO6IeaK0814.jpg

 配置完成後過一會兒就收到了報警正常的郵件。    

    wKiom1fuItWx3P7kAADTG3_qcjs358.jpg       


謝謝你打開這篇博文,並一直堅持看到了這裏,如果覺得對你有幫助,請不要吝嗇點一下右下角的贊。


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章