题记(心急的小伙伴命令集锦在文章末尾):
博客首页突然打不开了,以为前端代码问题。本地测试后发现后台端口报错。本地直接运行后端代码请求发现报如下错:
2020-11-22 20:36:40,188 INFO sqlalchemy.engine.base.Engine {}
(pymysql.err.InternalError) (3, "Error writing file '/tmp/MYvohWfH' (Errcode: 28 - No space left on device)") [SQL: "select ......
2020-11-22 20:36:40,662 INFO sqlalchemy.engine.base.Engine ROLLBACK
我的妈呀磁盘满了!想必是开了一个礼拜的爬虫爬了太多图片把磁盘占满了。打开文件MinIO服务器,果然如此:
但是我是1T的硬盘不该不够呀。
原因:
在安装centos系统的时候,如果在安装时没有分配磁盘空间,选择的是默认分配的(默认50G),在安装完成后,可以发现大容量磁盘往往分配在了home下面。
操作:
1、查磁盘使用情况:
[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 50G 50G 20K 100% /
devtmpfs 3.8G 0 3.8G 0% /dev
tmpfs 3.8G 0 3.8G 0% /dev/shm
tmpfs 3.8G 9.2M 3.8G 1% /run
tmpfs 3.8G 0 3.8G 0% /sys/fs/cgroup
/dev/sda1 1014M 209M 806M 21% /boot
/dev/mapper/centos-home 873G 33M 873G 1% /home
tmpfs 771M 0 771M 0% /run/user/0
果然centos-root只有50G, centos-home下有大量空闲存储。
2、将centos-home扩展到centos-root
A、备份home,home 没有文件 或者不需要了省略 直接下一步
cp -r /home/ homebak/
but没那么简单提示:
cp: error writing ‘homebak/damon/.bash_logout’: No space left on device
存储不够必须先腾点存储,于是rm -rf ... 了一些文件,用df -h 查看没变化的话 可以 reboot下,备份成功后,卸载挂载
B、卸载挂载
umount /home
notice:卸载时,发现/home在使用中,所以先终止。
fuser -km /home/(终止)
C、删除/home所在的lv
[root@localhost /]# lvremove /dev/mapper/centos-home
Do you really want to remove active logical volume centos/home? [y/n]: y
空间不够也可能会报错 /etc/lvm/archive/.lvm_localhost.localdomain_18265_1825144420: write error failed: No space left on device,
如上rm 腾空间就好
D、扩展centos-root
扩展的话使用
lvresize -A n -L +666G /dev/mapper/centos-root
全部合并到centos-root 使用
lvextend -l +100%FREE /dev/mapper/centos-root
正常情况到此为止了,BUT在我这没那么简单,收到如下报错:
Insufficient free space: 170496 extents needed, but only 1 available
E、关于Insufficient free space: 170496 extents needed, but only 1 available的处理
原因:划定vg时已经固定了容量,lv容量从vg扩充,第一次已经将vg的空间全部划给lv,所以无法扩充。需扩充vg,但扩充vg需先扩pv,扩pv需新建分区。(vg、lv、pv 自行脑补:https://blog.csdn.net/lenovouser/article/details/54233570)
所以要建分区才能扩展,如下命令操作:
[root@localhost ~]# fdisk -l (查看磁盘情况) Disk /dev/sda: 1000.2 GB, 1000204886016 bytes, 1953525168 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 4096 bytes I/O size (minimum/optimal): 4096 bytes / 4096 bytes Disk label type: dos Disk identifier: 0x0009b966 Device Boot Start End Blocks Id System /dev/sda1 * 2048 2099199 1048576 83 Linux /dev/sda2 2099200 1953523711 975712256 8e Linux LVM Disk /dev/mapper/centos-root: 53.7 GB, 53687091200 bytes, 104857600 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 4096 bytes I/O size (minimum/optimal): 4096 bytes / 4096 bytes Disk /dev/mapper/centos-swap: 8321 MB, 8321499136 bytes, 16252928 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 4096 bytes I/O size (minimum/optimal): 4096 bytes / 4096 bytes Disk /dev/mapper/centos-home: 937.1 GB, 937112371200 bytes, 1830297600 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 4096 bytes I/O size (minimum/optimal): 4096 bytes / 4096 bytes [root@localhost ~]# fdisk /dev/mapper/centos-home (在centos-home 创建分区)
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 0xd33e4258. The device presents a logical sector size that is smaller than the physical sector size. Aligning to a physical sector (or optimal I/O) size boundary is recommended, or performance may be impacted. 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): 3 First sector (2048-1830297599, default 2048): 1830297599 (我这全部分了) Partition 3 of type Linux and of size 512 B is set Command (m for help): wq The partition table has been altered! Calling ioctl() to re-read partition table. WARNING: Re-reading the partition table failed with error 22: Invalid argument. 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.
F、分区结束后再把 D跑下,然后执行
xfs_growfs /dev/mapper/centos-root
命令集锦1,扩展分区:
1.查看分区
df -h
vgdisplay (查看空闲磁盘大小)
2.备份home分区文件
tar cvf /tmp/home.tar /home
3.卸载/home
umount /home
4.删除/home所在的lv
lvremove /dev/mapper/centos-home
5.扩展/root所在的lv
lvextend -l +100%FREE /dev/mapper/centos-root
6.扩展/root文件系统
xfs_growfs /dev/mapper/centos-root