ldira.hatenablog.com

Ldira備忘録

Multipass VMへの接続がTimeout connectingで失敗する

f:id:ldira:20220206213744p:plain 近所のクレープ店のメニューに「チョコバナナ」があるんですが、「チョコバナナください!」と言うと「バナナチョコですね!」と毎回訂正されるLdiraです。

で、食べ物とは全然関係無いんですが、仕事用のMacIntelチップからM1チップの機器に変更しました。これにより使用できなくなったアプリがいくつかあります。

例えば、仮想サーバのVirtualBoxはARM未対応のため、M1 Macで使用できません。代替の仮想サーバはMultipassが良さそうに見えたので、これを導入しました。 また諸事情でDocker Desktopの代替が必要だったため、これをMultipassに移行しました。

Multipass導入後、しばらく問題なく使用していましたが、先日突然multipassコマンドが失敗するようになったため、このときのログと暫定対策を以下に記録します。

結論

Multipass VMへの接続がTimeout connectingで失敗していたが、multipassdの再起動で復旧しました。

事象

  • 今まで使えてたVMがある日突然利用できなくなりました。
    • XXX failed: ssh connection ailed: 'Timeout connecting to X.X.X.X' が表示されます。
  • 次は事象発生時のログです。
% multipass shell docker-vm
shell failed: ssh connection failed: 'Timeout connecting to 192.168.64.2'
% multipass info --all
info failed: ssh connection failed: 'Timeout connecting to 192.168.64.2'

環境

  • ハードウェア: MacBook Air (M1, 2020)
  • ソフトウェアは次のとおり
% multipass version
multipass   1.8.1+mac
multipassd  1.8.1+mac
% sw_vers
ProductName:    macOS
ProductVersion: 12.2
BuildVersion:   21D49

暫定対策

multipassdを再起動する。

  1. multipassdのプロセスIDを調べる。
  2. multipassdをkillする。
  3. VM接続を再確認をする。

1. multipassdのプロセスIDを調べる

次は ps aux | grep multipassd の実行結果です。

% ps aux | grep multipassd
~
ldira          55161   0.0  0.0 408628368   1616 s002  S+    5:00PM   0:00.00 grep multipassd
root               544   0.0  0.1 409419776  17680   ??  Ss   29 122    4:50.15 /Library/Application Support/com.canonical.multipass/bin/multipassd --verbosity debug

2. multipassdをkillする。

プロセスIDが544とわかったので、これをkillします。

% sudo kill -kill 544
Password:

何度かpsコマンドを叩き、multipassdが再起動していることを確認します。

% ps aux | grep multipassd

~
root             55165   1.9  0.1 409418208  23744   ??  Ss    5:00PM   0:00.22 /Library/Application Support/com.canonical.multipass/bin/multipassd --verbosity debug
ldira          55167   0.0  0.0 408628368   1616 s002  S+    5:00PM   0:00.00 grep multipassd
%

上記でmultipassdのプロセスIDが、kill前の544から55167に変わっているので、プロセスが再起動していることがわかります。

3. VM接続を再確認をする。

下記は multipass shell の実行結果です。再接続に成功しました。

% multipass shell docker-vm
Welcome to Ubuntu 20.04.3 LTS (GNU/Linux 5.4.0-97-generic aarch64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

  System information as of Sun Feb  6 19:59:45 JST 2022

  System load:              0.02
  Usage of /:               7.2% of 38.60GB
  Memory usage:             7%
  Swap usage:               0%
  Processes:                142
  Users logged in:          0
  IPv4 address for docker0: 172.17.0.1
  IPv4 address for enp0s1:  192.168.64.2
  IPv6 address for enp0s1:  fd6f:e5bb:97c4:7c25:5054:ff:fe9f:4171

 * Super-optimized for small spaces - read how we shrank the memory
   footprint of MicroK8s to make it the smallest full K8s around.

   https://ubuntu.com/blog/microk8s-memory-optimisation

4 updates can be applied immediately.
To see these additional updates run: apt list --upgradable


Last login: Sun Feb  6 18:13:24 2022 from 192.168.64.1
ubuntu@docker-vm:~$

ちなみに multipass alias 設定により、VM上のdockerコマンドをホスト上のコマンドとして扱えるよう紐付けできます。

% docker run hello-world

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (arm64v8)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/

%

検討・考察

VM~/.ssh/authorized_keys にホストのSSH公開鍵を登録すると、multipass list で見えるVMのIPに対してホストからSSHログインできるので、今後同様の事象が発生した際の切り分けに役立つかもしれません。

最後に

暫定対策ではありますが、無事復旧させることができました。

ネット上に惜しみなく情報をアウトプットして頂いた皆様に感謝します。

Ldira

参考

  • multipassdのkillについて、コメント欄に記載があります。大変助かりました。 zenn.dev

  • Docker DesktopをMultipassでリプレイスする方法について ubuntu.com

以上です。