TenForward

技術ブログ。はてなダイアリーから移転しました

lxd を使ったライブマイグレーション(未完)

(2015-04-15 追記) マイグレーションできたブログエントリを書きました > lxd を使ったライブマイグレーション (1) - TenForwardの日記
(2015-03-18 追記) lxd 0.4 が出たので試してますが、今度はマイグレーション先の lxd がこんなログを吐いてしまいます ^^;

panic: runtime error: invalid memory address or nil pointer dereference

(2015-03-18 追記ここまで)

前回、リリースされたばかりの lxd 0.3 を簡単に試してみました。本当に簡単なお試しで lxd である必要すらないお試しでした。もう少し lxd らしい使い方を、と思って試してますが、なかなかうまくいきませんね。

lxd 0.3 の目玉機能の一つはこれでしょう。

Initial support of live migration (requires particular container configuration)

https://linuxcontainers.org/lxd/news/

ライブマイグレーション!!

うまくいくか試してみました。ドキュメントがほとんどないので手探りです。

コンテナの特別な設定が必要とあります。これは lxd のバックエンドは liblxc を使っているので LXC 1.1 でも必要な設定と同じで以下の 3 つです。

lxc.tty=0
lxc.console=none
lxc.cgroup.devices.deny=c 5:1 rwm

お試し環境

以下の 3 台を使っています。

  • Ubuntu 14.04.2 LTS x 2 に lxd のデイリービルドパッケージをインストール (lxd ホスト、ここでは lxd01, lxd02 という名前)
  • Plamo 5.3.1 にソースからビルドしてインストール (lxc コマンド実行環境)

lxd のインストール

前回と同じです。Ubuntu 14.04.2 LTS を使いました。2 台にセットアップします。

ubuntu@lxd01:~$ sudo add-apt-repository ppa:ubuntu-lxc/lxd-daily
ubuntu@lxd01:~$ sudo apt-get update
ubuntu@lxd01:~$ sudo apt-get install lxd

これでインストールされた /etc/init/lxd.conf を書き換えて、リモートから接続できるようにします。lxd.conf の exec 行を書き換えて以下のようにします。

exec /usr/bin/lxd --group lxd --tcp 10.200.200.200:8443 --debug >> /var/log/lxd.log 2>&1

'--debug' を付けて、デバッグ出力を /var/log/lxd.log に保存するようにしてみました。

クライアントの設定

lxc コマンドを実行するクライアントで remote の設定をします。

plamo@client:~$ export GOPATH=~/go
plamo@client:~$ export PATH=$PATH:$GOPATH/bin
plamo@client:~$ lxc remote add lxd01 10.200.200.200:8443
plamo@client:~$ lxc remote add lxd02 10.200.200.208:8443
plamo@client:~$ lxc remote list
lxd01 <10.200.200.200:8443>
lxd02 <10.200.200.208:8443>

イメージの登録

lxd ホスト上で以下のようにします。

ubuntu@lxd01:~$ lxd-images import lxc ubuntu trusty amd64 --alias ubuntu --alias ubuntu/trusty --alias ubuntu/trusty/amd64

クライアントから確認してみます。

plamo@client:~$ lxc image list lxd01:
+--------+----------+--------+-------------+
| ALIAS  |   HASH   | PUBLIC | DESCRIPTION |
+--------+----------+--------+-------------+
| ubuntu | 47cd2f39 | no     |             |
+--------+----------+--------+-------------+

コンテナ作成

片方のlxdホスト上でコンテナを作成します。

plamo@client:~$ lxc init ubuntu lxd01:trusty01

デフォルトでは作成したコンテナには "default" というプロファイルが割りあたっています。プロファイルはコンテナに対する設定をまとめたものです。"default" をコピーして "criu" という名前のプロファイルにします。

plamo@client:~$ lxc config profile copy lxd01:default lxd01:criu

"criu" プロファイルを編集します。以下のように edit コマンドを実行するとエディタが起動します。

plamo@client:~$ lxc config profile edit lxd01:criu  (プロファイルの編集)

こんな感じにします(yaml形式)。config の所の raw.lxc を追加しました。

name: criu
config:
  raw.lxc: |-
    lxc.tty=0
    lxc.console=none
    lxc.cgroup.devices.deny=c 5:1 rwm
devices:
  eth0:
    nictype: bridged
    parent: lxcbr0
    type: nic

ちゃんと編集できたか確認します。

plamo@client:~$ lxc config profile show lxd01:criu  (プロファイルの確認)
raw.lxc = lxc.tty = 0
lxc.console = none
lxc.cgroup.devices.deny = c 5:1 rwm
eth0: nic

"criu" プロファイルをコンテナに割り当てます。

plamo@client:~$ lxc config profile apply lxd01:trusty01 criu
Profile criu applied to trusty01

もう一台の lxd ホストにもプロファイルをコピーします。

plamo@client:~$ lxc config profile copy lxd01:criu lxd02:criu

プロファイルの確認

plamo@client:~$ lxc config profile list lxd01:
default
criu
plamo@client:~$ lxc config profile list lxd02:
default
criu

コンテナの起動とマイグレーション

コンテナを起動します。

plamo@client:~$ lxc start lxd01:trusty01
plamo@client:~$ lxc list lxd01:
+----------+---------+---------------------+------+
|   NAME   |  STATE  |        IPV4         | IPV6 |
+----------+---------+---------------------+------+
| trusty01 | RUNNING | 10.0.3.7, 127.0.0.1 | ::1  |
+----------+---------+---------------------+------+

ライブマイグレーションを実行します。

$ lxc move lxd01:trusty01 lxd02:trusty01
error: restore failed

がーん。

コンテナの送り側 (lxd01) のログはこんな

2015/03/17 19:18:55 client cert != key for lxd01
2015/03/17 19:18:55 found cert for 10.200.200.200
2015/03/17 19:18:55 handling GET /1.0
2015/03/17 19:18:55 client cert != key for lxd01
2015/03/17 19:18:55 found cert for 10.200.200.200
2015/03/17 19:18:56 client cert != key for lxd01
2015/03/17 19:18:56 found cert for 10.200.200.200
2015/03/17 19:18:56 handling GET /1.0/containers/trusty01
2015/03/17 19:18:56 setting lxc.tty=0
2015/03/17 19:18:56 setting lxc.console=none
2015/03/17 19:18:56 setting lxc.cgroup.devices.deny=c 5:1 rwm
2015/03/17 19:18:56 Configured device eth0
2015/03/17 19:18:56 found cert for 10.200.200.200
2015/03/17 19:18:56 handling POST /1.0/containers/trusty01
2015/03/17 19:18:56 setting lxc.tty=0
2015/03/17 19:18:56 setting lxc.console=none
2015/03/17 19:18:56 setting lxc.cgroup.devices.deny=c 5:1 rwm
2015/03/17 19:18:56 Configured device eth0
2015/03/17 19:18:57 client cert != key for lxd01
2015/03/17 19:18:57 client cert != key for 10.200.200.200
2015/03/17 19:18:57 allowing untrusted GET to /1.0/operations/49bcae70-b968-4f14-886b-b5cb2280742c/websocket?secret=0h5i81aO9EXXfGHbTHm5eQXmB704mxX2%2BasWPYjEi0jL9Ykbdh1wzU635ylLE%2F3WbqJHplXBHlqM9tf8OrXIvpJBwRyhi4WrK2BCXwKJzwKRVt3hlqZNUPD02VHv%2B%2Bea4sgVDQ%3D%3D
2015/03/17 19:18:58 client cert != key for lxd01
2015/03/17 19:18:58 client cert != key for 10.200.200.200
2015/03/17 19:18:58 allowing untrusted GET to /1.0/operations/49bcae70-b968-4f14-886b-b5cb2280742c/websocket?secret=%2BAFr%2BL4Zt4mBciMWEciW0%2FOdHWSt14Ty13k%2Berz%2FC%2FKRF1LoGAZsnG7HBeuRgZMg8rEEG0oE2f5WfTrVKOZJnZd7cRtNaguiEYzwvwEly6fmplO9Nom37ti0v%2FSvNMbzZA3lDQ%3D%3D
2015/03/17 19:18:58 client cert != key for lxd01
2015/03/17 19:18:58 client cert != key for 10.200.200.200
2015/03/17 19:18:58 allowing untrusted GET to /1.0/operations/49bcae70-b968-4f14-886b-b5cb2280742c/websocket?secret=zOVPGshQorM8bm1IJk3Y9lVhXwz5oTkHSFbqH5yCZBSph2YOKEHpeqjrxj7BtESyq3iGabS993AHjzi8NG99A05z5OsL6EB2KGyx1%2Fb3sEDun%2B43TwzjGWYyiZbOcdYBvGxWaQ%3D%3D
2015/03/17 19:18:58 got error getting next reader websocket: close 1005 , &{{%!s(*net.netFD=&{{10 0 0} 16 1 1 false unix 0xc20811b300 0xc20811b320 {139997956048208}})}}
2015/03/17 19:19:15 got error getting next reader websocket: close 1005 , &{{%!s(*net.netFD=&{{10 0 0} 16 1 1 false unix 0xc20811a2a0 0xc20811a2e0 {139997956048384}})}}

受け側 (lxd02) のログはこんな

2015/03/17 19:18:56 client cert != key for lxd02
2015/03/17 19:18:56 found cert for 10.200.200.208
2015/03/17 19:18:56 handling GET /1.0
2015/03/17 19:18:56 client cert != key for lxd02
2015/03/17 19:18:56 found cert for 10.200.200.208
2015/03/17 19:18:56 found cert for 10.200.200.208
2015/03/17 19:18:56 handling GET /1.0/profiles
2015/03/17 19:18:56 responding to profiles get
2015/03/17 19:18:56 client cert != key for lxd02
2015/03/17 19:18:56 found cert for 10.200.200.208
2015/03/17 19:18:56 handling POST /1.0/containers
2015/03/17 19:18:56 responding to create
2015/03/17 19:18:57 setting lxc.tty=0
2015/03/17 19:18:57 setting lxc.console=none
2015/03/17 19:18:57 setting lxc.cgroup.devices.deny=c 5:1 rwm
2015/03/17 19:18:57 Configured device eth0
2015/03/17 19:18:57 client cert != key for lxd02
2015/03/17 19:18:57 found cert for 10.200.200.208
2015/03/17 19:18:57 handling GET /1.0/operations/4aabada3-030d-4d6e-96b4-2625b070a180/wait
2015/03/17 19:18:58 got error getting next reader read tcp 10.200.200.200:8443: use of closed network connection, &{%!s(*os.File=&{0xc2080b2a50}) {{%!s(int32=0) %!s(uint32=0)} %!s(uint32=0)} ?reflect.Value?}
2015/03/17 19:19:15 got error getting next reader read tcp 10.200.200.200:8443: use of closed network connection, &{%!s(*os.File=&{0xc2080b23f0}) {{%!s(int32=0) %!s(uint32=0)} %!s(uint32=0)} ?reflect.Value?}

何か実行されてる風ですが、エラーが出てますね。(ホスト間で rsync は実行されてるっぽい)

識者の登場を待ちましょう :-p (続くかも)