2009年6月21日日曜日

OpenVZ #2

CentOS 5の上でOpenVZを導入するにあたって、vethを使ってネットワークを構築するときに得たノウハウを公開しておきます。

用語解説
HN:OpenVZが稼働しているホストマシン(ハードウェアノード)
CT:vzctl createで作成した仮想マシン(コンテナ)

HN上に複数のCTを構築する

この作業は、必ずコンソール上から行ってください。SSHなどネットワークを経由しているときには、途中で一時的にネットワークがつながらなくなるため、作業続行不能となります。

#1の記事にそって、もうひとつCTを作成します(IP:10.0.1.102)
そしてHNから各CTに対してpingを打つと、きちんと結果が返ってきます。

[root@hn ~]# ping -c4 10.0.1.101
PING 10.0.1.101 (10.0.1.101) 56(84) bytes of data.
64 bytes from 10.0.1.101: icmp_seq=1 ttl=64 time=0.093 ms
64 bytes from 10.0.1.101: icmp_seq=2 ttl=64 time=0.110 ms
64 bytes from 10.0.1.101: icmp_seq=3 ttl=64 time=0.109 ms
64 bytes from 10.0.1.101: icmp_seq=4 ttl=64 time=0.113 ms

--- 10.0.1.101 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 2999ms
rtt min/avg/max/mdev = 0.093/0.106/0.113/0.010 ms
[root@hn ~]# ping -c4 10.0.1.102
PING 10.0.1.102 (10.0.1.102) 56(84) bytes of data.
64 bytes from 10.0.1.102: icmp_seq=1 ttl=64 time=0.122 ms
64 bytes from 10.0.1.102: icmp_seq=2 ttl=64 time=0.116 ms
64 bytes from 10.0.1.102: icmp_seq=3 ttl=64 time=0.110 ms
64 bytes from 10.0.1.102: icmp_seq=4 ttl=64 time=0.115 ms

--- 10.0.1.102 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3002ms
rtt min/avg/max/mdev = 0.110/0.115/0.122/0.013 ms

しかし、CTからCTにはpingが通りません。
[root@ct101 /]# ping -c4 10.0.1.102
PING 10.0.1.102 (10.0.1.102) 56(84) bytes of data.
From 10.0.1.101 icmp_seq=2 Destination Host Unreachable
From 10.0.1.101 icmp_seq=3 Destination Host Unreachable
From 10.0.1.101 icmp_seq=4 Destination Host Unreachable

--- 10.0.1.102 ping statistics ---
4 packets transmitted, 0 received, +3 errors, 100% packet loss, time 2999ms
, pipe 3

これは、HNにあるveth101.0とveth102.0がネットワーク的につながっていないのが原因です。
eth0(CT101) --- veth101.0(HN) --|ここが切れている| -- veth102.0(HN) --- eth0(CT102)

HN側に作成された二つの仮想ネットワークインターフェイス(veth101.0, veth102.0)を接続するためには、HN内に仮想のブリッジを作成します。

[root@hn ~]# yum install bridge-utils
[root@hn ~]# brctl addbr vzbr0
[root@hn ~]# brctl addif vzbr0 eth
[root@hn ~]# brctl addif vzbr0 veth101.0
[root@hn ~]# brctl addif vzbr0 veth102.0
[root@hn ~]# ifconfig eth0 down
[root@hn ~]# ifconfig eth0 0.0.0.0 promisc up
[root@hn ~]# ifconfig vzbr0 192.168.0.101 up
[root@hn ~]# route add -net 10.0.1.0 netmask 255.255.255.0 vzbr0
[root@hn ~]# route
ernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
10.0.1.0 * 255.255.255.0 U 0 0 0 vzbr0
192.168.0.0 * 255.255.255.0 U 0 0 0 vzbr0
169.254.0.0 * 255.255.0.0 U 0 0 0 vzbr0
default 192.168.0.230 0.0.0.0 UG 0 0 0 vzbr0

これでct101とct102から、それぞれ別の子サーバへのpingが通るようになります。

0 件のコメント:

コメントを投稿