Ubuntu14.04安装配置Open vSwitch

时间:2023-08-05 09:05:32

最近在研究学习Open vSwitch,准备在本地Ubuntu14.04机器上安装一下,并基于其创建一些KVM虚拟机,下面就简要记录下在Ubuntu14.04系统上安装Open vSwitch的过程。

1、由于之前安装过KVM,其在本机生成了一个名为virbr0的bridge,这里我们需要事先将其删除,否则可能会与Open vSwitch产生不兼容的问题,命令如下:

◄►  virsh net-destroy default
Network default destroyed ◄► virsh net-autostart --disable default
Network default unmarked as autostarted

2、这里我们同样也不需要bridge模块:

◄►  sudo aptitude purge ebtables
The following packages will be REMOVED:
ebtables{p}
packages upgraded, newly installed, to remove and not upgraded.
Need to get B of archives. After unpacking kB will be freed.
Do you want to continue? [Y/n/?] y
(Reading database ... files and directories currently installed.)
Removing ebtables (2.0.10.4-3ubuntu1) ...
* Clearing ebtables rulesets [ OK ]
Purging configuration files for ebtables (2.0.10.4-3ubuntu1) ...
Processing triggers for man-db (2.6.7.1-1ubuntu1) ...

3、下面开始安装openvswitch相关包:

◄►  sudo apt-get install openvswitch-switch

4、查看下ovs的运行状况:

◄►  ps -ea | grep ovs
? :: ovsdb-server
? :: ovs-vswitchd

5、查看下安装的ovs的版本:

◄►  ovs-appctl --version
ovs-appctl (Open vSwitch) 2.0.
Compiled May ::

6、查看下当前ovs支持的OpenFlow协议的版本:

◄►  ovs-ofctl --version
ovs-ofctl (Open vSwitch) 2.0.
Compiled May ::
OpenFlow versions 0x1:0x4

7、通过ovs创建一个网桥 br0,供kvm虚拟机使用:

◄►  sudo ovs-vsctl add-br br0
◄► ifconfig
br0 Link encap:Ethernet HWaddr ::fd::e5:4b
inet6 addr: fe80::4c0a:7bff:fec6:98d7/ Scope:Link
UP BROADCAST RUNNING MTU: Metric:
RX packets: errors: dropped: overruns: frame:
TX packets: errors: dropped: overruns: carrier:
collisions: txqueuelen:
RX bytes: (0.0 B) TX bytes: (578.0 B)

通过ifconfig命令,我们发现多了一个br0网桥。

8、将物理网卡eth0添加到br0上:

◄►  sudo ovs-vsctl add-port br0 eth0

这步执行后,发现无法再访问外网,不过没关系,我们可以按照如下步骤解决:

1)先清除eth0的配置:

◄►  sudo ifconfig eth0 

2)让br0自动获取ip地址:

◄►  sudo dhclient br0

3)此时就又可以通外网了:

◄►  ping www.baidu.com
PING www.a.shifen.com (119.75.217.109) () bytes of data.
bytes from 119.75.217.109: icmp_seq= ttl= time=30.9 ms
bytes from 119.75.217.109: icmp_seq= ttl= time=31.9 ms

9、最后查看下目前br0和eth0的情况:

◄►  sudo ovs-vsctl show
1e6548a9-956e-4b86-b743-f8da0aa2b922
Bridge "br0"
Port "br0"
Interface "br0"
type: internal
Port "eth0"
Interface "eth0"
ovs_version: "2.0.2"