gpt4 book ai didi

php - Yii2:减少 vServer 上的 inode 使用

转载 作者:太空狗 更新时间:2023-10-29 12:28:10 24 4
gpt4 key购买 nike

在我的 Linux 虚拟服务器上,inode 是有限的(例如 250.000)。我发现 Yii2 安装需要相当多的 inode。 inode的数量大致就是文件和目录的数量。

当前目录及其子目录使用的inode数可以用

find .  -xdev -printf '%h\n' | sort | uniq -c | awk '{total = total + $1}END{print total}'

我的 Yii2 项目平均大约有 30k 个 inode。 ./web/assets./runtime./web/images 文件夹中的文件不多。大多数 inode 都在 ./vendor 目录中使用。

所以我的 Yii2 项目数量限制在 8 个。

如何减少 Yii2 项目中 inode 的使用?

最佳答案

假设您在 Linux vServer 中拥有 root 权限,您可以将一个新的文件系统嵌入到一个文件中并挂载它。这样的文件在父文件系统中只占用一个 inode,而图像中的 inode 数量由您决定。

# dd if=/dev/zero of=myfs bs=1MB count=512
512+0 records in
512+0 records out
512000000 bytes (512 MB) copied, 4.10134 s, 125 MB/s
# losetup --find --show `pwd`/myfs
/dev/loop0
# mkfs -t ext4 -i 1024 /dev/loop0
mke2fs 1.42.12 (29-Aug-2014)
Discarding device blocks: done
Creating filesystem with 500000 1k blocks and 500464 inodes
Filesystem UUID: fef5ab29-8991-4f99-8a27-80b4d11b3133
Superblock backups stored on blocks:
8177, 24529, 40881, 57233, 73585, 204401, 220753, 400625

Allocating group tables: done
Writing inode tables: done
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done

# mount /dev/loop0 /mnt
# df -i | sed -n '1p;/mnt/p'
Filesystem Inodes IUsed IFree IUse% Mounted on
/dev/loop0 500464 11 500453 1% /mnt

在这里,我选择了 ext4,并将每个 inode 的字节数 -i 设置为其最小值,为 ext4 上的 512MiB 提供了最大 inode 计数 500464。

您可以通过这种方式制作多个文件系统,每个项目一个,或者制作一个更大的文件系统,其中包含更多 inode。

要在下次重启时挂载镜像,请在 /etc/fstab 中添加一行。

关于php - Yii2:减少 vServer 上的 inode 使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35669792/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com