2009年6月9日火曜日

quagga on lxc

T/O debian/lenny amd64 でやってみました。こちらにイメージ? 置いときます。/opt/lxc 配下に展開仮定なので fstab を適宜直して使ってやって下さい。# レイノゴトクルートデ....
# seq とゆーもの覚えた。
# for i in `seq 0 7`; do
> br=br${i}
> brctl addbr $br
> brctl setfd $br 0
> brctl stp $br off
> ip link set $br up
> done

# ip link ls | grep "br[0-7]"
630: br0: mtu 1500 qdisc noqueue state UNKNOWN
631: br1: mtu 1500 qdisc noqueue state UNKNOWN
632: br2: mtu 1500 qdisc noqueue state UNKNOWN
633: br3: mtu 1500 qdisc noqueue state UNKNOWN
634: br4: mtu 1500 qdisc noqueue state UNKNOWN
635: br5: mtu 1500 qdisc noqueue state UNKNOWN
636: br6: mtu 1500 qdisc noqueue state UNKNOWN
637: br7: mtu 1500 qdisc noqueue state UNKNOWN
# ip addr add 192.168.200.1/24 dev br0
# pwd
/opt/lxc/quagga
# lxc-execute -n quagga -f lxc-quagga.conf -- /etc/init.d/quagga start &
[1] 5417
# Loading capability module if not yet done.
Starting Quagga daemons (prio:10): zebra ospfd ospf6d.

#
で稼働。起動の仕方がイマイチの気もするけど、まぁ。zebra と ospfd、 ospf6d が起動しているハズです。ホスト側のアドレスはこんな感じ。
# ip addr ls | egrep "(^[0-9]|inet )"
1: lo: mtu 16436 qdisc noqueue state UNKNOWN
inet 127.0.0.1/8 scope host lo
2: eth0: mtu 1500 qdisc pfifo_fast state UP qlen 1000
3: sit0: mtu 1480 qdisc noop state DOWN
4: ip6tnl0: mtu 1460 qdisc noop state DOWN
5: wmaster0: <> mtu 0 qdisc noop state DOWN qlen 1000
6: wlan0: mtu 1500 qdisc noop state DOWN qlen 1000
7: vlan10@eth0: mtu 1500 qdisc noqueue state UP
inet 172.27.129.2/24 brd 172.27.129.255 scope global vlan10
8: vlan11@eth0: mtu 1500 qdisc noqueue state UP
inet 192.168.1.3/24 brd 192.168.1.255 scope global vlan11
630: br0: mtu 1500 qdisc noqueue state UNKNOWN
inet 192.168.200.1/24 scope global br0
631: br1: mtu 1500 qdisc noqueue state UNKNOWN
632: br2: mtu 1500 qdisc noqueue state UNKNOWN
....
やっぱりホスト側でも ospfd 動いているので、寂しい経路数ですが....
# telnet 192.168.200.10 zebra
Trying 192.168.200.10...
Connected to 192.168.200.10.
Escape character is '^]'.

Hello, this is Quagga (version 0.99.10).
Copyright 1996-2005 Kunihiro Ishiguro, et al.


User Access Verification

Password:
zebra@quagga> en
Password:
zebra@quagga# show ip route
Codes: K - kernel route, C - connected, S - static, R - RIP, O - OSPF,
I - ISIS, B - BGP, > - selected route, * - FIB route

C>* 127.0.0.0/8 is directly connected, lo
C>* 192.168.200.0/24 is directly connected, eth0
C>* 192.168.201.0/24 is directly connected, eth1
C>* 192.168.202.0/24 is directly connected, eth2
C>* 192.168.203.0/24 is directly connected, eth3
C>* 192.168.204.0/24 is directly connected, eth4
C>* 192.168.205.0/24 is directly connected, eth5
C>* 192.168.206.0/24 is directly connected, eth6
C>* 192.168.207.0/24 is directly connected, eth7
zebra@quagga#
申し遅れましたが、パスワードは共に zebra です。
# telnet 192.168.200.10 ospfd
Trying 192.168.200.10...
Connected to 192.168.200.10.
Escape character is '^]'.

Hello, this is Quagga (version 0.99.10).
Copyright 1996-2005 Kunihiro Ishiguro, et al.


User Access Verification

Password:
ospfd@quagga> en
Password:
ospfd@quagga# conf t
ospfd@quagga(config)# router ospf
ospfd@quagga(config-router)# network 192.168.200.0/24 area 0.0.0.128
ospfd@quagga(config-router)#
で再度 zebra に
# telnet 192.168.200.10 zebra
Trying 192.168.200.10...
Connected to 192.168.200.10.
Escape character is '^]'.

Hello, this is Quagga (version 0.99.10).
Copyright 1996-2005 Kunihiro Ishiguro, et al.


User Access Verification

Password:
zebra@quagga> en
Password:
zebra@quagga# show ip route
Codes: K - kernel route, C - connected, S - static, R - RIP, O - OSPF,
I - ISIS, B - BGP, > - selected route, * - FIB route

C>* 127.0.0.0/8 is directly connected, lo
O>* 172.27.1.0/24 [110/40] via 192.168.200.1, eth0, 00:00:58
O>* 172.27.68.0/24 [110/40] via 192.168.200.1, eth0, 00:00:58
O>* 172.27.129.0/24 [110/20] via 192.168.200.1, eth0, 00:00:59
O>* 172.27.193.0/24 [110/30] via 192.168.200.1, eth0, 00:00:59
O 192.168.200.0/24 [110/10] is directly connected, eth0, 00:00:59
C>* 192.168.200.0/24 is directly connected, eth0
C>* 192.168.201.0/24 is directly connected, eth1
C>* 192.168.202.0/24 is directly connected, eth2
C>* 192.168.203.0/24 is directly connected, eth3
C>* 192.168.204.0/24 is directly connected, eth4
C>* 192.168.205.0/24 is directly connected, eth5
C>* 192.168.206.0/24 is directly connected, eth6
C>* 192.168.207.0/24 is directly connected, eth7
をぉ....後片付けは
# lxc-stop -n quagga
#
[1]+ Exit 137 lxc-execute -n quagga -f lxc-quagga.conf -- /etc/init.d/quagga start
# lxc-destroy -n quagga
最近のものを git で持ってこないと、後が何かおかしくなるコトあり。

# 沢山稼働させる場合は、きちんと絵を描いてから。って自分に言いきかせる。

/dev/pts -o newinstance,ptmxmode= その 2

udev やっぱわかってない。ごめんなさい....当面、こんなんで繕っていますが udev 絡めた方法や、イカンと思った方は教えてやって下さい。udev 周りイジらず /etc/init.d 配下のファイルだけ。正統派で無い気がする。
~# diff -ubB /etc/init.d/mountdevsubfs.sh.orig /etc/init.d/mountdevsubfs.sh
--- /etc/init.d/mountdevsubfs.sh.orig 2009-05-27 21:40:09.000000000 +0900
+++ /etc/init.d/mountdevsubfs.sh 2009-06-09 21:06:46.000000000 +0900
@@ -60,7 +60,8 @@
fi
if [ -d /dev/pts ]
then
- if [ ! -c /dev/ptmx ]
+ domount devpts "" /dev/pts devpts -onoexec,nosuid,gid=$TTYGRP,mode=$TTYMODE,newinstance,ptmxmode=0666
+ if [ ! -c /dev/ptmx -a ! -c /dev/pts/ptmx ]
then
mknod --mode=666 /dev/ptmx c 5 2
ES=$?
@@ -69,8 +70,9 @@
log_warning_msg "Failed making node /dev/ptmx with error code ${ES}."
fi
[ -x /sbin/restorecon ] && /sbin/restorecon /dev/ptmx
+ else
+ ln -sf /dev/pts/ptmx /dev/ptmx
fi
- domount devpts "" /dev/pts devpts -onoexec,nosuid,gid=$TTYGRP,mode=$TTYMODE
fi
fi
}
diff -ubB /etc/init.d/mtab.sh.orig /etc/init.d/mtab.sh
--- /etc/init.d/mtab.sh.orig 2009-06-01 22:25:45.000000000 +0900
+++ /etc/init.d/mtab.sh 2009-06-01 23:18:15.000000000 +0900
@@ -137,7 +137,7 @@
SHM_OPT=
[ "${SHM_SIZE:=$TMPFS_SIZE}" ] && SHM_OPT=",size=$SHM_SIZE"
domtab tmpfs /dev/shm tmpfs -onosuid,nodev$SHM_OPT
- domtab devpts /dev/pts "devpts" -onoexec,nosuid,gid=$TTYGRP,mode=$TTYMODE
+ domtab devpts /dev/pts "devpts" -onoexec,nosuid,gid=$TTYGRP,mode=$TTYMODE,newinstance,ptmxmode=0666

# Add everything else in /proc/mounts into /etc/mtab, with
# special exceptions.
むーん....

2009年6月4日木曜日

lxc のインストール 4

まとめてみると
  • debian/lenny で git から持ってきた lxc-sshd はそのままは動きそうになさげ。
    動かすにあたっては....

  • /usr/local/ 配下などにインストールする場合はコンテナ内で liblxc.*.so が見付けられるようにする

  • コンテナ側での /dev/pts マウント

  • より独立したコンテナを望むのであればホスト側で devpts を newinstance オプション付でマウントする。
    (詳細は /usr/src/linux/Documentation/filesystems/devpts.txt参照)
ってコトでしょうか。

lxc のインストールと言うより lxc-sshd を動かすまでの道のりになってしまいました。
ごめんなさい....おやすみなさい....

lxc のインストール 3

続き。別ターミナルから
# killall slogin
戻って
# lxc-stop -n tetest
#
[1]+ Exit 137 lxc-execute -n tetest /usr/sbin/sshd
# lxc-execute -n tetest /bin/bash
# /usr/sbin/sshd -dD
....
Server listening on 0.0.0.0 port 22.
また別ターミナル行って
# slogin -v 192.168.1.100
....
debug1: Next authentication method: password
root@192.168.1.100's password:
....
debug1: permanently_set_uid: 0/0
Environment:
LANG=en_US
USER=root
LOGNAME=root
戻ってみると
debug1: Allocating pty.
openpty: No such file or directory
session_pty_req: session 0 alloc failed
....
debug1: session_input_channel_req: session 0 req shell
^CExiting on signal 2
debug1: do_cleanup
# exit
わかる人には、わかるのでしょうが、この後のコンテナで strace したり、デーモン君のソース探検読んだり。で、結果 /dev/pts が マウントされていないため。に気付くに至る....
# lxc-execute -n tetest /bin/bash
# mount -t devpts none /dev/pts
# mount
none on /dev/pts type devpts (rw)
# /usr/sbin/sshd
#
で、別ターミナルから
# slogin 192.168.1.100
root@192.168.1.100's password:
-bash-3.2#
おぉ....。ひとしきり遊んだ後で止めて、更にターミナル戻って # 変なところで試していてごめんなさい
# cat /usr/local/var/lib/lxc/tetest/fstab
/lib /opt/src/lxc/./rootfs.tetest/lib none ro,bind 0 0
/bin /opt/src/lxc/./rootfs.tetest/bin none ro,bind 0 0
/usr /opt/src/lxc/./rootfs.tetest/usr none ro,bind 0 0
/sbin /opt/src/lxc/./rootfs.tetest/sbin none ro,bind 0 0
/opt/src/lxc/rootfs.tetest /usr/local/var/lib/lxc/tetest/rootfs none rbind 0 0
# vi !$
....
# cat /usr/local/var/lib/lxc/tetest/fstab
/lib /opt/src/lxc/./rootfs.tetest/lib none ro,bind 0 0
/bin /opt/src/lxc/./rootfs.tetest/bin none ro,bind 0 0
/usr /opt/src/lxc/./rootfs.tetest/usr none ro,bind 0 0
/sbin /opt/src/lxc/./rootfs.tetest/sbin none ro,bind 0 0
/dev/pts /opt/src/lxc/./rootfs.tetest/dev/pts none bind 0 0
# none /opt/src/lxc/./rootfs.tetest/dev/pts devpts defaults 0 0 も同じようなモン
/opt/src/lxc/rootfs.tetest /usr/local/var/lib/lxc/tetest/rootfs none rbind 0 0
# lxc-execute -n tetest /usr/sbin/sshd &
[1] 30491
で OK なんだけど....
# echo $$
29056
# ls -l /proc/29056/fd/
total 0
lrwx------ 1 root root 64 2009-06-04 22:31 0 -> /dev/pts/1
lrwx------ 1 root root 64 2009-06-04 22:31 1 -> /dev/pts/1
lrwx------ 1 root root 64 2009-06-04 22:31 2 -> /dev/pts/1
lrwx------ 1 root root 64 2009-06-04 22:31 255 -> /dev/pts/1
別ターミナルで
# slogin 192.168.1.100
root@192.168.1.100's password:
-bash-3.2# echo hogehoge > /dev/pts/1
として、ターミナル戻ってみると... がイカンと言うことで newinstance という devpts マウントのオプションができたらしいです。

lxc のインストール 2

続き。
# lxc-execute -n tetest /bin/bash
/usr/local/libexec/lxc-init: error while loading shared libraries: liblxc-0.6.2.so: cannot open shared object file: No such file or directory
# ldd /usr/local/libexec/lxc-init
linux-gate.so.1 => (0xb8070000)
libutil.so.1 => /lib/i686/cmov/libutil.so.1 (0xb8060000)
liblxc-0.6.2.so => /usr/local/lib/liblxc-0.6.2.so (0xb804a000)
libc.so.6 => /lib/i686/cmov/libc.so.6 (0xb7eef000)
/lib/ld-linux.so.2 (0xb8071000)
# ls -l /usr/local/lib/liblxc-0.6.2.so
-rwxr-xr-x 1 root staff 271005 2009-06-04 20:48 /usr/local/lib/liblxc-0.6.2.so
って何よ何。で Google 様に尋ねたところ chroot 先 ldconfig の問題との事。liblxc-0.6.2.so/usr/lib にコピーしてあげれば OK でこだわる必要無いけど....
lxc-createした後 chroot 先は var/lib/lxc。今回の場合は /usr/local/var/lxc なので
# cd /usr/local/var/lib/lxc/
# ls
tetest
# cd tetest
# ls
config fstab network rootfs state utsname
# cd rootfs
# ls
rootfs
# cd rootfs
# ls
bin dev etc lib lib64 proc root sbin sys tmp usr var
# cd etc
# ls
group gshadow passwd shadow ssh
# cat > ld.so.conf
/usr/local/lib
# cp /usr/local/lib/liblxc-0.6.2.so /usr/lib/
# lxc-execute -n tetest /sbin/ldconfig
# pwd
/usr/local/var/lib/lxc/tetest/rootfs/rootfs/etc
# ls -l ld.so.cache
-rw-r--r-- 1 root root 37669 2009-06-04 21:29 ld.so.cache
# rm /usr/lib/liblxc-0.6.2.so
# cd
# lxc-execute -n tetest /bin/bash
# hostname
tetest
鶏卵だけど /usr/local にインストールした場合、chroot 先に /usr/local/lib 含んだ /etc/ld.so.cache が必要。で 本筋に戻って
# lxc-execute -n tetest /usr/sbin/sshd
^Z
[1]+ Stopped lxc-execute -n tetest /usr/sbin/sshd
# bg
[1]+ lxc-execute -n tetest /usr/sbin/sshd &
# ping 192.168.1.100
PING 192.168.1.100 (192.168.1.100) 56(84) bytes of data.
64 bytes from 192.168.1.100: icmp_seq=1 ttl=64 time=1.08 ms
64 bytes from 192.168.1.100: icmp_seq=2 ttl=64 time=0.157 ms
64 bytes from 192.168.1.100: icmp_seq=3 ttl=64 time=0.159 ms
^C
--- 192.168.1.100 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2000ms
rtt min/avg/max/mdev = 0.157/0.466/1.082/0.435 ms
おぉ....
# slogin 192.168.1.100
The authenticity of host '192.168.1.100 (192.168.1.100)' can't be established.
RSA key fingerprint is ff:9e:86:97:0e:98:44:23:98:44:93:b0:2e:2c:a8:ee.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.1.100' (RSA) to the list of known hosts.
root@192.168.1.100's password:
PTY allocation request failed on channel 0
# 応答なし
もぉ....
# あと二つ三つつづく。

lxc のインストール

順序がおかしいけど debian/lenny で git リポジトリからのインストールをちょっと jot。
debian/sid ではパッケージ化されていて、依存関係眺めると libc6-dev の他は libcap2-dev と libcap2-bin があれば OK。マニュアル作成に docbook-utils が必要だけど tex 関連の依存大きいので割愛。カーネルは 2.6.30-rc では
CONFIG_CGROUP_NS=y
....
CONFIG_NAMESPACES=y
CONFIG_UTS_NS=y
CONFIG_IPC_NS=y
CONFIG_USER_NS=y
CONFIG_PID_NS=y
CONFIG_NET_NS=y
....
CONFIG_DEVPTS_MULTIPLE_INSTANCES=y
最後は先日の /dev/pts のお話。git リポジトリは大元参考にして....
#  git-clone git://lxc.git.sourceforge.net/gitroot/lxc 
Initialized empty Git repository in /opt/src/lxc/.git/
remote: Counting objects: 2234, done.
remote: Compressing objects: 100% (1099/1099), done.
remote: Total 2234 (delta 1740), reused 1461 (delta 1123)
Receiving objects: 100% (2234/2234), 559.49 KiB | 125 KiB/s, done.
Resolving deltas: 100% (1740/1740), done.
# ls
lxc
# cd lxc
# ls
AUTHORS configure.ac doc lxc.spec.in NEWS scripts TODO
autogen.sh CONTRIBUTING etc MAINTAINERS README src
config COPYING INSTALL Makefile.am RELEASE-NOTES test
# ./autogen.sh
....
# ./configure --prefix=/usr/local && make && make install
....
# lxc-setcap -h
lxc-setcap [-d] : set or remove capabilities on the lxc tools
libcap2 関係入れある lxc-setcap で root でなくても動かせるらしいけど、面倒なのでそのまま。先にネットワーク周り。後の lxc-sshd にて名称 br0 は固定なので
# brctl addbr br0
# brctl stp br0 off
# ip addr add 192.168.1.1/24 dev br0
# ip link set br0 up
その後 lxc-sshd
# lxc-sshd -h
Usage: /usr/local/bin/lxc-sshd {create|destroy|help}
# lxc-sshd create
What is the container name ? [sshd] tetest
What hostname do you wish for this container ? [tetest] tetest
What IP address do you wish for this container ? [172.20.0.20/24] 192.168.1.100/24
Done.

You can run your container with:
'lxc-execute -n tetest /usr/sbin/sshd &'

# lxc-execute -n tetest /usr/sbin/sshd
/usr/local/libexec/lxc-init: error while loading shared libraries: liblxc-0.6.2.so: cannot open shared object file: No such file or directory
むーん、見事に動かず。長くなったので続きは次のエントリで。

2009年6月1日月曜日

/dev/pts -o newinstance,ptmxmode=

唐突に lxc を試し始めてみました。 IBM dw の記事 が詳しいです。で、唐突ついでに /dev/pts のお話。
lxc.mount = ./fstab
....

/dev/pts /opt/lxc/rootfs/dev/pts none bind 0 0
ではコンテナを root で実行して、コンテナ内で
echo hogehoge > /dev/pts/0
なんてすると、見事? ホスト側の /dev/pts/0 に hogehoge と出力されてしまうのはイカンでしょ。で devpts を mount するオプションで newinstance なるモノが登場。こちらで /dev/pts/ についても別空間にしましょう。というコトらしい。詳しくは /usr/src/linux/Documentation/filesystems/devpts.txt を参照してみて下さい。こちら有効するために格闘。etch からのバージョンアップなので、未確認の部分もあるけど
--- /etc/init.d/mountdevsubfs.sh.orig 2009-05-27 21:40:09.000000000 +0900
+++ /etc/init.d/mountdevsubfs.sh 2009-06-01 23:35:42.000000000 +0900
@@ -70,7 +70,7 @@
fi
[ -x /sbin/restorecon ] && /sbin/restorecon /dev/ptmx
fi
- domount devpts "" /dev/pts devpts -onoexec,nosuid,gid=$TTYGRP,mode=$TTYMODE
+ domount devpts "" /dev/pts devpts -onoexec,nosuid,gid=$TTYGRP,mode=$TTYMODE,newinstance,ptmxmode=0666
fi
fi
}

--- /etc/init.d/mtab.sh.orig 2009-06-01 22:25:45.000000000 +0900
+++ /etc/init.d/mtab.sh 2009-06-01 23:18:15.000000000 +0900
@@ -137,7 +137,7 @@
SHM_OPT=
[ "${SHM_SIZE:=$TMPFS_SIZE}" ] && SHM_OPT=",size=$SHM_SIZE"
domtab tmpfs /dev/shm tmpfs -onosuid,nodev$SHM_OPT
- domtab devpts /dev/pts "devpts" -onoexec,nosuid,gid=$TTYGRP,mode=$TTYMODE
+ domtab devpts /dev/pts "devpts" -onoexec,nosuid,gid=$TTYGRP,mode=$TTYMODE,newinstance,ptmxmode=0666

# Add everything else in /proc/mounts into /etc/mtab, with
# special exceptions.

--- /etc/udev/rules.d/50-udev.rules.orig 2009-06-01 23:37:47.000000000 +0900
+++ /etc/udev/rules.d/50-udev.rules 2009-06-01 23:05:15.000000000 +0900
@@ -99,3 +99,5 @@
SUBSYSTEM=="aoe", NAME="etherd/%k"

KERNEL=="device-mapper", NAME="mapper/control"
+
+KERNEL=="ptmx", NAME="pts/ptmx"
/dev/pts/ptmx をイキナリ 0666 にしてはイカンらしいが、まぁ X でターミナルも開いたし、ssh でログインもできた。

つづきはまた後日。