在 Debian 上 inotify 报错 通常和 内核参数限制、文件/目录数量过多、或程序使用方式不对 有关。下面把常见原因和解决办法系统说一下。
No space left on device这是 最典型 的 inotify 报错。
不是磁盘满了,而是:
inotify watches 数量达到上限
cat /proc/sys/fs/inotify/max_user_watches
sudo sysctl fs.inotify.max_user_watches=524288
sudo sysctl -p
echo 'fs.inotify.max_user_watches=524288' | sudo tee -a /etc/sysctl.conf
sudo sysctl -p
Too many open filesinotify 也会占用 fd。
查看:
ulimit -n
增大限制:
sudo vim /etc/security/limits.conf
添加:
* soft nofile 65536
* hard nofile 65536
ENOSPC / EMFILEENOSPC → watches 满EMFILE → 进程 fd 满inotifywait -r /project
问题:
✅ 解决:
inotifywait -r -e modify --exclude 'node_modules|/.git' /project
容器内 inotify 限制通常更小。
解决:
会 共享系统 watches 配额
✅ 解决:
max_user_watches如果是 service 使用 inotify:
[Service]
LimitNOFILE=65536
然后:
sudo systemctl daemon-reexec
Debian 旧版本(如 9 以前)默认 watches 很低(8192)
✅ 升级内核或手动调大
# 1. 当前 watches
cat /proc/sys/fs/inotify/max_user_watches
# 2. 当前使用量(近似)
find /proc/*/fd -lname 'anon_inode:inotify' 2>/dev/null | wc -l
# 3. 报错程序
dmesg | grep inotify
Debian 上 inotify 报错,99% 是
max_user_watches太小,尤其是监听大目录或容器环境。
如果你愿意,可以把:
发出来,我可以给你精确定位方案。