我使用并行连接在大量 Linux VM 上执行脚本(一次最大并行连接数为 500,随机休眠 300 秒)。问题是其中一些转到错误的 VM 并执行脚本。当我在其他 iterm 会话中检查手动 ssh 到 VM 时(同时并行连接执行正在进行),它实际上转到了错误的 VM(在 VM 上总是随机的)。例如

ubuntu@admin:~$ ssh 10.10.97.2 "hostname -i"
10.10.13.47
ubuntu@admin:~$ ssh 10.10.97.2 "hostname -i"
10.10.13.4
ubuntu@admin:~$ ssh 10.10.97.2 "hostname -i"
10.10.12.90

我已在 ssh 配置中添加了以下条目,但没有成功

ControlMaster auto
ControlPath ~/.ssh/socket_pool/%C
ControlPersist yes

它总是更改为连接到错误的 IP(同时并行连接执行正在其他会话中进行)。有人告诉我我的 ubuntu VM 出了什么问题吗?

1

  • ip a机器上的输出是什么?


    – 


最佳答案
1

当这些目标机器有多个接口或多个名称(可解析的名称,如 DNS 或 NBNS)时,这是预期的输出。不是因为脚本连接到了错误的机器,而是因为预期的输出。使用时要非常小心hostname -i

的手册页非常具体地说明了区别:

-i, --ip-address
     Display  the  network address(es) of the host name. Note that this works only if the
     host name can be resolved.
     Avoid using this option; use hostname --all-ip-addresses instead.
-I, --all-ip-addresses
     Display all network addresses of the host. This option enumerates all configured addresses on all network interfaces.
     The  loopback interface and IPv6 link-local addresses are omitted. Contrary to option -i, this option does not depend
     on name resolution. Do not make any assumptions about the order of the output.