In today's multi-tenant data center environment, virtualization technology is expanding from traditional virtual machine management program-based server virtualization to network virtualization. In this environment, software-based virtual switches are usually deployed on servers together with virtual machine management programs, and KVM is connected in a multi-tenant data center environment, virtualization technology is expanding from traditional virtual machine management program-based server virtualization to network virtualization. In this environment, software-based virtual switches are usually deployed on servers together with virtual machine management programs, which concatenates the traffic transmitted between different virtual machines.
In this tutorial, I will demonstrate how to install and configure KVM and Open vSwitch (OVS) on Ubuntu or Debian ). KVM and Open vSwitch are the most popular Open-source virtual machine management programs and virtual switches in today's data centers.
Install Open vSwitch on Ubuntu or Debian
Although OVS appears in Ubuntu or Debian as a package, I still use the source code to build OVS, which will have the latest features and revisions.
First, install the dependencies used to build OVS.
- ___FCKpd___0nbsp;sudo apt-get install build-essential libssl-dev linux-headers-$(uname -r)
Build OVS using source code, as shown below. Follow these steps to build the OVS kernel module and OVS User space tool.
- ___FCKpd___1nbsp;wget http://openvswitch.org/releases/openvswitch-1.9.3.tar.gz
- ___FCKpd___1nbsp;tar xvfvz openvswitch-1.9.3.tar.gz
- ___FCKpd___1nbsp;cd openvswitch-1.9.3
- ___FCKpd___1nbsp;./configure --with-linux=/lib/modules/`uname -r`/build
- ___FCKpd___1nbsp;make
Next, install the OVS User space component under/usr/local/share:
- ___FCKpd___2nbsp;sudo make install
The next step is to test the OVS kernel module (before this module is installed ). Therefore, first install the kernel module in the kernel.
- ___FCKpd___3nbsp;sudo insmod ./datapath/linux/openvswitch.ko
It is confirmed that the OVS kernel module has been successfully loaded.
- ___FCKpd___4nbsp;lsmod | grep openvswitch
- openvswitch 97934 0
Once you confirm that openvswitch. ko has been successfully loaded into the kernel, continue to install the kernel module, as shown below.
- ___FCKpd___5nbsp;sudo make modules_install
Configure and start Open vSwitch
Create a framework OVS configuration database.
- ___FCKpd___6nbsp;sudo mkdir /etc/openvswitch
- ___FCKpd___6nbsp;sudo ovsdb-tool create /etc/openvswitch/conf.db ./vswit
- chd/vswitch.ovsschema
Start the OVS database server.
- ___FCKpd___7nbsp;sudo ovsdb-server --remote=punix:/usr/local/var/run/ope
- nvswitch/db.sock - remote=db:Open_vSwitch,manager_options
- --pidfile --detach
OVS configures database initialization.
- ___FCKpd___8nbsp;sudo ovs-vsctl --no-wait init
Finally, start the OVS daemon.
- ___FCKpd___9nbsp;sudo ovs-vswitchd --pidfile --detach
Install KVM on Ubuntu or Debian
Use the apt-get command to install KVM and necessary user space tools.
- ___FCKpd___10nbsp;sudo apt-get install qemu-kvm libvirt-bin bridge-utils
- virt-manager
Add a common non-root user (such as alice) to the libmongod group so that the user can start the virtual machine without the root user permission.
- ___FCKpd___11nbsp;sudo adduser alice libvirtd
Log out and log on again as this user to make changes to group members take effect.
Run the following command. If you see a list of empty virtual machines, this means that KVM has been successfully set.
- ___FCKpd___12nbsp;virsh -c qemu:///system list
- Id Name State
Configure Open vSwitch for KVM
Now it is time to create an OVS Bridge startup script, so that OVS can be automatically configured when the VM is started or terminated.
Install dependencies (user-mode Linux utilities) that are used to process the Linux bridge mode.
- ___FCKpd___13nbsp;sudo apt-get install uml-utilities
Create a bridge startup script, as shown below.
- ___FCKpd___14nbsp;sudo vi /etc/openvswitch/ovs-ifup
- #!/bin/sh
- switch='br0'
- /sbin/ifconfig $1 0.0.0.0 up
- ovs-vsctl add-port ${switch} $1
- ___FCKpd___14nbsp;sudo vi /etc/openvswitch/ovs-ifdown
- #!/bin/sh
- switch='br0'
- /sbin/ifconfig $1 0.0.0.0 down
- ovs-vsctl del-port ${switch} $1
- ___FCKpd___14nbsp;sudo chmod +x /etc/openvswitch/ovs-if*
Then, create a default Bridge br0 and add a physical network interface through which the virtual machine will contact the external network. In this tutorial, I assume that this type of network interface is eth5.
- ___FCKpd___15nbsp;sudo ovs-vsctl add-br br0
- ___FCKpd___15nbsp;sudo ovs-vsctl add-port br0 eth5
Start a VM with KVM
Now you can prepare to start the guest virtual machine.
I assume that you have prepared a guest virtual machine image, such as a ubuntu-client.img ). Run the following command to start the guest virtual machine.
- ___FCKpd___16nbsp;sudo kvm -m 1024 -net nic,macaddr=11:11:11:EE:EE:EE -ne
- t tap,script=/etc/openvswitch/ovs-ifup,downscript=/etc/op
- envswitch/ovs-ifdown -vnc :1 -drive file=/home/dev/images
- /ubuntu-client.img,boot=on
This creates and starts a guest virtual machine. Once the guest virtual machine is started, its virtual interface is automatically added to OVS Bridge br0.
You can use the ovs-vsctl command to verify the OVS status, as shown below.
This is the remote desktop session of the started virtual machine.
Link: http://xmodulo.com/2014/01/install-configure-kvm-open-vswitch-ubuntu-debian.html