VMwarePlayer+Ubuntu/KVM/OVSでOpenFlowテスト環境をつくる(1)
はじめに
Windows Note PC にお手軽に入れられる、ポータブルな OpenFlow テスト環境を構築しようという試みの個人的な記録です。目的は、KVM の使い方を見ること、OVS + Trema で OpenFlow のテスト環境を作ることす。Trema だと仮想ネットワークつくってテストする機能とかあるんだけど、まあ KVM とかつかってもうちょっとベタにやってみようよ、という方向です。
第1回は KVM 環境の構築。
ゴール
使う道具はこんな感じ。手軽に試せるというのが一つのコンセプトなので、無償で使えるソフトウェアか OSS をベースにします。
最終的にこういう環境を作ります : Windows7 な PC の上に KVM Host + OFC を構築、KVM Host 上で OVS + KVM Guest による OpenFlow テスト環境を作ります。
KVM Host の構築
KVM Host のインストール
インストール前に、Windows Host 側で Intel VT-x/AMD-V とかが有効になっていることを確認しておきます。
VirtualChecker というアプリでチェックできます。
まずは普通に NAT 接続(VMnet8)で VMware Player 上で Ubuntu をインストールします。その後、仮想マシンの設定をいじって NIC をもう一つ追加、ホストオンリーに接続します。
もうひとつ、仮想マシン側でも VT-x/AMD-V を有効にしておきます。
設定したら仮想マシン上で確認。
ネットワーク設定の確認。デフォルトだと各 NIC は DHCP です。とりあえず、ホスト側(Windows)と通信できることを確認できれば良いです。
/etc/network/interfaces
# The loopback network interface auto lo iface lo inet loopback # The primary network interface auto eth0 iface eth0 inet dhcp # closed local auto eth1 iface eth1 inet dhcp
VT-x/AMD-V の確認は /proc/cpuinfo
で vmx(VT-x) あるいは svm (AMD-V) があるかどうかを確認します。
stereocat@oftest01:~$ cat /proc/cpuinfo processor : 0 vendor_id : GenuineIntel cpu family : 6 model : 58 model name : Intel(R) Core(TM) i5-3320M CPU @ 2.60GHz (略) flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts mmx fxsr sse sse2 ss syscall nx rdtscp lm constant_tsc up arch_perfmon pebs bts nopl xtopology tsc_reliable nonstop_tsc aperfmperf pni pclmulqdq vmx ssse3 cx16 pcid sse4_1 sse4_2 x2apic popcnt aes xsave avx f16c rdrand hypervisor lahf_lm ida arat epb xsaveopt pln pts dtherm tpr_shadow vnmi ept vpid fsgsbase smep
NICの設定(IP固定)
- VMWare Interfaces Tutorial | RedNectar's Blog
- VMWare Player上で動作するUbuntuのIPアドレスを固定化する | 近藤嘉雪のプログラミング工房日誌
サーバとして使うのだと DHCP (動的IP) だと不便なので IP を固定します。とはいえ、VMware 側で作ってあるネットワーク(VMnet1/8) には DHCP が乗っているのでアドレスが重複しないようにする必要があります。
Windows7 の場合、C:\ProgramData\VMware
にある vmnetdhcp.conf
に dhcp 設定が書いてあります。
# Virtual ethernet segment 8 # Added at 12/16/12 16:51:11 subnet 192.168.124.0 netmask 255.255.255.0 { range 192.168.124.128 192.168.124.254; # default allows up to 125 VM's option broadcast-address 192.168.124.255; option domain-name-servers 192.168.124.2; option domain-name "localdomain"; option netbios-name-servers 192.168.124.2; option routers 192.168.124.2; default-lease-time 1800; max-lease-time 7200; } host VMnet8 { hardware ethernet 00:50:56:C0:00:08; fixed-address 192.168.124.1; option domain-name-servers 0.0.0.0; option domain-name ""; option routers 0.0.0.0; }
こんな感じで、VMnet1/8 の各セグメントはそれぞれ、/24 ネットワークで、第4オクテット .128-.254 が dhcp pool として設定されています。また、.1-.2 は gateway/dns/Windows Host IP などで使われています。仮想マシンで固定IPにする場合は、これ以外の .3-.127 の中から選んで使ってやれば良いことになります。
/etc/network/interface
auto eth0 iface eth0 inet static address 192.168.124.127 netmask 255.255.255.0 gateway 192.168.124.2 dns-nameservers 192.168.124.2 192.168.2.16
vmware player の前のバージョンまでは vmnetcfg.exe
がインストーラに同梱されていた気がしますが、vmware player 5 以降はそもそも含まれてもいないようで…。
Version 5
In version 5, the vmnetcfg.exe is in the VMWare Player folder, but running it does nothing. I get an "This program has stopped" error. According to this thread, you must download Workstation 9 and grab vmnetcfg.exe from the core.cab file.
OSの更新
インストールが終わったら update + dist-upgrade して更新しておきます。
stereocat@oftest01:~$ sudo apt-get update stereocat@oftest01:~$ sudo apt-get dist-upgrade stereocat@oftest01:~$ uname -a Linux oftest01 3.2.0-35-generic #55-Ubuntu SMP Wed Dec 5 17:42:16 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux stereocat@oftest01:~$
KVM/OVS のインストール
まずは kvm/libvirt-bin/virtinst package をインストールします。
stereocat@oftest01:~$ sudo apt-get install kvm libvirt-bin virtinst
libvirt をインストールすると bridge ができています。
stereocat@oftest01:~$ ifconfig (略) virbr0 Link encap:Ethernet HWaddr 56:5b:b6:e6:76:b1 inet addr:192.168.122.1 Bcast:192.168.122.255 Mask:255.255.255.0 UP BROADCAST MULTICAST MTU:1500 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:0 (0.0 B) TX bytes:0 (0.0 B) stereocat@oftest01:~$
OVS を使うのでデフォルトの linux bridge は不要…ということで削除します。ebtables package も同様の理由で不要です。合わせて削除しておきます。
stereocat@oftest01:~$ sudo virsh net-destroy default Network default destroyed stereocat@oftest01:~$ sudo virsh net-autostart --disable default Network default unmarked as autostarted stereocat@oftest01:~$ sudo aptitude purge ebtables The following packages will be REMOVED: ebtables{p} (略) stereocat@oftest01:~$
ブリッジを削除したら OVS をインストールします。
stereocat@oftest01:~$ sudo apt-get install openvswitch-controller openvswitch-brcompat openvswitch-switch openvswitch-datapath-source
OVS をインストールしたら、bridge compatibility mode を設定します。
/etc/default/openvswitch-switch
# This is a POSIX shell fragment -*- sh -*- # FORCE_COREFILES: If 'yes' then core files will be enabled. # FORCE_COREFILES=yes # BRCOMPAT: If 'yes' and the openvswitch-brcompat package is installed, then # Linux bridge compatibility will be enabled. # BRCOMPAT=no
最後の行を以下のように変えます。
BRCOMPAT=yes
OVS を起動して動作確認します。
stereocat@oftest01:~$ sudo service openvswitch-switch start * Inserting openvswitch module * Inserting brcompat module * /etc/openvswitch/conf.db does not exist * Creating empty database /etc/openvswitch/conf.db * Starting ovsdb-server * Configuring Open vSwitch system IDs * Starting ovs-vswitchd * Starting ovs-brcompatd * Enabling gre with iptables stereocat@oftest01:~$
カーネルモジュールの確認(brcompat_mod
, openvswitch_mod
)、OVS のプロセス番号の確認(service openvswitch-switch status
)、コンフィグの確認(ovs-vsctl show
: 初期状態なので空)を確認できれば大丈夫です。問題なければ一度再起動しておきます。
stereocat@oftest01:~$ lsmod | grep brcom brcompat_mod 13512 0 openvswitch_mod 83993 1 brcompat_mod stereocat@oftest01:~$ service openvswitch-switch status ovsdb-server is running with pid 12744 ovs-vswitchd is running with pid 12753 ovs-brcompatd is running with pid 12756 stereocat@oftest01:~$ sudo ovs-vsctl show 73ffb051-5d54-4226-bebf-d180b32debda ovs_version: "1.4.0+build0" stereocat@oftest01:~$
なお参考リンクより: OVS 起動したときに "モジュールがカーネル用にビルドされていない" とか、"モジュールのフォーマットがおかしい" とかエラーメッセージが出力された場合、必要なモジュールの再インストールをせよ、とのこと。
$ sudo module-assistant auto-install openvswitch-datapath
ブリッジ(virbr0
)消さなかったりブリッジ周りの設定で変なのを入れるとこんな感じでエラーになります。
stereocat@oftest01:~$ sudo service openvswitch-switch start FATAL: Error inserting brcompat_mod (/lib/modules/3.2.0-35-generic/updates/dkms/brcompat_mod.ko): Invalid module format * Inserting brcompat module Module has probably not been built for this kernel. For instructions, read /usr/share/doc/openvswitch-datapath-source/README.Debian FATAL: Error inserting brcompat_mod (/lib/modules/3.2.0-35-generic/updates/dkms/brcompat_mod.ko): Invalid module format * Inserting brcompat module stereocat@oftest01:~$
OVS 基本設定
まず、OVS の初期設定として、ブリッジと eth1
(VMnet1) の追加をしておきます。
stereocat@oftest01:~$ sudo ovs-vsctl add-br br0 stereocat@oftest01:~$ sudo ovs-vsctl add-port br0 eth1 stereocat@oftest01:~$ sudo ovs-vsctl show 73ffb051-5d54-4226-bebf-d180b32debda Bridge "br0" Port "eth1" Interface "eth1" Port "br0" Interface "br0" type: internal ovs_version: "1.4.0+build0" stereocat@oftest01:~$
KVM Host 側も VMnet1 と通信させたいので、別途インタフェースを書いておきます。
/etc/network/interfaces
auto eth0 iface eth0 inet static address 192.168.124.127 netmask 255.255.255.0 gateway 192.168.124.2 dns-nameservers 192.168.124.2 192.168.2.16 auto eth1 iface eth1 inet manual up /sbin/ifconfig $IFACE up down /sbin/ifconfig $IFACE down auto br0 iface br0 inet static address 192.168.72.127 netmask 255.255.255.0 dns-nameservers 192.168.72.2