
編輯:問題是我的 umask 設定為 027 而不是預設的 022。
我遇到了一系列有關 LXC 的令人困惑的問題,這些問題在發生後會在整個系統中顯現出來。
啟動/停止 LXC 容器時,有時啟動或停止會無限期掛起。當啟動時發生這種情況時,容器的init
進程正在運行但無法終止,即使使用kill -9
.容器永遠不會上線,結束該過程的唯一方法是重新啟動系統。
問題是,系統也不會再重新啟動。在出現此問題的同時,我注意到運行時存在一個問題update-initramfs
,該問題也會無限期掛起。找到這個之後:
https://unix.stackexchange.com/questions/428001/update-initramfs-hangs-on-debian-stretch
我得出的結論是,sync
命令(實用程式和系統呼叫)確實掛起,導致 LXC 無法工作、update-initramfs
掛起和系統關閉掛起(應該sync
在卸載檔案系統之前完成)。一旦出現問題,sync
從命令列呼叫(實用程式)將始終無限期掛起。我嘗試運行它,strace
但跟踪在進入內核調用時結束,我無法進一步調試。我已經使用監控快取這但它只是徘徊在 <100kB 範圍內。
考慮到sync
與檔案系統有關,我預期 LXC 處理某些檔案系統的方式有問題。我有另一台相同的伺服器,但不使用 LXC,在比較輸出後,mount
我卸載了該伺服器上不存在的檔案系統,但無濟於事。sync
繼續掛起。
現在,乾淨啟動,並且不接觸 LXC,sync
總是工作,並且繼續工作。出於這個原因,並且我沒有看到其他問題,我確信不存在實際的 I/O 問題。此外,當容器成功啟動時,它似乎沒有任何問題。
關於這個問題,我在互聯網上進行了廣泛的搜索,但沒有成功。
Debian 9(穩定)上的 LXC 2.0.7-2+deb9u2,內核為 4.19.0-0.bpo.4-amd64(儘管其他最近的內核也發生了這種情況),raid1 中有 2 個 SSD,/
raid5 中有3 個HDD( mdadm) 為/home
.來賓是 Debian 9(stretch)或 10(buster),作為非特權容器運作。我似乎已經將範圍縮小到:特權容器沒有出現該問題。
訪客容器設定範例:
# Template used to create this container: /usr/share/lxc/templates/lxc-download
# Distribution configuration
lxc.include = /usr/share/lxc/config/debian.common.conf
lxc.include = /usr/share/lxc/config/debian.userns.conf
lxc.arch = linux64
# Container specific configuration
lxc.id_map = u 0 200000 100000
lxc.id_map = g 0 200000 100000
# Network configuration
#lxc.network.type = empty
lxc.network.type = veth
lxc.network.link = lxcbr0
lxc.network.flags = up
lxc.network.hwaddr = 00:16:3e:e9:4a:e7
lxc.rootfs = /var/lib/lxc/somename/rootfs
lxc.rootfs.backend = dir
lxc.utsname = somename
# Mounts
lxc.mount.entry = /var/lib/lxc/temp mnt/temp none bind 0 0
和 subuid/gid 映射:
# cat /etc/s*id
root:100000:1000000000
root:100000:1000000000
容器建立、啟動和失敗停止範例:
# lxc-create -n test -t download
...
Distribution: debian
Release: stretch
Architecture: amd64
Downloading the image index
Downloading the rootfs
Downloading the metadata
The image cache is now ready
Unpacking the rootfs
---
You just created a Debian stretch amd64 (20190522_05:24) container.
# lxc-ls -f
NAME STATE AUTOSTART GROUPS IPV4 IPV6
test STOPPED 0 - - -
# lxc-start -n test
# lxc-ls -f
NAME STATE AUTOSTART GROUPS IPV4 IPV6
test RUNNING 0 - - -
# lxc-attach -n test
root@test:/# ls -alh /
total 68K
drwxr-xr-x 21 root root 4.0K May 22 05:26 .
drwxr-xr-x 21 root root 4.0K May 22 05:26 ..
drwxr-xr-x 2 root root 4.0K May 22 05:26 bin
drwxr-xr-x 2 root root 4.0K Mar 28 09:12 boot
drwxr-xr-x 4 root root 400 May 22 09:26 dev
drwxr-xr-x 42 root root 4.0K May 22 09:24 etc
drwxr-xr-x 2 root root 4.0K Mar 28 09:12 home
drwxr-xr-x 9 root root 4.0K May 22 05:25 lib
drwxr-xr-x 2 root root 4.0K May 22 05:25 lib64
drwxr-xr-x 2 root root 4.0K May 22 05:25 media
drwxr-xr-x 2 root root 4.0K May 22 05:25 mnt
drwxr-xr-x 2 root root 4.0K May 22 05:25 opt
dr-xr-xr-x 225 nobody nogroup 0 May 22 09:26 proc
drwx------ 2 root root 4.0K May 22 05:25 root
drwxr-xr-x 3 root root 60 May 22 09:26 run
drwxr-xr-x 2 root root 4.0K May 22 05:26 sbin
drwxr-xr-x 2 root root 4.0K May 22 05:25 srv
dr-xr-xr-x 13 nobody nogroup 0 May 19 17:07 sys
drwxrwxrwt 2 root root 4.0K May 22 05:25 tmp
drwxr-xr-x 10 root root 4.0K May 22 05:25 usr
drwxr-xr-x 11 root root 4.0K May 22 05:25 var
root@test:/# exit
# lxc-ls -f
NAME STATE AUTOSTART GROUPS IPV4 IPV6
debian_buster STOPPED 0 - - -
rtorrent STOPPED 0 - - -
test RUNNING 0 - - -
# lxc-stop -n test
^C
# lxc-stop -n test
... continues to hang ...
# ^C
# sync
^C^C^Z^X^C^Z^X^C^Z^C^Z^X^C
... won't die.
答案1
事實證明,問題出在我的 umask 不那麼寬鬆。 Debian 的預設值是 022,.bashrc
出於安全原因,我已在使用者帳戶中將其變更為 027。在su
成為 root 後,會複製此 umask,以便lxc-*
使用umask 027 執行所有命令。 ) )。
更改 umask(在會話中或透過修改.bashrc
)使我可以很好地運行我已經擁有的容器。
資源:
https://github.com/lxc/lxc/issues/2277(不確定這是同一個問題)