解决CentOS 7 df命令卡住问题

先说解决方法
  • systemctl restart proc-sys-fs-binfmt_misc.automount,或
  • 升级systemd版本,或
  • 在systemd中mask掉(也就是无效化)automount。
再说问题

大数据集群中某几台机器执行df -h命令会hang住,没有任何输出,CTRL+C无效。
执行strace df命令,发现是卡在了/proc/sys/fs/binfmt_misc这里。

execve("/bin/df", ["df"], [/* 27 vars */]) = 0
brk(NULL)                               = 0x231c000
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fb17cc0b000
access("/etc/ld.so.preload", R_OK)      = -1 ENOENT (No such file or directory)
.....................
stat("/sys/kernel/config", {st_mode=S_IFDIR|0755, st_size=0, ...}) = 0
stat("/", {st_mode=S_IFDIR|0555, st_size=4096, ...}) = 0
stat("/usr", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
stat("/proc/sys/fs/binfmt_misc",

执行mount | grep binfmt命令,得知这个挂载路径是属于systemd的。

systemd-1 on /proc/sys/fs/binfmt_misc type autofs (rw,relatime,fd=28,pgrp=1,timeout=300,minproto=5,maxproto=5,direct)

执行systemctl list-units -all | grep binfmt,查看unit状态。

  proc-sys-fs-binfmt_misc.automount                                                                loaded    active   running   Arbitrary Executable File Formats File System Automount Point
  proc-sys-fs-binfmt_misc.mount                                                                    loaded    inactive dead      Arbitrary Executable File Formats File System
  systemd-binfmt.service                                                                           loaded    inactive dead      Set Up Additional Binary Formats

可见只有proc-sys-fs-binfmt_misc.automount是活着的,其他两个都死掉了。

稍微摸索一下

找到RedHat Bugzilla中报的一条bug:https://bugzilla.redhat.com/show_bug.cgi?id=1534701
大意是说,在234版本之前的systemd中,proc-sys-fs-binfmt_misc.automount与proc-sys-fs-binfmt_misc.mount这两个unit之间存在竞争条件,所以内核会持续hold这个挂载点,任何其他进程如果试图取得这个挂载点,就会无限hang住。
那么systemd.automount是做什么的呢?这里有解释:https://www.freedesktop.org/software/systemd/man/systemd.automount.html
执行了systemctl restart proc-sys-fs-binfmt_misc.automount命令之后,再用mount看一下,发现变成了:

systemd-1 on /proc/sys/fs/binfmt_misc type autofs (rw,relatime,fd=31,pgrp=1,timeout=0,minproto=5,maxproto=5,direct)

timeout从300变成了0。根据上面链接中TimeoutIdleSec项的解释,如果这个挂载点空闲超过timeout秒,那么systemd就会试图卸载它。很显然,在之前的配置中,/proc/sys/fs/binfmt_misc挂载点实际上已经不存在。重启之后,timeout为0,就没有超时设定了。

  • 2
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值