在 Debian 里,inotify 本身是 Linux 内核提供的文件系统事件通知机制,不是一个“需要配置的守护进程”。所谓“配置 inotify”,通常分为两类需求:
inotifywait、inotifywatch(inotify-tools)下面按实际使用场景说明。
sudo apt update
sudo apt install inotify-tools
常用命令:
inotifywait:监听文件/目录变化inotifywatch:统计事件示例:
inotifywait -m /var/log
cat /proc/sys/fs/inotify/max_user_watches
cat /proc/sys/fs/inotify/max_user_instances
cat /proc/sys/fs/inotify/max_queued_events
含义:
max_user_watches:单用户可监听的文件数(最常用)max_user_instances:inotify 实例数max_queued_events:事件队列长度sudo sysctl fs.inotify.max_user_watches=524288
编辑:
sudo nano /etc/sysctl.conf
添加或修改:
fs.inotify.max_user_watches=524288
fs.inotify.max_queued_events=1048576
生效:
sudo sysctl -p
如果你用 systemd 服务(如 Docker、Node、Java 程序)使用 inotify,可能会受 systemd 限制,而不是内核限制。
查看:
systemctl show docker | grep TasksMax
修改示例(Docker):
sudo systemctl edit docker
写入:
[Service]
TasksMax=infinity
然后:
sudo systemctl daemon-reexec
sudo systemctl restart docker
inotifywait -m -e modify,create,delete /data | while read path action file
do
echo "$file $action"
done
inotifywait -m -r -e close_write /src | while read dir ev file
do
rsync -az /src/ user@host:/dst/
done
max_user_watchesmax_queued_eventsTasksMax如果你有具体用途(比如 Docker、Node、Webpack、Fail2ban、Syncthing 等),可以告诉我,我可以给你针对性的配置示例。