openvswitch centos6.X 安装及使用

本文详细介绍了如何在CentOS 6.x系统中从源码编译安装Open vSwitch (OVS),并提供了简单的VLAN配置示例。包括搭建编译环境、创建RPM包、安装服务、配置网络以及测试步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

摘要

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,如需转载请自行联系原作者






评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值