Reasons for insufficient root directory space
1.1 The inode is full
Although the block is left, the inode is full. Therefore, when creating a new directory or file, the system prompts that the disk space is insufficient. The inode is translated into Chinese as an index node, and each storage device (such as a hard disk) or the partition of the storage device is formatted After being transformed into a file system, there should be two parts, one part is an inode, the other part is a block. The block is used to store data, and the inode is used to store the information of these data, including file size. , Owner, user group to which it belongs, read and write permissions, etc. The inode indexes the information for each file, so there is the value of the inode. According to the instruction, the operating system can find the corresponding file the fastest through the inode value.
phenomenon:
Use df -Th
with room to spare but can not continue to use
(see inode occupation command: df -i
)
Solution
Delete useless temporary files and release inode
Traverse to find files with 0 bytes and delete them.
find / -type f -size 0 -exec rm {} \;
The root directory includes all directories, and some directories are mounted on the disk, these directories will not occupy the system disk space under the root directory.
When there is insufficient space in the root directory, just pay attention to the file size of those files that are not mounted, and use the du command to view the size of each directory (only one level of directory is displayed)
1.2 Too many large files
Use the du command to view the size of each directory (Only display one level of directory)
du -ah --max-depth=1 /
1.3 Too many log files
Log files will be generated when the Linux system is running, you can talk about remote backup of the log files, or copy to other hard disks
If none of the above methods work, you can use the soft connection method, or expand the root directory
Solution
2.1 Soft connection
Copy the directory that takes up a lot of space to another disk, or the storage provided by nfs
For example
, /opt/nfs
the file on one server A (IP: 20.0.0.105) is too large, you can install nfs shared storage on another server B (IP: 20.0.0.104), and then mount it. Copying the contents in the past.
[root@serverb ~]# yum -y install nfs-utils rpcbind
[root@serverb ~]# vi /etc/exports
/opt 20.0.0.0/24(rw)
[root@serverb ~]# systemctl start nfs
[root@servera ~]# showmount -e 20.0.0.104
Export list for 20.0.0.104:
/opt 20.0.0.0/24
[root@servera ~]# mkdir centos
[root@servera ~]# mount 20.0.0.104:/opt /centos/
[root@servera ~]# df -Th
文件系统 类型 容量 已用 可用 已用% 挂载点
···········
20.0.0.104:/opt nfs4 39G 2.4G 36G 7% /centos
[root@servera ~]# cp -R /opt/nfs/* /centos/
[root@servera ~]# ln -s /centos/ /opt/nfs
2.2: Root directory expansion
Usage scenario: The storage space of the device is full and has been cleaned up, and other hard disks are full. The physical hardware of the server supports adding hard disks
Add a new hard drive
[root@localhost ~]# init 6 #硬盘很少有支持热插拔的,需要重启
连接断开
连接成功
[root@localhost ~]# fdisk -l
磁盘 /dev/sdb:21.5 GB, 21474836480 字节,41943040 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘 /dev/sda:64.4 GB, 64424509440 字节,125829120 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x0009ed77
设备 Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 125829119 61864960 8e Linux LVM
磁盘 /dev/mapper/centos-root:41.1 GB, 41120956416 字节,80314368 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘 /dev/mapper/centos-swap:2147 MB, 2147483648 字节,4194304 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘 /dev/mapper/centos-home:20.1 GB, 20073938944 字节,39206912 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
[root@localhost ~]# fdisk /dev/sdb
欢迎使用 fdisk (util-linux 2.23.2)。
更改将停留在内存中,直到您决定将更改写入磁盘。
使用写入命令前请三思。
Device does not contain a recognized partition table
使用磁盘标识符 0xf60c7ee0 创建新的 DOS 磁盘标签。
命令(输入 m 获取帮助):n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p
分区号 (1-4,默认 1):
起始 扇区 (2048-41943039,默认为 2048):
将使用默认值 2048
Last 扇区, +扇区 or +size{K,M,G} (2048-41943039,默认为 41943039):
将使用默认值 41943039
分区 1 已设置为 Linux 类型,大小设为 20 GiB
命令(输入 m 获取帮助):t
已选择分区 1
Hex 代码(输入 L 列出所有代码):8e
已将分区“Linux”的类型更改为“Linux LVM”
命令(输入 m 获取帮助):w
The partition table has been altered!
Calling ioctl() to re-read partition table.
正在同步磁盘。
[root@localhost ~]# mkfs -t xfs /dev/sdb1
meta-data=/dev/sdb1 isize=512 agcount=4, agsize=1310656 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=5242624, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal log bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
[root@localhost ~]# lvm
lvm> pvcreate /dev/sdb1
WARNING: xfs signature detected on /dev/sdb1 at offset 0. Wipe it? [y/n]: y
Wiping xfs signature on /dev/sdb1.
Physical volume "/dev/sdb1" successfully created.
lvm> vgdisplay
--- Volume group ---
VG Name centos
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 4
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 3
Open LV 3
Max PV 0
Cur PV 1
Act PV 1
VG Size <59.00 GiB
PE Size 4.00 MiB
Total PE 15103
Alloc PE / Size 15102 / 58.99 GiB
Free PE / Size 1 / 4.00 MiB
VG UUID Cnl1hp-dBeF-55rw-KU0p-co0L-FiSn-5Nrs2d
lvm> vgextend centos /dev/sdb1
Volume group "centos" successfully extended
lvm> vgdisplay
--- Volume group ---
VG Name centos
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 5
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 3
Open LV 3
Max PV 0
Cur PV 2
Act PV 2
VG Size 78.99 GiB
PE Size 4.00 MiB
Total PE 20222
Alloc PE / Size 15102 / 58.99 GiB
Free PE / Size 5120 / 20.00 GiB
VG UUID Cnl1hp-dBeF-55rw-KU0p-co0L-FiSn-5Nrs2d
lvm> lvextend -l +5120 /dev/mapper/centos-root
Size of logical volume centos/root changed from <38.30 GiB (9804 extents) to <58.30 GiB (14924 extents).
Logical volume centos/root successfully resized.
lvm> lvdisplay
--- Logical volume ---
LV Path /dev/centos/root
LV Name root
VG Name centos
LV UUID OeHFno-diSX-xWuQ-K8j6-tdpT-D0KE-YB3jxG
LV Write Access read/write
LV Creation host, time localhost, 2021-02-01 22:26:07 -0500
LV Status available
# open 1
LV Size <58.30 GiB
Current LE 14924
Segments 3
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:0
--- Logical volume ---
LV Path /dev/centos/home
LV Name home
VG Name centos
LV UUID ne6xL1-fepP-cE9h-WJzc-12Kw-FVzK-NNYU6i
LV Write Access read/write
LV Creation host, time localhost, 2021-02-01 22:26:07 -0500
LV Status available
# open 1
LV Size <18.70 GiB
Current LE 4786
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:2
--- Logical volume ---
LV Path /dev/centos/swap
LV Name swap
VG Name centos
LV UUID 7mtj59-3PN7-1UbZ-QiJa-He5b-hGTz-SCpicW
LV Write Access read/write
LV Creation host, time localhost, 2021-02-01 22:26:07 -0500
LV Status available
# open 2
LV Size 2.00 GiB
Current LE 512
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:1
lvm> exit
Exiting.
[root@localhost ~]# df -Th
文件系统 类型 容量 已用 可用 已用% 挂载点
/dev/mapper/centos-root xfs 39G 1.5G 37G 4% /
devtmpfs devtmpfs 898M 0 898M 0% /dev
tmpfs tmpfs 910M 0 910M 0% /dev/shm
tmpfs tmpfs 910M 9.6M 901M 2% /run
tmpfs tmpfs 910M 0 910M 0% /sys/fs/cgroup
/dev/sda1 xfs 1014M 146M 869M 15% /boot
/dev/mapper/centos-home xfs 19G 33M 19G 1% /home
tmpfs tmpfs 182M 0 182M 0% /run/user/0
[root@localhost ~]# xfs_growfs /dev/mapper/centos-root
meta-data=/dev/mapper/centos-root isize=512 agcount=4, agsize=2509824 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=10039296, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal bsize=4096 blocks=4902, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 10039296 to 15282176
[root@localhost ~]# df -Th
文件系统 类型 容量 已用 可用 已用% 挂载点
/dev/mapper/centos-root xfs 59G 1.5G 57G 3% /
devtmpfs devtmpfs 898M 0 898M 0% /dev
tmpfs tmpfs 910M 0 910M 0% /dev/shm
tmpfs tmpfs 910M 9.6M 901M 2% /run
tmpfs tmpfs 910M 0 910M 0% /sys/fs/cgroup
/dev/sda1 xfs 1014M 146M 869M 15% /boot
/dev/mapper/centos-home xfs 19G 33M 19G 1% /home
tmpfs tmpfs 182M 0 182M 0% /run/user/0
[root@localhost ~]#