原本虛擬centos的服務器的磁盤分配的就不大,以前只分配了20G的樣子,因爲最近有裝了很多軟件,好比nifi壓縮版就有1.2G的大小,一會兒沒有磁盤資源了。今晚就折騰在這事上了。node
[root@master spark]# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/centos-root 17G 17G 20K 100% / devtmpfs 2.4G 0 2.4G 0% /dev tmpfs 2.4G 4.0K 2.4G 1% /dev/shm tmpfs 2.4G 12M 2.4G 1% /run tmpfs 2.4G 0 2.4G 0% /sys/fs/cgroup /dev/sda1 1014M 142M 873M 14% /boot tmpfs 479M 0 479M 0% /run/user/1000
df -h
顯示結果:根目錄可用磁盤只有20K。linux
首先須要關閉操做系統,而後在設置中將磁盤調整到須要的容量。
若是選項是灰色的,說明虛擬機有快照,將其快照刪除再操做。apache
備註:這裏經過vmw,擴展master節點10G磁盤資源。centos
[root@master spark]# fdisk -l Disk /dev/sda: 32.2 GB, 32212254720 bytes, 62914560 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: 0x000aad3c Device Boot Start End Blocks Id System /dev/sda1 * 2048 2099199 1048576 83 Linux /dev/sda2 2099200 41943039 19921920 8e Linux LVM Disk /dev/mapper/centos-root: 18.2 GB, 18249416704 bytes, 35643392 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/mapper/centos-swap: 2147 MB, 2147483648 bytes, 4194304 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
備註:新增磁盤驅動目錄爲/dev/sda1,大小爲10G。服務器
[root@master]# fdisk /dev/sda
分別鍵入如下參數:app
p 查看已分區數量(我看到有兩個 /dev/sda1 和/dev/sda2)
n 新增長一個分區
p 分區類型,選擇主分區
分區號選3(1和2已佔用,見上)
回車 默認選擇(起始扇區)
回車 默認選擇(結束扇區)
t 修改分區類型
選分區3
8e 修改成LVM(8e就是LVM)
w 寫分區表,完成後退出fdisk命令elasticsearch
實際操做:maven
[root@master spark]# fdisk /dev/sda 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/sda: 32.2 GB, 32212254720 bytes, 62914560 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: 0x000aad3c Device Boot Start End Blocks Id System /dev/sda1 * 2048 2099199 1048576 83 Linux /dev/sda2 2099200 41943039 19921920 8e Linux LVM Command (m for help): n Partition type: p primary (2 primary, 0 extended, 2 free) e extended Select (default p): p Partition number (3,4, default 3): 3 First sector (41943040-62914559, default 41943040): #直接回車(不輸入任何內容) Using default value 41943040 Last sector, +sectors or +size{K,M,G} (41943040-62914559, default 62914559): #直接回車(不輸入任何內容) Using default value 62914559 Partition 3 of type Linux and of size 10 GiB is set Command (m for help): t Partition number (1-3, default 3): 3 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. WARNING: Re-reading the partition table failed with error 16: Device or resource busy. The kernel still uses the old table. The new table will be used at the next reboot or after you run partprobe(8) or kpartx(8) Syncing disks.
#從新查看從新分區後的分區狀況: [root@master spark]# fdisk /dev/sda 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/sda: 32.2 GB, 32212254720 bytes, 62914560 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: 0x000aad3c Device Boot Start End Blocks Id System /dev/sda1 * 2048 2099199 1048576 83 Linux /dev/sda2 2099200 41943039 19921920 8e Linux LVM /dev/sda3 41943040 62914559 10485760 8e Linux LVM Command (m for help):
注意:格式化以前要重啓機器ide
[spark@master ~]$ mkfs.ext3 /dev/sda3 mke2fs 1.42.9 (28-Dec-2013) mkfs.ext3: Permission denied while trying to determine filesystem size [spark@master ~]$ su root Password: [root@master spark]# mkfs.ext3 /dev/sda3 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 655360 inodes, 2621440 blocks 131072 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=2684354560 80 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 Allocating group tables: done Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done [root@master spark]#
進入lvm管理oop
[root@master]# lvm
實際上如下命令我在centos7下直接操做也行。
關於lvm的一些基礎知識能夠參考:《Linx 卷管理詳解--VG LV PV》
pvcreate /dev/sda3
vgdisplay
要記下」VG Name」,這裏爲centos;再記下」Free PE/Size」的大小,例如這裏爲21513
vgextend centos /dev/sda3
剛纔記下的」VG Name」就在這裏使用。
可是執行到這一步時報錯了:
Couldn't create temporary archive name.
Volume group "centos" metadata archive failed. Internal error:
Attempt to unlock unlocked VG #orphans.
查看了下,由於磁盤實在過小了,沒法執行,刪除一些數據就行。
lvextend -l +9.5G /dev/mapper/centos-root
lvextend
指令用於在線擴展邏輯卷的空間大小,而不中斷應用程序對邏輯卷的訪問。其後有兩個選項
選項 | 說明 |
---|---|
-L | 指定邏輯卷的大小,單位爲「kKmMgGtT」字節,也就是Size |
-l | 指定邏輯卷的大小,單位爲PE數 |
其他兩個參數:+9.5G是磁盤擴增的大小(也能夠是經過vgdisplay
查看的free
的大小【儘可能不徹底使用,小個幾十到幾百M】),後邊的目錄參數/dev/mapper/centos-root
能夠經過df
命令查看
pvdisplay
quit
如下是具體實操操做記錄:
[root@master spark]# pvcreate /dev/sda3 Physical volume "/dev/sda3" successfully created. [root@master spark]# [root@master spark]# vgextend centos /dev/sda3 Couldn't create temporary archive name. Volume group "centos" metadata archive failed. Internal error: Attempt to unlock unlocked VG #orphans. [root@master spark]# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/centos-root 17G 17G 20K 100% / devtmpfs 2.4G 0 2.4G 0% /dev tmpfs 2.4G 4.0K 2.4G 1% /dev/shm tmpfs 2.4G 12M 2.4G 1% /run tmpfs 2.4G 0 2.4G 0% /sys/fs/cgroup /dev/sda1 1014M 142M 873M 14% /boot tmpfs 479M 0 479M 0% /run/user/1000 #磁盤資源不足清理磁盤 [root@master spark]# cd /opt/ [root@master opt]# ls apache-maven-3.5.4 elasticsearch-head-master hdfs-over-ftp-master.zip kibana-6.2.2-linux-x86_64.tar.gz node-v8.9.1.tar.gz zookeeper-3.4.12 apache-maven-3.5.4-bin.tar.gz elasticsearch-head-master.zip jdk1.8.0_171 nifi-1.7.1 scala-2.11.0 zookeeper-3.4.12.tar.gz elasticsearch-6.2.2 hadoop-2.9.0 jdk-8u171-linux-x64.tar.gz nifi-1.7.1-bin.zip scala-2.11.0.tgz elasticsearch-6.2.2.zip hadoop-2.9.0.tar.gz kafka_2.11-1.1.0 node-8.9.1 spark-2.2.1-bin-hadoop2.7 elasticsearch-analysis-ik-6.2.2.zip hdfs-over-ftp-master kibana-6.2.2-linux-x86_64 node-v8.9.1 spark-2.2.1-bin-hadoop2.7.tgz [root@master opt]# rm *.gz rm: remove regular file ‘apache-maven-3.5.4-bin.tar.gz’? y rm: remove regular file ‘hadoop-2.9.0.tar.gz’? y rm: remove regular file ‘jdk-8u171-linux-x64.tar.gz’? y rm: remove regular file ‘kibana-6.2.2-linux-x86_64.tar.gz’? y rm: remove regular file ‘node-v8.9.1.tar.gz’? y rm: remove regular file ‘zookeeper-3.4.12.tar.gz’? y [root@master opt]# rm *.zip rm: remove regular file ‘elasticsearch-6.2.2.zip’? y rm: remove regular file ‘elasticsearch-analysis-ik-6.2.2.zip’? y rm: remove regular file ‘elasticsearch-head-master.zip’? y rm: remove regular file ‘hdfs-over-ftp-master.zip’? y rm: remove regular file ‘nifi-1.7.1-bin.zip’? y [root@master opt]# rm *.tgz rm: remove regular file ‘scala-2.11.0.tgz’? y rm: remove regular file ‘spark-2.2.1-bin-hadoop2.7.tgz’? y #磁盤清理後查看磁盤資源 [root@master opt]# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/centos-root 17G 15G 2.1G 88% / devtmpfs 2.4G 0 2.4G 0% /dev tmpfs 2.4G 4.0K 2.4G 1% /dev/shm tmpfs 2.4G 12M 2.4G 1% /run tmpfs 2.4G 0 2.4G 0% /sys/fs/cgroup /dev/sda1 1014M 142M 873M 14% /boot tmpfs 479M 0 479M 0% /run/user/1000 #重啓服務器 [root@master opt]# reboot #從新登陸 Last login: Tue Aug 7 23:16:33 2018 from 192.168.0.103 [spark@master ~]$ su root Password: [root@master spark]# pvcreate /dev/sda3 WARNING: ext3 signature detected on /dev/sda3 at offset 1080. Wipe it? [y/n]: y Wiping ext3 signature on /dev/sda3. Physical volume "/dev/sda3" successfully created. [root@master spark]# vgdisplay --- 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.00 GiB PE Size 4.00 MiB Total PE 4863 Alloc PE / Size 4863 / <19.00 GiB Free PE / Size 0 / 0 VG UUID cKJ05H-yI4f-5qfY-5SO5-ybTW-2zDx-M5uyg0 [root@master spark]# vgextend centos /dev/sda3 Volume group "centos" successfully extended [root@master spark]# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/centos-root 17G 15G 2.1G 88% / devtmpfs 2.4G 0 2.4G 0% /dev tmpfs 2.4G 0 2.4G 0% /dev/shm tmpfs 2.4G 12M 2.4G 1% /run tmpfs 2.4G 0 2.4G 0% /sys/fs/cgroup /dev/sda1 1014M 142M 873M 14% /boot tmpfs 479M 0 479M 0% /run/user/1000 [root@master spark]# fdisk -l Disk /dev/sda: 32.2 GB, 32212254720 bytes, 62914560 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: 0x000aad3c Device Boot Start End Blocks Id System /dev/sda1 * 2048 2099199 1048576 83 Linux /dev/sda2 2099200 41943039 19921920 8e Linux LVM /dev/sda3 41943040 62914559 10485760 8e Linux LVM Disk /dev/mapper/centos-root: 18.2 GB, 18249416704 bytes, 35643392 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/mapper/centos-swap: 2147 MB, 2147483648 bytes, 4194304 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
以上只是卷擴容了,還要對文件系統實現真正擴容
CentOS 7 下面 因爲使用的是 XFS,因此要用
xfs_growfs /dev/mapper/centos-root
CentOS 6 下面 要用
resize2fs /dev/mapper/centos-root
如下是具體實操操做記錄:
[root@master spark]# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/centos-root 17G 15G 2.1G 88% / devtmpfs 2.4G 0 2.4G 0% /dev tmpfs 2.4G 0 2.4G 0% /dev/shm tmpfs 2.4G 12M 2.4G 1% /run tmpfs 2.4G 0 2.4G 0% /sys/fs/cgroup /dev/sda1 1014M 142M 873M 14% /boot tmpfs 479M 0 479M 0% /run/user/1000 [root@master spark]# xfs_growfs /dev/mapper/centos-root meta-data=/dev/mapper/centos-root isize=512 agcount=4, agsize=1113856 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=0 spinodes=0 data = bsize=4096 blocks=4455424, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=1 log =internal bsize=4096 blocks=2560, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0 data blocks changed from 4455424 to 6945792 [root@master spark]# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/centos-root 27G 15G 12G 57% / devtmpfs 2.4G 0 2.4G 0% /dev tmpfs 2.4G 0 2.4G 0% /dev/shm tmpfs 2.4G 12M 2.4G 1% /run tmpfs 2.4G 0 2.4G 0% /sys/fs/cgroup /dev/sda1 1014M 142M 873M 14% /boot tmpfs 479M 0 479M 0% /run/user/1000
df -h