lost and found ( for me ? )

Ubuntu 14:04 : install open vswitch with single interface

Here is how to install/configure openvswitch on Ubuntu 14.04 with single interface

reference
http://blog.allanglesit.com/2012/10/linux-kvm-ubuntu-12-10-with-openvswitch/

# tail -1 /etc/lsb-release

DISTRIB_DESCRIPTION="Ubuntu 14.04.1 LTS"

# uname -ri
3.13.0-32-generic x86_64

# kvm -version
QEMU emulator version 2.0.0 (Debian 2.0.0+dfsg-2ubuntu1.1), Copyright (c) 2003-2008 Fabrice Bellard

# libvirtd --version
libvirtd (libvirt) 1.2.2

- before installing openvswitch.

server eth0 --- the internet

- after installing open vswitch

   VM1 vnet0 - ovsbr0p1 - ovsbr0 - eth0 --------- the internet
   VM2 vnet1
   VM3 vnetX
  ←---------------- server ----------------->

ovsbr0p1 : internal port
ovsbr0 : bridge
eth0 : uplink
vnetX : port for VMs

assign an IP to ovsbr0p1 for the KVM host to use the internet

The KVM host has only one NIC.

install openvswitch. assume that you have already installed KVM.
# apt-get install openvswitch-switch

[ configure network ]

add ovsbr0 bridge and destroy default network.

After issuing “ovs-vsctl add-br ovsbr0”, the network ovsbr0 has been automatically created in KVM. ( virsh net-list --all )
# ovs-vsctl add-br ovsbr0

# virsh net-destroy default
Network default destroyed

# ovs-vsctl show
3e182188-430d-443c-abd3-e5d2e93ac90a
   Bridge "ovsbr0"
       Port "ovsbr0"
           Interface "ovsbr0"
               type: internal
   ovs_version: "2.0.1"

virsh # net-list --all
Name                 State      Autostart     Persistent
----------------------------------------------------------
default              inactive   yes           yes
isolate1             active     yes           yes
isolate2             active     yes           yes
isolate3             active     yes           yes
network1             active     yes           yes
network2             active     yes           yes
network3             active     yes           yes
ovsbr0               inactive   no            yes

# net-dumpxml ovsbr0
<network>
 <name>ovsbr0</name>
 <uuid>f2587c6e-b393-4a20-8580-6e5b3c815410</uuid>
 <forward mode='bridge'/>
 <bridge name='ovsbr0'/>
 <virtualport type='openvswitch'/>
</network>

undefine default network ( nat network ) and enable ovsbr0 network. ( open vswitch )
virsh # net-undefine default
Network default has been undefined

virsh # net-autostart ovsbr0
Network ovsbr0 marked as autostarted

virsh # net-list --all
Name                 State      Autostart     Persistent
----------------------------------------------------------
isolate1             active     yes           yes
isolate2             active     yes           yes
isolate3             active     yes           yes
network1             active     yes           yes
network2             active     yes           yes
network3             active     yes           yes
ovsbr0               inactive   yes           yes

connect bridge ovsbr0 to its uplink eth0
# ovs-vsctl add-port ovsbr0 eth0

add an internal port ovsbr0p1 connected to bridge ovsbr0
# ovs-vsctl add-port ovsbr0 ovsbr0p1 -- set interface ovsbr0p1 type=internal


edit /etc/network/interfaces.
assign an IP to ovsbr0.

before editing
# cat /etc/network/interfaces.org
# interfaces(5) file used by ifup(8) and ifdown(8)
auto lo
iface lo inet loopback

auto eth0
#iface eth0 inet dhcp
iface eth0 inet static
   address 192.168.11.100
   netmask 255.255.255.0
   gateway 192.168.11.1
   dns-nameservers 8.8.4.4 8.8.8.8
#    dns-nameservers 127.0.0.1

after editing
assign an IP to ovsbr0p1 for the KVM host to use the internet
# cat /etc/network/interfaces
# interfaces(5) file used by ifup(8) and ifdown(8)
auto lo
iface lo inet loopback

auto eth0
iface eth0 inet manual
up ifconfig $IFACE 0.0.0.0 up
down ifconfig $IFACE down

auto ovsbr0p1
iface ovsbr0p1 inet static
   address 192.168.11.100
   netmask 255.255.255.0
   gateway 192.168.11.1
   dns-nameservers 8.8.8.8
   dns-search mydomain.local

reboot the OS.

after rebooting the OS.

root@ubuntu:~# virsh net-list
Name                 State      Autostart     Persistent
----------------------------------------------------------
isolate1             active     yes           yes
isolate2             active     yes           yes
isolate3             active     yes           yes
network1             active     yes           yes
network2             active     yes           yes
network3             active     yes           yes
ovsbr0               active     yes           yes

# ip addr show | grep -v 'link/ether'
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default
   link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
   inet 127.0.0.1/8 scope host lo
      valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master ovs-system state UP group default qlen 1000
3: ovs-system: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default
4: ovsbr0p1: <BROADCAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UNKNOWN group default
   inet 192.168.11.100/24 brd 192.168.11.255 scope global ovsbr0p1
      valid_lft forever preferred_lft forever
5: ovsbr0: <BROADCAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UNKNOWN group default
6: lxcbr0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UNKNOWN group default
   inet 10.0.3.1/24 brd 10.0.3.255 scope global lxcbr0
      valid_lft forever preferred_lft forever
7: docker0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UNKNOWN group default
   inet 172.17.42.1/16 scope global docker0
      valid_lft forever preferred_lft forever
8: virbr3: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default
   inet 192.168.102.1/24 brd 192.168.102.255 scope global virbr3
      valid_lft forever preferred_lft forever
9: virbr3-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast master virbr3 state DOWN group default qlen 500
10: virbr2: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default
   inet 192.168.101.1/24 brd 192.168.101.255 scope global virbr2
      valid_lft forever preferred_lft forever
11: virbr2-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast master virbr2 state DOWN group default qlen 500
12: virbr4: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default
   inet 192.168.200.1/24 brd 192.168.200.255 scope global virbr4
      valid_lft forever preferred_lft forever
13: virbr4-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast master virbr4 state DOWN group default qlen 500
14: virbr6: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default
   inet 192.168.202.1/24 brd 192.168.202.255 scope global virbr6
      valid_lft forever preferred_lft forever
15: virbr6-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast master virbr6 state DOWN group default qlen 500
16: virbr1: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default
   inet 192.168.100.1/24 brd 192.168.100.255 scope global virbr1
      valid_lft forever preferred_lft forever
17: virbr1-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast master virbr1 state DOWN group default qlen 500
18: virbr5: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default
   inet 192.168.201.1/24 brd 192.168.201.255 scope global virbr5
      valid_lft forever preferred_lft forever
19: virbr5-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast master virbr5 state DOWN group default qlen 500
20: vnet0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master ovs-system state UNKNOWN group default qlen 500



# ovs-vsctl show
3e182188-430d-443c-abd3-e5d2e93ac90a
   Bridge "ovsbr0"
       Port "ovsbr0p1"
           Interface "ovsbr0p1"
               type: internal
       Port "ovsbr0"
           Interface "ovsbr0"
               type: internal
       Port "eth0"
           Interface "eth0"
   ovs_version: "2.0.1"

edit an XML file of a VM to use openvswitch and start the VM
# virsh dumpxml vm1
   <interface type='bridge'>
     <mac address='52:54:00:33:63:cf'/>
     <source bridge='ovsbr0'/>
     <virtualport type='openvswitch'>
       <parameters interfaceid='a08c8dcf-7417-413a-92ee-d2999a1eadca'/>
     </virtualport>
     <model type='virtio'/>

# virsh start vm1

dump the VM xml
port vnet1 has been created by libvirtd.
   <interface type='bridge'>
     <mac address='52:54:00:33:63:cf'/>
     <source bridge='ovsbr0'/>
     <virtualport type='openvswitch'>
       <parameters interfaceid='a08c8dcf-7417-413a-92ee-d2999a1eadca'/>
     </virtualport>
     <target dev='vnet1'/>
     <model type='virtio'/>


# ovs-vsctl show
3e182188-430d-443c-abd3-e5d2e93ac90a
   Bridge "ovsbr0"
       Port "ovsbr0p1"
           Interface "ovsbr0p1"
               type: internal
       Port "ovsbr0"
           Interface "ovsbr0"
               type: internal
       Port "vnet1"
           Interface "vnet1"
       Port "eth0"
           Interface "eth0"
   ovs_version: "2.0.1"

# ip addr show vnet1
22: vnet1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master ovs-system state UNKNOWN group default qlen 500
   link/ether fe:54:00:33:63:cf brd ff:ff:ff:ff:ff:ff

If you run multiple VMs which are connected to the openvswitch, target device (vnetX) for each VM has been added by libvirtd.
Three VMs are running which are connected to the openvswitch.
root@ubuntu:~# virsh list --all
Id    Name                           State
----------------------------------------------------
2     ubuntu1404-vm1                 running
4     ubuntu1404-vm2                 running
5     ubuntu1404-vm3                 running
-     centos7-vm1                    shut off
-     ubuntu1404-vm4                 shut off
-     ubuntu1404-vm5                 shut off
-     ubuntu1404-vm6                 shut off
-     ubuntu1404-vm7                 shut off

root@ubuntu:~# ovs-vsctl show
3e182188-430d-443c-abd3-e5d2e93ac90a
   Bridge "ovsbr0"
       Port "vnet0"
           Interface "vnet0"
       Port "ovsbr0p1"
           Interface "ovsbr0p1"
               type: internal
       Port "ovsbr0"
           Interface "ovsbr0"
               type: internal
       Port "vnet1"
           Interface "vnet1"
       Port "eth0"
           Interface "eth0"
       Port "vnet3"
           Interface "vnet3"
   ovs_version: "2.0.1"

# ip addr show | grep vnet
20: vnet0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master ovs-system state UNKNOWN group default qlen 500
22: vnet1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master ovs-system state UNKNOWN group default qlen 500
23: vnet2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master virbr4 state UNKNOWN group default qlen 500
24: vnet3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master ovs-system state UNKNOWN group default qlen 500
25: vnet4: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master virbr4 state UNKNOWN group default qlen 500

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.