lxdでライブマイグレーションを試そうと思ったけど、インターネット経由だと無理だよね
災害に備えて石狩リージョンのVPSを借りましたので、まずubutn14.04を導入し、必要なパッケージをインストールします。
ishikari:~$ sudo apt-get install software-properties-common ishikari:~$ sudo add-apt-repository ppa:ubuntu-lxc/lxd-stable ishikari:~$ sudo apt-get update ishikari:~$ sudo apt-get dist-upgrade ishikari:~$ sudo apt-get install lxd criu ishikari:~$ newgrp lxd ishikari:~$ dpkg -l | grep lxd ii lxd 0.21-0ubuntu3~ubuntu14.04.1~ppa1 amd64 Container hypervisor based on LXC - daemon ii lxd-client 0.21-0ubuntu3~ubuntu14.04.1~ppa1 amd64 Container hypervisor based on LXC - client ishikari:~$ uname -a Linux ishikari 3.13.0-68-generic #111-Ubuntu SMP Fri Nov 6 18:17:06 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux ishikari:~$
カーネルバージョンは3.13.0.68。
lxdのバージョンは0.21です。lxdはおおよそ半月に1回くらいのペースでバージョン上がってます。
※2015/11/12の時点で0.22が出てました。
インストール直後はコンテナが存在しないので、こうなります。
ishikari:~$ lxc list +------+-------+------+------+-----------+-----------+ | NAME | STATE | IPV4 | IPV6 | EPHEMERAL | SNAPSHOTS | +------+-------+------+------+-----------+-----------+ +------+-------+------+------+-----------+-----------+ ishikari:~$
すでに稼働中の東京はこうです。
tokyo:~$ lxc list +----------+---------+------------+------+-----------+-----------+ | NAME | STATE | IPV4 | IPV6 | EPHEMERAL | SNAPSHOTS | +----------+---------+------------+------+-----------+-----------+ | mail | RUNNING | 10.0.3.242 | | NO | 0 | | owncloud | RUNNING | 10.0.3.241 | | NO | 0 | | www | RUNNING | 10.0.3.243 | | NO | 0 | +----------+---------+------------+------+-----------+-----------+ tokyo:~$
まずそれぞれのlxdに対してリモートでのアクセスを許可する設定を行ないます。
マイグレーションを実行する側は、マイグレーション元をlocalにするとエラーになります。
かならず自分のIPを許可します。
ishikari:~$ lxc config set core.https_address [::] ishikari:~$ lxc config set core.trust_password password ishikari:~$ lxc remote add tokyo tokyo.xxxx.jp Certificate fingerprint: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ok (y/n)? y Admin password for tokyo: Client certificate stored at server: tokyo ishikari:~$ lxc remote list +----------+--------------------------------+--------+ | NAME | URL | PUBLIC | +----------+--------------------------------+--------+ | ishikari | https://ishikari.xxxx.jp:8443 | NO | | local | unix:// | NO | | tokyo | https://tokyo.xxxx.jp:8443 | NO | +----------+--------------------------------+--------+ ishikari:~$
マイグレートされる側の石狩側は不要な気がしますが、今後相互にマイグレーションのテスト
を行うことを考えると石狩側にも設定しておきます。
tokyo:~$ lxc config set core.https_address [::] tokyo:~$ lxc config set core.trust_password password tokyo:~$ lxc remote add ishikari ishikari.xxxx.jp Certificate fingerprint: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ok (y/n)? y Admin password for ishikari: Client certificate stored at server: ishikari tokyo:~$ tokyo:~$ lxc remote add tokyo tokyo.xxxx.jp Certificate fingerprint: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ok (y/n)? y Admin password for tokyo: Client certificate stored at server: tokyo tokyo:~$ lxc remote list +----------+--------------------------------+--------+ | NAME | URL | PUBLIC | +----------+--------------------------------+--------+ | ishikari | https://ishikari.xxxx.jp:8443 | NO | | local | unix:// | NO | | tokyo | https://tokyo.xxxx.jp:8443 | NO | +----------+--------------------------------+--------+ tokyo:~$
この状態でマイグレーションを実行するとエラーになります。
tokyo:~$ lxc move tokyo:www ishikari:www error: Error transferring container data: checkpoint failed: Problem accessing CRIU log: open /tmp/lxd_migration_363269796/dump.log: no such file or directory tokyo:~$
マイグレーションにはいくつか制約があるようです。プロファイルを見てみましょう。
tokyo:~$ lxc profile list default migratable
「migratable」というそれっぽいプロファイルがあります。
中身はこんな感じでこれを適用します。
tokyo:~$ lxc profile show migratable name: migratable config: raw.lxc: |- lxc.console = none lxc.cgroup.devices.deny = c 5:1 rwm lxc.seccomp = security.privileged: "true" devices: {} tokyo:~$
すでにdefaultプロファイルで動いてますので、一旦停止し、migratableプロファイルで起動し
マイグレートを実行します。別のターミナルで確認するとwwwコンテナはSTOPになります。
STOP状態だったらライブマイグレーションにならないような・・・・・
tokyo:~$ lxc stop www tokyo:~$ lxc profile apply www migratable tokyo:~$ lxc start www tokyo:~$ lxc move tokyo:www ishikari:www tokyo:~$ lxc list <-- 別のターミナルから実行 +----------+---------+------------+------+-----------+-----------+ | NAME | STATE | IPV4 | IPV6 | EPHEMERAL | SNAPSHOTS | +----------+---------+------------+------+-----------+-----------+ | mail | RUNNING | 10.0.3.242 | | NO | 0 | | owncloud | RUNNING | 10.0.3.241 | | NO | 0 | | www | STOPPED | | | NO | 0 | +----------+---------+------------+------+-----------+-----------+ error: Error transferring container data: restore failed: (00.076048) 1: Error (mount.c:2030): Can't mount at ./dev/.lxd-mounts: No such file or directory (00.088553) Error (cr-restore.c:1939): Restoring FAILED. tokyo:~$
エラー出ました。何ぞ・・・・・
もう一回やってみました。STOP状態からでも問題無いようです。
tokyo:~$ lxc list +----------+---------+------------+------+-----------+-----------+ | NAME | STATE | IPV4 | IPV6 | EPHEMERAL | SNAPSHOTS | +----------+---------+------------+------+-----------+-----------+ | mail | RUNNING | 10.0.3.242 | | NO | 0 | | owncloud | RUNNING | 10.0.3.241 | | NO | 0 | | www | STOPPED | | | NO | 0 | +----------+---------+------------+------+-----------+-----------+ tokyo:~$ lxc move tokyo:www ishikari:www tokyo:~$
できた。
STOPの状態だったらうまくいくようだ。
ライブマイグレーションではないけど・・・・・
ishikari:~$ lxc list +------+---------+------+------+-----------+-----------+ | NAME | STATE | IPV4 | IPV6 | EPHEMERAL | SNAPSHOTS | +------+---------+------+------+-----------+-----------+ | www | STOPPED | | | NO | 0 | +------+---------+------+------+-----------+-----------+ ishikari:~$
起動してみる。
ishikari:~$ lxc start www ishikari:~$ lxc list +------+---------+------+------+-----------+-----------+ | NAME | STATE | IPV4 | IPV6 | EPHEMERAL | SNAPSHOTS | +------+---------+------+------+-----------+-----------+ | www | RUNNING | | | NO | 0 | +------+---------+------+------+-----------+-----------+ ishikari:~$ ps auxf <-- 必要な場所だけ抽出 root 8691 0.0 0.2 157320 4276 ? Ss 15:35 0:00 /usr/bin/lxd forkstart www /var/lib/lxd/containers /tmp/lxd_lxc_startconfig_121365120 root 8696 0.1 0.1 33344 2624 ? Ss 15:35 0:00 \_ /sbin/init root 9261 0.0 0.0 19472 660 ? S 15:35 0:00 \_ upstart-udev-bridge --daemon root 9291 0.0 0.0 49268 1328 ? Ss 15:35 0:00 \_ /lib/systemd/systemd-udevd --daemon message+ 9420 0.0 0.0 190304 1160 ? Ssl 15:35 0:00 \_ rsyslogd root 9480 0.0 0.0 15272 636 ? S 15:35 0:00 \_ upstart-file-bridge --daemon root 9483 0.0 0.0 15388 772 ? S 15:35 0:00 \_ upstart-socket-bridge --daemon root 10234 0.0 0.0 23652 904 ? Ss 15:37 0:00 \_ cron root 10242 0.0 0.1 61364 3072 ? Ss 15:37 0:00 \_ /usr/sbin/sshd -D root 10313 0.0 0.0 12784 900 ? Ss 15:38 0:00 \_ /sbin/getty -8 38400 console ishikari:~$ lxc config show www name: www profiles: - migratable config: volatile.base_image: 9468e75eb8f27f895a0b06b1a44e067e3add82f8631c51aff640be6a4949d2c6 volatile.eth0.hwaddr: 00:16:3e:49:3d:de volatile.last_state.idmap: '[]' devices: {} ephemeral: false ishikari:~$
特権状態で動いているので、元に戻す。IPも振られてない。なんで?
migratableのプロファイルにはdevicesの中身が記載されていないからですね。
ishikari:~$ lxc stop www ishikari:~$ lxc profile apply www defalut ishikari:~$ lxc start www ishikari:~$ lxc list +------+---------+------------+------+-----------+-----------+ | NAME | STATE | IPV4 | IPV6 | EPHEMERAL | SNAPSHOTS | +------+---------+------------+------+-----------+-----------+ | www | RUNNING | 10.0.3.243 | | NO | 0 | +------+---------+------------+------+-----------+-----------+ ishikari:~$ ps auxf <-- 必要な場所だけ抽出 root 10601 0.0 0.1 157320 2540 ? Ss 15:40 0:00 /usr/bin/lxd forkstart www /var/lib/lxd/containers /tmp/lxd_lxc_startconfig_153988455 165536 10616 0.8 0.1 33320 2628 ? Ss 15:40 0:00 \_ /sbin/init 165536 11276 0.0 0.0 19472 656 ? S 15:40 0:00 \_ upstart-udev-bridge --daemon 165536 11298 0.0 0.0 49268 1324 ? Ss 15:40 0:00 \_ /lib/systemd/systemd-udevd --daemon 165638 11464 0.0 0.0 182108 1204 ? Ssl 15:40 0:00 \_ rsyslogd 165536 11488 0.0 0.1 10228 2420 ? Ss 15:40 0:00 \_ dhclient -1 -v -pf /run/dhclient.eth0.pid -lf /var/lib/dhcp/dhclient.eth0.leases eth0 165536 11554 0.0 0.0 15388 760 ? S 15:40 0:00 \_ upstart-socket-bridge --daemon 165536 11632 0.0 0.0 15404 748 ? S 15:40 0:00 \_ upstart-file-bridge --daemon 165536 11673 0.0 0.0 23652 904 ? Ss 15:40 0:00 \_ cron 165536 11680 0.0 0.1 61364 3080 ? Ss 15:40 0:00 \_ /usr/sbin/sshd -D 165536 11742 0.0 0.0 12784 860 pts/1 Ss+ 15:40 0:00 \_ /sbin/getty -8 38400 console ishikari:~$
正常になりました。
プロファイルを適用し直したりするのであれば、一旦停止した状態でコピーでいいな。
今時点はまだ開発進んでるし、いずれはこの辺りも改善されるんだろうと思います。
ということで次回は停止した後、コピーしてみます。