LoginSignup
21
25

More than 5 years have passed since last update.

KVM環境で、OpenvSwitchでゲストVMを外部ネットワークと接続するメモ

Last updated at Posted at 2015-02-22

目的

仮想ネットワーク周りの学習のため、KVM環境で、OpenvSwitchでゲストVMを外部ネットワークと接続する(下図)環境を構築したので、その手順メモ。

最終イメージ

ScreenClip.png

 前提条件

  • ホストはCentOS6.6(64bit)インストール済み
  • ゲストVMのOSインストールメディアをダウンロード済

手順

KVMのインストール

# yum -y install qemu-kvm qemu-kvm-tools

ゲストVMの作成

割愛:libvirtで管理出来るように作成(virt-install等)。

OpenvSwitchのインストール

事前準備

# yum -y install wget gcc make automake rpm-build redhat-rpm-config openssl-devel kernel-devel libtool

LinuxBridgeが存在していたら削除

# lsmod | grep bridge
(bridgeがあったら)
# rmmod bridge

OpenvSwitchのインストール

# cd
# wget http://openvswitch.org/releases/openvswitch-2.3.1.tar.gz
# cp openvswitch-2.3.1.tar.gz ~/rpmbuild/SOURCES/
# tar zxvf openvswitch-2.3.1.tar.gz
# cd openvswitch-2.3.1
# cp rhel/openvswitch-kmod.files ~/rpmbuild/SOURCES/
# rpmbuild -bb rhel/openvswitch.spec
# rpmbuild -bb rhel/openvswitch-kmod-rhel6.spec
# cd ~/rpmbuild/RPMS/x86_64/
# yum -y install openvswitch-2.3.1-1.x86_64.rpm kmod-openvswitch-2.3.1-1.el6.x86_64.rpm

OpenvSwitchの起動、確認

# /etc/init.d/openvswitch start
# ovs-vsctl show
fba905c9-89dd-4ca5-8ba6-c873771c3fed
    ovs_version: "2.3.1"

仮想ブリッジの追加

# ovs-vsctl add-br ovsbr0
# ovs-vsctl add-port ovsbr0 eth0
# ovs-vsctl show
fba905c9-89dd-4ca5-8ba6-c873771c3fed
    Bridge "ovsbr0"
        Port "ovsbr0"
            Interface "ovsbr0"
                type: internal
        Port "eth0"
            Interface "eth0"
    ovs_version: "2.3.1"

IPアドレスの設定

# ifconfig eth0 0.0.0.0
# ifconfig ovsbr0 192.168.0.3/24

仮想マシンの設定

# virsh shutdown gutestos
# virsh edit guestos
(例)
 <interface type='bridge'>
      <mac address='52:54:00:68:bf:42'/>
      <source bridge='ovsbr0'/>
      <virtualport type='openvswitch'>![ScreenClip.png](https://qiita-image-store.s3.amazonaws.com/0/50690/522b846f-fef9-e62c-1aa3-5823e1c6491e.png)

      </virtualport>
      <model type='virtio'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
    </interface>
# virsh start guestos

仮想ネットワークの確認

以下の例ではvnet1インタフェースが作成されている

# ovs-vsctl show
fba905c9-89dd-4ca5-8ba6-c873771c3fed
    Bridge "ovsbr0"
        Port "ovsbr0"
            Interface "ovsbr0"
                type: internal
        Port "vnet1"
            Interface "vnet1"
        Port "eth0"
            Interface "eth0"
    ovs_version: "2.3.1"

ゲストVMの設定

IPアドレスの設定(割愛)

以上。

参考

KVM環境でLinux標準ブリッジの代わりにOpen vSwitchを利用する - 揮発性メモリ搭載エンジニアの日記 http://knqyf263.hatenablog.com/entry/2013/12/30/220214

KVMからbr0(ブリッジインターフェイス)が選択できないけど何故か解決した件 - qphoney記 http://qphoney.hatenadiary.com/entry/2011/12/01/184534

CentOS 6.4 に Open vSwitch 2.0.0 をインストールする | CUBE SUGAR STORAGE http://momijiame.tumblr.com/post/68058348274/centos-6-4-open-vswitch-2-0-0

21
25
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
21
25