LXD を試してみた
- 公式ページに簡単なクライアントプログラムの使い方が載りました (2015-02-27 更新)
LXD 0.1 がリリースされましたので LXD を試してみました。
こちらも参考に。ただし、現時点では以下とは少しコマンドが違うようです。
Plamo 5.3 で試しています (kernel は独自ビルドの 3.19)。go コマンドはインストール済み。
構築
lxd/README.md at master · lxc/lxd · GitHub の通りです。
$ mkdir -p ~/go $ export GOPATH=~/go $ go get github.com/lxc/lxd $ cd $GOPATH/src/github.com/lxc/lxd $ go get -v -d ./... $ make
これで ~/go/bin 以下にコマンドができました。
$ ls ~/go/bin fuidshift* lxc* lxd*
デーモン起動
これも書いてある通り。
$ sudo mkdir -p /var/lib/lxd $ sudo chown karma:users /var/lib/lxd
subuid, subgid は設定済みです
$ cat /etc/subuid karma:100000:65536 $ cat /etc/subgid karma:100000:65536
とりあえず verbose モードで起動してみました。
$ ~/go/bin/lxd --help Usage: lxd [options] Options: --debug (= false) Enables debug mode. --group (= "") Group which owns the shared socket --help (= false) Print this help message. --tcp (= "") TCP address <addr:port> to listen on in addition to the unix socket (e.g., 127.0.0.1:8443) -v (= false) Enables verbose mode. --version (= false) Print LXD's version number and exit.
非特権コンテナのようですから、Plamo の場合、lxd コマンドを動かすシェルを読み書きできる cgroup に登録しないといけません(Ubuntuだとsystemd-logind辺りが作ったグループがあるのでそれを使いますのでこれは不要)。その後おもむろに lxd 起動
$ for d in /sys/fs/cgroup/* > do > echo $$ > $d/karma/tasks > done $ ~/go/bin/lxd -v
コマンド
$ cd ~/go/bin $ ./lxc help Usage: lxc [subcommand] [options] Available commands: config - Manage configuration. delete - lxc delete <resource> exec - exec specified command in a container. file - Manage files on a container. finger - Fingers the lxd instance to check if it is up and working. help - Presents details on how to use lxd. list - Lists the available resources. remote - Manage remote lxc servers. restart - Changes a containers state to restart. snapshot - Create a read-only snapshot of a container. start - Changes a containers state to start. stop - Changes a containers state to stop. version - Prints the version number of lxd.
コンテナ作成
イメージを勝手に落としてきてコンテナ作ります。help に init がないよw
$ ./lxc init ubuntu test01 $ ./lxc list test01
コンテナ起動
特にひねりはありません。素直に start。
$ ./lxc start test01 $
コンテナの状態確認
特に何もなく起動しているようですが、起動している様子を表示することができません ^^;
$ ./lxc info test01 error: unknown command: info :(snip)
プロセスを見てみると
$ pstree -p :(snip) | |-bash(24780)---lxd(17197)-+-{lxd}(17198) | | |-{lxd}(17199) | | |-{lxd}(17202) | | `-{lxd}(17203) :(snip) |-lxd(17207)---init(17218)-+-cron(18639) | |-getty(18626) | |-getty(18628) | |-getty(18629) | |-getty(18670) | |-getty(18673) | |-rsyslogd(17673)-+-{rsyslogd}(17684) | | `-{rsyslogd}(17685) | |-systemd-udevd(17564) | |-upstart-file-br(17670) | |-upstart-socket-(17669) | `-upstart-udev-br(17540)
確かに Plamo の上で Ubuntu が起動しているようです。
試してみると lxc のコマンドが使えそうです。
$ lxc-ls -P /var/lib/lxd/lxc -f NAME STATE IPV4 IPV6 GROUPS AUTOSTART ---------------------------------------------- test01 RUNNING - - - NO $ lxc-info -P /var/lib/lxd/lxc -n test01 Name: test01 State: RUNNING PID: 17218 CPU use: 1.17 seconds BlkIO use: 248.00 KiB Memory use: 3.94 MiB KMem use: 0 bytes
コマンド実行
$ ./lxc exec test01 -- /bin/uname -a Linux test01 3.19.0-plamo64-karma #2 SMP PREEMPT Mon Feb 9 16:13:40 JST 2015 x86_64 x86_64 x86_64 GNU/Linux
lxc-attach コマンドも使えます。
$ lxc-attach -P /var/lib/lxd/lxc -n test01 -- uname -a Linux test01 3.19.0-plamo64-karma #2 SMP PREEMPT Mon Feb 9 16:13:40 JST 2015 x86_64 x86_64 x86_64 GNU/Linux
コンテナの停止
普通にできます。
$ ./lxc stop test01 $ lxc-ls -P /var/lib/lxd/lxc -fNAME STATE IPV4 IPV6 GROUPS AUTOSTART ---------------------------------------------- test01 STOPPED - - - NO
(続く)