更新文档
All checks were successful
continuous-integration/drone Build is passing

This commit is contained in:
2025-08-26 16:48:41 +08:00
parent 60d48613f6
commit 97760935bd
2 changed files with 43 additions and 1 deletions

View File

@@ -0,0 +1,42 @@
> 本文作者:丁辉
# 日志报文件数超出系统限制问题
## 遇到报错
`failed to create fsnotify watcher: too many open files`
## 解决方法
- 临时设置
```bash
sudo sysctl fs.inotify.max_user_instances=8192
```
- 永久设置
```bash
echo "fs.inotify.max_user_instances=8192" | sudo tee -a /etc/sysctl.conf
sudo sysctl -p
```
### 参数含义
| 参数 | 说明 |
| :-----------------------------: | :----------------------------------------------------------: |
| `fs.inotify.max_user_instances` | 每个用户user可以创建的 inotify 实例watcher 的集合)最大数量 |
| `8192` | 将限制提升到 8192 个实例 |
- **inotify** 是 Linux 提供的文件系统事件监控机制,应用程序可以用它来监控文件或目录的变化(创建、删除、修改等)。
- **每个 inotify watcher** 占用一个 inotify 实例的资源。
- 默认值通常较小(如 128 或 1024在日志收集、文件监控场景下容易不够用。
### 为什么要设置大一点
例如 Promtail、Fluentd、Filebeat 等日志收集工具,会 **为每个被监控的日志文件创建 inotify watcher**
- 如果你的机器上有大量容器或日志文件:
- 默认 `max_user_instances` 太小 → Promtail 会报错 `failed to create fsnotify watcher: too many open files`
- 提升到 8192 或更高,可以允许单个用户(比如运行 Promtail 的 `root` 或容器内用户)创建更多 inotify watcher。