码迷,mamicode.com
首页 > 其他好文 > 详细

openvswitch centos6.X 安装及使用

时间:2016-06-27 00:11:42      阅读:184      评论:0      收藏:0      [点我收藏+]

标签:openvswitch centos6.x 安装及使用

摘要

openvswitch 虚拟交换机 centos6.x 编译安装及简单vlan配置

一、搭建编译环境

 安装编译环境

#yum install gcc make python-devel openssl-devel kernel-devel graphviz        kernel-debug-devel autoconf automake rpm-build redhat-rpm-config        libtool

  编译rpm建议使用普通用户

  下载创建编译目录脚本

$wget ftp://ftp.owlriver.com/pub/local/COLUG//RPM-build-tree.txt

  执行脚本

$sh RPM-build-tree.txt

 将会在当前用户家目录创建如下目录

rpmbuild
├── BUILD├── BUILDROOT├── RPMS
├── SOURCES
├── SPECS
└── SRPMS

二、编译 openvswitch rpm包

##切换至家目录
$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包位于

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安装

#yum install openvswitch-2.3.1-1.x86_64.rpm  kmod-openvswitch-2.3.1-1.el6.x86_64.rpm

  启动服务

#/etc/init.d/openvswitch start


三、配置及使用

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网卡配置信息

[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

   

[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网卡配置信息

[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
[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"


  配置好网卡后

#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


本文出自 “尼古风锁丝愁过” 博客,请务必保留此出处http://smoke520.blog.51cto.com/9256117/1793069

openvswitch centos6.X 安装及使用

标签:openvswitch centos6.x 安装及使用

原文地址:http://smoke520.blog.51cto.com/9256117/1793069

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!