【发布时间】:2017-03-11 18:37:31
【问题描述】:
我正在尝试使用以下命令
gcloud compute instances list --format=json --regexp .*gluster.* | jq '.[].networkInterfaces[].networkIP' | tr -d '\"' | while read i; do gcloud compute ssh --zone $ZONE ubuntu@gluster-1 -- "sudo gluster peer probe $i && cat >> peers.txt"; done
基本上 gcloud 命令给出:
gcloud compute instances list --format=json --regexp .*gluster.* | jq '.[].networkInterfaces[].networkIP' | tr -d '\"'
10.128.0.2
10.128.0.3
10.128.0.4
但是运行上述命令似乎只在主机的第一个 ip 上运行,并给出警告
peer probe: success. Probe on localhost not needed
其他节点都没有连接。
注意事项: 奇怪的是在第二个节点上运行 gcloud 命令会连接到第一个节点,在第三个节点上运行根本不会做任何事情
除了第三个节点之外的所有节点上的 peers.txt 文件再次奇怪地只有后两个 ips
ubuntu@gluster-1:~$ cat peers.txt
10.128.0.3
10.128.0.4
对循环中的值运行 echo 给出
gcloud compute instances list --format=json --regexp .*gluster.* | jq '.[].networkInterfaces[].networkIP' | tr -d '\"' | while read i; do echo ip: $i; done
ip: 10.128.0.2
ip: 10.128.0.3
ip: 10.128.0.4
【问题讨论】:
-
请注意,gcloud 融合了 jq 的许多特性。以下产生相同的结果
gcloud compute instances list --format="value(networkInterfaces.networkIP)" --filter="name~gluster"