
我在 Archlinux 上運行 LXC。
我有 Arch、Fedora、Centos、Debian 和 Ubuntu LXC 容器的組合,每個容器都基於 systemd。
如果我嘗試開啟超過 19 個 LXC 容器,第 20 個容器將啟動,但內部不會執行 systemd。 (ps aux
僅顯示bash
、init
、 和ps
)
我認為這可能與打開文件的數量有關,因為當我運行poweroff
大量 LXC 容器時,centos 容器有時會報告「太多打開文件」。但我增加了文件限制如此連結所述,重新啟動並驗證更改,但我的問題仍然存在。
可能是什麼原因造成的?
答案1
如果您的問題發生在非特權(即:使用使用者命名空間)容器上,而不是特權(即:root)容器上,我相信這可能是由於運行容器的相同使用者對 inotify 介面的使用受到限製造成的。顯然 systemd 依賴 inotify。 Debian buster LXC 軟體包包含一個放鬆 sysctl 的fs.inotify.max_user_instances
設置/etc/sysctl.d/30-lxc-inotify.conf
:
# Defines the maximum number of inotify listeners. # By default, this value is 128, which is quickly exhausted when using # systemd-based LXC containers (15 containers are enough). # When the limit is reached, systemd becomes mostly unusable, throwing # "Too many open files" all around (both on the host and in containers). # See https://kdecherf.com/blog/2015/09/12/systemd-and-the-fd-exhaustion/ # Increase the user inotify instance limit to allow for about # 100 containers to run before the limit is hit again fs.inotify.max_user_instances = 1024
這此設定的相關文檔告訴:
/proc/sys/fs/inotify/max_user_instances
這指定了每個真實使用者 ID 可以建立的 inotify 實例數量的上限。
如果您的 LXC 安裝不包含此類設置,您可以檢查是否只是在主機上執行:
sysctl -w fs.inotify.max_user_instances=1024
將解決問題。