open vswitch研究:ovs的安装和使用

通过

git clone git://openvswitch.org/openvswitch
下载ovs代码到本地,运行boot.sh,如果遇到提示autoconf版本过低,可以去找最新的autoconf m4等rpm包安装或者通过yum update更新,也可以去下一个较新的包自己装下,e.g. http://ftp.gnu.org/gnu/autoconf/autoconf-2.69.tar.gz

之后就是 configure --with-linux=/lib/modules/`uname -r`/build

make

make install  默认安装在/usr/local下


下面开始安装ovs,对于下列步骤最好写个脚本放到启动脚本里

rmmod bridge #移除bridge模块,我们要用openvswitch.ko替换掉

insmod datapath/openvswitch.ko # ovs的核心模块,配合ovs-vswitchd使用

mkdir -p /usr/local/etc/openvswitch


创建ovsdb数据库

ovsdb-tool create /usr/local/etc/openvswitch/conf.db vswitchd/vswitch.ovsschema # 后续可以更改数据库的schema, e.g. ovsdb-tool convert /usr/local/etc/openvswitch/conf.db xxxx.schema


启动ovsdb-server

ovsdb-server /usr/local/etc/openvswitch/conf.db --remote=punix:/usr/local/var/run/openvswitch/db.sock --remote=db:Open_vSwitch,manager_options --pidfile --detach --log-file


启动vswitchd daemon

需要指定和ovsdb-server通信的机制,默认是unix:/usr/local/var/run/openswitch/db.sock

ovs-vsctl --no-wait init

ovs-vswitchd --pidfile --detach unix:/usr/local/var/run/openvswitch/db.sock --log-file --verbose

(--verbose会产生debug log)


我们可以通过ovs-appctl来管理ovsdb-server, ovs-vswitchd这些daemon,e.g. 

ovs-appctl -t ovsdb-server exit, ovs-appctl -t ovsdb-server ovsdb-server/reconnect

ovs-appctl -t ovs-vswitchd exit, ovs-appctl -t ovs-vswitchd qos/show, ovs-appctl -t ovs-vswitchd fdb/flush br0, ovs-appctl -t ovs-vswitchd fdb/show br0


下面就是和bridge基本类似的配置了

ovs-vsctl add-br br0

ovs-vsctl add-port br0 eth0

ifconfig eth0 0 up

ifconfig br0 x.x.x.x netmask x.x.x.x up

route add default gw x.x.x.x


可以通过ovs-vsctl show br0查看

    Bridge "br0"
        Port "br0"
            Interface "br0"
                type: internal
        Port "eth0"
            Interface "eth0"


注意如果想使用brctl(比如xen的很多脚本都依赖brctl),需要启动ovsbrcompatd,首先insmod brcompatd.ko,之后运行ovs-brcompatd --detach --pidfile


-----------------------------------------------华丽的分割线--------------------------------------------------

下面启动一台虚拟机来验证下ovs,需要准备一个kvm的环境,RHEL6对kvm的支持还是蛮赞的,lsmod | grep kvm,如果发现有kvm, kvm_intel(kvm_amd)两个模块,说明已经支持了。同时需要安装一些包

yum install libvirt*

yum install virt-manager

yum install python-virtinst

为了启动libvirtd,还需要安装

yum install avahi*

/etc/init.d/messagebus start

/etc/init.d/avahi-daemon start

/etc/init.d/libvirtd start

chkconfig messagebus on

chkconfig avahi-daemon on

chkconfig libvirtd on


下面通过virt-install安装一台ubuntu11的kvm虚拟机

qemu-img create -f qcow2 ubuntu11 30G  #通过qemu-img创建一个qcow2的空盘

virt-install --connect qemu:///system --hvm --virt-type kvm --name ubuntu11_test1 --ram 8192 --vcpus=4 --disk path=/disk2/kvm/ubuntu11/ubuntu11,format=qcow2 --cdrom=/disk1/iso/ubuntu-11.10-desktop-amd64.iso --nonetworks --vnclisten=x.x.x.x --vncport=6900 --vnc


kvm虚拟机创建成功之后,连接到ovs上

注意,为支持openvswitch,libvirt需要升级到0.9.11以上版本,目前RHEL6上自带的libvirt都是0.9.10版本的,我们下载fedora16的source rpm来build

从 http://libvirt.org/sources/libvirt-0.9.13-1.fc16.src.rpm 中下载,build过程会依赖很多其他的包,请自行解决

下面修改ubuntu11.xml,增加网络部分

   <interface type='bridge'>
      <mac address='54:52:00:83:03:17'/>
      <source bridge='br0'/>
      <virtualport type='openvswitch'>
      </virtualport>
      <model type='virtio'/>
    </interface>

注意kvm的虚拟机的mac地址都以 54:52:00 开头,之后virsh create ubuntu11.xml,成功


----------------------------------------- 华丽的分割线 -----------------------------------------------

下面我们来配置一个gre tunnel,验证下

我使用两台物理机,一台配置了kvm + ovs,另一台配置了xen + ovs,首先建立gre tunnel

ovs-vsctl add-br br1  #在这个bridge建立gre口

ovs-vsctl add-port br1 gre1 -- set interface gre1 type=gre options:remote_ip=x.x.x.x  #这个x.x.x.x 是另一台物理机的地址

ovs-vsctl add-port br1 vnetXXX #把虚拟机的口接入到网桥

两台物理机配置完毕之后,我们看下网桥的fdb表

# ovs-appctl fdb/show br1
 port  VLAN  MAC                Age
    1     0  00:16:3e:91:e2:b9    0
    2     0  54:52:00:83:03:17    0

两台vm的mac地址都被学习到了。。下面互相ping下也没问题

BTW,用传统gre tunnel的方式,性能下降厉害不说,如果是multipath的话也无法支持,对于构建多租户虚拟网络而言,我们需要更加先进的技术方案







  • 1
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 6
    评论
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值