💻运维部署
未读
Linux 如何增加 Inotify 监视器限制
本篇文章主要讲述了 Java 和 Shell 程序中出现的“Failed to allocate directory watch: Too many open files”错误的原因和解决方案。该错误并非指打开普通文件过多,而是由于系统达到 `inotify 监视器` 的数量限制。解决办法是修改内核参数,永久性地增加 `inotify 监视器` 限制。具体步骤包括:首先,在 `/etc/sysctl.d/` 目录下创建或编辑 `99-inotify.conf` 文件,添加或修改 `fs.inotify.max_user_watches` 和 `fs.inotify.max_user_instances` 参数,建议将 `fs.inotify.max_user_watches` 设置为 524288,`fs.inotify.max_user_instances` 设置为 1024;然后使用 `sudo sysctl --system` 命令应用更改;最后重启相关应用程序,以确保错误消失。 通过这些步骤,可以解决 `inotify 监视器` 数量限制问题,从而避免程序出现该错误。

