在 Debian 中,inotify 是 Linux 内核自带的功能,通常不需要“安装”,只需要确认内核支持并正确配置参数即可使用。下面按常见场景说明。
grep INOTIFY /boot/config-$(uname -r)
正常应看到:
CONFIG_INOTIFY_USER=y
如果是 =m,说明是模块形式,一般也会自动加载。
ls /proc/sys/fs/inotify
应看到:
max_queued_events
max_user_instances
max_user_watches
有这些文件,说明 inotify 已启用。
很多程序(如 Java、Node、Docker、IDE)会报:
Too many open files
ENOSPC: System limit for number of file watchers reached
cat /proc/sys/fs/inotify/max_user_watches
sudo sysctl fs.inotify.max_user_watches=524288
sudo sysctl fs.inotify.max_user_instances=512
编辑:
sudo nano /etc/sysctl.conf
添加:
fs.inotify.max_user_watches=524288
fs.inotify.max_user_instances=512
使生效:
sudo sysctl -p
inotify 不需要 root,只要:
示例(普通用户):
inotifywait -m ~/test
Debian 默认可能没装命令行工具:
sudo apt update
sudo apt install inotify-tools
测试:
inotifywait -m /tmp
max_user_watchesnoatime 导致的问题(一般不影响)→ 调大 max_user_watches
在 service 文件中:
[Service]
LimitNOFILE=65536
如果你能说明 具体用途(如 Docker、Java、Vite、文件同步等),我可以给你更精准的配置方案。