From 97760935bd4fc1843e9f73c4be3464c7aace789c Mon Sep 17 00:00:00 2001 From: offends Date: Tue, 26 Aug 2025 16:48:41 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Helm/Helm部署Memos.md | 2 +- 问题记录/日志报文件数超出系统限制问题.md | 42 ++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 问题记录/日志报文件数超出系统限制问题.md diff --git a/Helm/Helm部署Memos.md b/Helm/Helm部署Memos.md index 2503d3d..55d66d7 100644 --- a/Helm/Helm部署Memos.md +++ b/Helm/Helm部署Memos.md @@ -33,7 +33,7 @@ ```yaml # 配置镜像加速 image: - repo: ghcr.dockerproxy.com + repo: ghcr.nju.edu.cn # 开启持久化存储 persistence: diff --git a/问题记录/日志报文件数超出系统限制问题.md b/问题记录/日志报文件数超出系统限制问题.md new file mode 100644 index 0000000..1cae87b --- /dev/null +++ b/问题记录/日志报文件数超出系统限制问题.md @@ -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。