设为首页 收藏本站
查看: 1247|回复: 0

[经验分享] Installing KVM and Open vSwitch on Ubuntu

[复制链接]

尚未签到

发表于 2015-10-10 10:48:35 | 显示全部楼层 |阅读模式

原文:http://blog.scottlowe.org/2012/08/17/installing-kvm-and-open-vswitch-on-ubuntu/:blog.scottlowe.org


This is the first of a number of posts in which I’ll be discussing Ubuntu Linux, KVM, and the Open vSwitch (OVS). I hope that you find the posts helpful.


Let me start this post by providing this disclaimer: I’m still very early in the learning curve with KVM and OVS, so I can’t promise you that this post will be absolutely perfect. It is, however, a pretty decent starting point. I’ve gone through this process
several times, and there is only one sticking point that I haven’t yet resolved (which I’ll describe later on).


I’m going to assume that you are reasonably familiar with Ubuntu, as that’s the platform I’m using for all my testing (specifically, Ubuntu Server 12.04 LTS with a 64-bit kernel). I’m also assuming that you are prefacing all these commands with sudo or
that you’ve attained root privileges via the method of your choice.


We’ll start this process by ensuring that our Ubuntu installation is up-to-date:


# apt-get update && apt-get dist-upgrade

In my case, this brought me up to Ubuntu 12.04.1, running the 3.2.0-29 kernel.


Next, we’ll install KVM and a couple associated packages:


# apt-get install kvm libvirt-bin virtinst

This command will install KVM, libvirt, a couple of command-line utilities, and a whole bunch of other required packages.


Next, to prepare the system for the installation of OVS, we’ll remove the default libvirt bridge (named virbr0). This ensures that the bridge compatibility portion of OVS
can load without any potential conflicts:


# virsh net-destroy default
# virsh net-autostart --disable default

At this point, because we aren’t using the default Linux bridge, we can remove the ebtables package using the following command. (Note: I am not 100% sure that this step is necessary, but almost all of the guides I followed included this step. If anyone
has more information, please let me know in the comments.)


# aptitude purge ebtables

You’re now ready to install OVS (this should be all on one line; I’ve added a line breaks—noted by a backslash—for readability):


# apt-get install openvswitch-controller openvswitch-brcompat \
openvswitch-switch openvswitch-datapath-source

This command installs the various OVS components and—as with KVM—a large number of required packages. Depending on the speed of your Internet connection, you might want to go get a cup of coffee.


Once the OVS packages are installed, we’ll need to enable bridge compatibility mode for OVS. To enable bridge compatibility mode, edit/etc/default/openvswitch-switch and
change this line:


#BRCOMPAT=no

Change it by removing the hash mark (uncommenting it) and specifying yes, like this:


BRCOMPAT=yes

At this point, you can try starting OVS with service openvswitch-switch start, but you might get an error about a module being in the wrong format or not built for your
kernel. If you removed the default libvirt bridge (virbr0) using thevirsh commands
earlier, then you should be OK, but if you get an error about the module being in the wrong format go ahead and run this command to build and install the necessary module:


# module-assistant auto-install openvswitch-datapath

Once this process finishes, let’s go ahead and reboot. After the system reboots and comes back up, check the status of KVM and OVS with the following commands.


To check KVM, use this command:


# virsh -c qemu:///system list

This will return a list of running VMs (which is probably empty on your system).


To check OVS, first use this command to see if the kernel modules loaded properly:


# lsmod | grep brcom

This should return an entry containing brcompat_mod and openvswitch_mod. Follow that
with this command:


service openvswitch-switch status
The output should show several OVS processes in the running state.
Assuming that everything is working properly, you should now be able to runovs-vsctl show and get a very simple
response that basically indicates that OVS has no configuration.
We are now nearing the end; only a couple of steps remain. The last thing we need to do is create an OVS bridge that will allow KVM guests to communicate with the outside world. This is a two-step
process. The first step is to use ovs-vsctl to create a bridge and add at least one physical interface:

# ovs-vsctl add-br br0
# ovs-vsctl add-port br0 eth0
Obviously, you’ll want to substitute the correct physical interface for eth0 in the commands above. After running
these commands, then running ovs-vsctl show will return something like this:

bc12c8d2-6900-42dd-9c1c-30e8ecb99a1b
Bridge "br0"
Port "eth0"
Interface "eth0"
Port "br0"
Interface "br0"
type: internal
ovs_version: "1.4.0+build0"
The final step is to edit /etc/network/interfaces so that the bridge comes up automatically. This is where
I ran into problems. No matter what I tried, I could get the bridge to come up, but the physical interface attached to the bridge would not come up automatically. I could easily manually bring it up (usingifconfig
eth0 up), but it wouldn’t come up automatically on boot. If anyone has any ideas, I’m open to them.
In any case, here’s the /etc/network/interfaces that I used (IP addresses and domain names have been changed
to protect the innocent):

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
auto eth0
iface eth0 inet static
# The OVS bridge interface
auto br0
iface br0 inet static
address 192.168.1.200
network 192.168.1.0
netmask 255.255.255.0
broadcast 192.168.1.255
gateway 192.168.1.1
bridge_ports eth0
bridge_fd 9
bridge_hello 2
bridge_maxage 12
bridge_stp off
dns-search mydomain.local
dns-nameservers 192.168.1.1 192.168.1.2
I tried several different variations for eth0, but none of them would bring the interface up automatically
when I boot the system. Everything else seems to work just fine, so I’ve settled with manually bringing the interface up after a reboot until I figure out how to fix it. Suggestions are welcome.
In a future post (very soon), I’ll be talking more about OVS and what it looks like when you boot up KVM guests on OVS, so stay tuned for that.
As always, thoughts, corrections, questions, and clarifications are welcome—just speak up in the comments below. Thanks!

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-125013-1-1.html 上篇帖子: KVM概念 下篇帖子: KVM初始化过程
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表