加入收藏 | 设为首页 | 会员中心 | 我要投稿 | RSS
您当前的位置:首页 > 教程文章 > 虚拟化技术

How to install and configure KVM and Open vSwitch on Ubuntu or Debian

时间:2014-03-07 22:47:52  来源:  作者:

 In today's multi-tenant data centers, the concept of virtualization is being extended from hypervisor-driven server virtualization to network virtualization. In this environment, software-based virtual switches are being installed on servers along with hypervisor, bridging traffic among different virtual machines (VMs).

In this tutorial, I am going to demonstrate how to install and configure KVM and Open vSwitch (OVS) on Ubuntu or Debian. KVM and Open vSwitch are, respectively, the most popular open-source hypervisor and virtual switch used in today's data centers.

Install Open vSwitch on Ubuntu or Debian

While OVS comes as a package on Ubuntu or Debian, here I am going to build it from the source, which will have the latest features and bug fixes.

First, install dependencies for building OVS.

$ sudo apt-get install build-essential libssl-dev linux-headers-$(uname -r)

 

Build OVS from the source as follows. The steps below will build OVS user-space tools as well as its kernel module.

$ wget http://openvswitch.org/releases/openvswitch-1.9.3.tar.gz
$ tar xvfvz openvswitch-1.9.3.tar.gz
$ cd openvswitch-1.9.3
$ ./configure --with-linux=/lib/modules/`uname -r`/build
$ make

 

Go ahead and install OVS user-space components under /usr/local/share/

$ sudo make install

 

The next step is to test the OVS kernel module (before installing it). For that, load the kernel module in the kernel first.

$ sudo insmod ./datapath/linux/openvswitch.ko

 

Verify that the OVS kernel module is loaded successfully.

$ lsmod | grep openvswitch
openvswitch            97934  0

Once you verify that openvswitch.ko is successfully loaded in the kernel, go ahead and install the kernel module as follows.

$ sudo make modules_install

 

Configure and Start Open vSwitch

Create a skeleton OVS configuration database.

$ sudo mkdir /etc/openvswitch
$ sudo ovsdb-tool create /etc/openvswitch/conf.db ./vswitchd/vswitch.ovsschema

 

Start OVS database server.

$ sudo ovsdb-server --remote=punix:/usr/local/var/run/openvswitch/db.sock - remote=db:Open_vSwitch,manager_options --pidfile --detach

 

Initialize OVS configuration database.

$ sudo ovs-vsctl --no-wait init

 

Finally, start OVS daemon.

$ sudo ovs-vswitchd --pidfile --detach

Install KVM on Ubuntu or Debian

Install KVM and necessary user-space tools with apt-get command.

$ sudo apt-get install qemu-kvm libvirt-bin bridge-utils virt-manager

Add a non-root regular user (e.g., alice) to libvirtd group, so that the user can launch VMs without root privilege.

$ sudo adduser alice libvirtd

Log out and log back in as the user to make the group membership change effective.

Run the following command. If you should see an empty list of VMs, that means KVM is set up successfully.

$ virsh -c qemu:///system list
 Id    Name                           State
----------------------------------------------------

Configure Open vSwitch for KVM

Now it is time to create OVS bridge startup scripts, so that OVS can be automatically configured when a VM is started or stopped.

Install dependencies (user-mode Linux utilities), which will be used to handle Linux bridging modes.

$ sudo apt-get install uml-utilities

Create bridge startup scripts as follows.

$ sudo vi /etc/openvswitch/ovs-ifup
1
2
3
4
5
#!/bin/sh
 
switch='br0'
/sbin/ifconfig $1 0.0.0.0 up
ovs-vsctl add-port ${switch} $1
$ sudo vi /etc/openvswitch/ovs-ifdown
1
2
3
4
5
#!/bin/sh
 
switch='br0'
/sbin/ifconfig $1 0.0.0.0 down
ovs-vsctl del-port ${switch} $1
$ sudo chmod +x /etc/openvswitch/ovs-if*

Then, create a default bridge br0, and add a physical network interface via which VMs will communicate with external networks. In this tutorial, I assume such a network interface is eth5.

$ sudo ovs-vsctl add-br br0
$ sudo ovs-vsctl add-port br0 eth5

Launch a VM with KVM

Now you are ready to launch a guest VM.

I assume that you already prepared a guest VM image (e.g., ubuntu-client.img). Use the following command to launch a guest VM.

$ sudo kvm -m 1024 -net nic,macaddr=11:11:11:EE:EE:EE -net tap,script=/etc/openvswitch/ovs-ifup,downscript=/etc/openvswitch/ovs-ifdown -vnc :1 -drive file=/home/dev/images/ubuntu-client.img,boot=on

This will create and launch a guest VM whose virtual interface is automatically added to OVS bridge br0 upon launch.

You can verify the OVS status by using ovs-vsctl command as follows.

This is the remote desktop session for the launched VM.

来顶一下
返回首页
返回首页
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表
推荐资讯
开源网络存储系统FreeNAS 8.0.1 RC2 发布
开源网络存储系统Free
VMWare Workstation 8 最新版发布
VMWare Workstation 8
诺基亚中国塞班系统研发服务部约170人被裁
诺基亚中国塞班系统研
百度开放云计算平台:将推云存储等服务
百度开放云计算平台:
相关文章
    无相关信息
栏目更新
栏目热门