摘要
openvswitch 虚拟交换机 centos6.x 编译安装及简单vlan配置
一、搭建编译环境
安装编译环境
1
2
3
|
#yum install gcc make python-devel openssl-devel kernel-devel graphviz \
kernel-debug-devel autoconf automake rpm-build redhat-rpm-config \
libtool
|
编译rpm建议使用普通用户
下载创建编译目录脚本
1
|
$wget
ftp
:
//ftp
.owlriver.com
/pub/local/COLUG//RPM-build-tree
.txt
|
执行脚本
1
|
$sh RPM-build-tree.txt
|
将会在当前用户家目录创建如下目录
1
2
3
4
5
|
rpmbuild
├── BUILD├── BUILDROOT├── RPMS
├── SOURCES
├── SPECS
└── SRPMS
|
二、编译 openvswitch rpm包
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
##切换至家目录
$
cd
~
##下载openvswitch源码包
$wget http:
//openvswitch
.org
/releases/openvswitch-2
.3.1.
tar
.gz
$
cp
openvswitch-2.3.1.
tar
.gz rpmbuild
/SOURCES/
$
tar
xvf openvswitch-2.3.1.
tar
.gz
$
cd
openvswitch-2.3.1
##编译内核
$
cp
rhel
/openvswitch-kmod
.files ~
/rpmbuild/SOURCES/
$rpmbuild -bb rhel
/openvswitch-kmod-rhel6
.spec
##编译openvswitch rpm
$rpmbuild -bb rhel
/openvswitch
.spec
|
编译完成后rpm包位于
1
2
3
4
5
|
ll ~
/rpmbuild/RPMS/x86_64/
total 11440
-rw-rw-r--. 1 firxiao firxiao 1223288 Dec 17 05:50 kmod-openvswitch-2.3.1-1.el6.x86_64.rpm
-rw-rw-r--. 1 firxiao firxiao 2640440 Dec 17 06:01 openvswitch-2.3.1-1.x86_64.rpm
-rw-rw-r--. 1 firxiao firxiao 7846548 Dec 17 06:01 openvswitch-debuginfo-2.3.1-1.x86_64.rpm
|
将openvswitch-2.3.1-1.x86_64.rpm kmod-openvswitch-2.3.1-1.el6.x86_64.rpm 上传至vm1、vm2
使用yum安装
1
|
#yum install openvswitch-2.3.1-1.x86_64.rpm kmod-openvswitch-2.3.1-1.el6.x86_64.rpm
|
启动服务
1
|
#/etc/init.d/openvswitch start
|
三、配置及使用
1
2
3
4
5
6
7
8
9
10
|
vm1 vm2 vm1 and vm2 创建桥接网卡ovsbridge0
---- ---- 基于ovsbridge0创建vlan100网卡。
eth0 ech0
-------------- -------------
ovsbridge0 ovsbridge0
172.16.0.20
/24
172.16.0.21
/24
-------------- --------------
vlan100 vlan100
192.168.100.2
/24
192.168.100.3
/24
---------------- ----------------
|
将配置文件放于/etc/sysconfig/network-scripts
vm1网卡配置信息
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
[root@vm1 network-scripts]
# cat ifcfg-eth0
DEVICE=eth0
ONBOOT=
yes
DEVICETYPE=ovs
TYPE=OVSPort
OVS_BRIDGE=ovsbridge0
BOOTPROTO=none
HOTPLUG=no
[root@vm1 network-scripts]
# cat ifcfg-ovsbridge0
DEVICE=ovsbridge0
ONBOOT=
yes
DEVICETYPE=ovs
TYPE=OVSBridge
BOOTPROTO=static
IPADDR=172.16.0.20
NETMASK=255.255.255.0
HOTPLUG=no
[root@vm1 network-scripts]
# cat ifcfg-vlan100
DEVICE=vlan100
ONBOOT=
yes
DEVICETYPE=ovs
TYPE=OVSIntPort
BOOTPROTO=static
IPADDR=192.168.100.2
NETMASK=255.255.255.0
OVS_BRIDGE=ovsbridge0
OVS_OPTIONS=
"tag=100"
OVS_EXTRA=
"set Interface $DEVICE external-ids:iface-id=$(hostname -s)-$DEVICE-vif"
HOTPLUG=no
|
1
2
3
4
5
6
7
8
9
10
11
12
13
|
[root@vm1 ~]
# ovs-vsctl show
fedbda2f-2516-4aff-b89f-ca221873eb9c
Bridge
"ovsbridge0"
Port
"vlan100"
tag: 100
Interface
"vlan100"
type
: internal
Port
"eth0"
Interface
"eth0"
Port
"ovsbridge0"
Interface
"ovsbridge0"
type
: internal
ovs_version:
"2.3.1"
|
vm2网卡配置信息
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
[root@vm2 network-scripts]
# cat ifcfg-eth0
DEVICE=eth0
ONBOOT=
yes
DEVICETYPE=ovs
TYPE=OVSPort
OVS_BRIDGE=ovsbridge0
BOOTPROTO=none
HOTPLUG=no
[root@vm2 network-scripts]
# cat ifcfg-ovsbridge0
DEVICE=ovsbridge0
ONBOOT=
yes
DEVICETYPE=ovs
TYPE=OVSBridge
BOOTPROTO=static
IPADDR=172.16.0.21
NETMASK=255.255.255.0
HOTPLUG=no
[root@vm2 network-scripts]
# cat ifcfg-vlan100
DEVICE=vlan100
ONBOOT=
yes
DEVICETYPE=ovs
TYPE=OVSIntPort
BOOTPROTO=static
IPADDR=192.168.100.3
NETMASK=255.255.255.0
OVS_BRIDGE=ovsbridge0
OVS_OPTIONS=
"tag=100"
OVS_EXTRA=
"set Interface $DEVICE external-ids:iface-id=$(hostname -s)-$DEVICE-vif"
HOTPLUG=no
|
1
2
3
4
5
6
7
8
9
10
11
12
13
|
[root@vm2 ~]
# ovs-vsctl show
646f5f0f-6a6b-4b01-9c3c-f7684aa64ecc
Bridge
"ovsbridge0"
Port
"eth0"
Interface
"eth0"
Port
"ovsbridge0"
Interface
"ovsbridge0"
type
: internal
Port
"vlan100"
tag: 100
Interface
"vlan100"
type
: internal
ovs_version:
"2.3.1"
|
配置好网卡后
1
|
#service network restart
|
四、测试配置
在vm1 上 vm2 上使用 172.16.0.0/24可以互相通信
使用vlan100 192.168.100.0/24也可进行通信 两个网络互相隔离
编译rpm参考: openvswitch-2.3.1/INSTALL.RHEL
网络配置参考:http://git.openvswitch.org/cgi-bin/gitweb.cgi?p=openvswitch;a=blob_plain;f=rhel/README.RHEL;hb=HEAD
本文转自灬落魄灬 51CTO博客,原文链接:http://blog.51cto.com/smoke520/1793069,如需转载请自行联系原作者