原本虚拟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