现在的位置: 首页 > 综合 > 正文

Install Openvswitch by binary and source way on rhe6.3 ( by quqi99 )

2014年01月13日 ⁄ 综合 ⁄ 共 8762字 ⁄ 字号 评论关闭

                                                           Install Openvswitch by rpm binary and source code way on rhe6.3 ( by quqi99 )

作者:张华  发表于:2012-12-30
版权声明:可以任意转载,转载时请务必以超链接形式标明文章原始出处和作者信息及本版权声明

( http://blog.csdn.net/quqi99 )


1 Install openvswitch by rpm binary way

 cat /etc/yum.repos.d/base.repo
     [rhel]
    name=rhel
    baseurl=ftp://ftp.redhat.com/pub/redhat/linux/enterprise/6Workstation/en/os/SRPMS/
    enabled=1
    gpgcheck=0

    [centos]
    name=centos
    baseurl=http://mirror.centos.org/centos/6/os/x86_64
    enabled=1
    gpgcheck=0

1) yum install gcc make python-devel openssl-devel kernel-devel kernel-debug-devel tunctl
       2) Install rpm packages
          rpm -ivh http://rchgsa.ibm.com/projects/e/emsol/ccs/build/driver/300/openstack/latest-bld/x86_64/kmod-openvswitch-1.4.2-1.el6.x86_64.rpm
          rpm -ivh http://rchgsa.ibm.com/projects/e/emsol/ccs/build/driver/300/openstack/latest-bld/x86_64/openvswitch-1.4.2-1.x86_64.rpm
          Note: above openvswitch.rpm doesn't include brcompat.ko
       3) restart the service
          service openvswitch restart
       4) add following commands to /etc/rc.local and delete the file /etc/sysconfig/network-scripts/ifcfg-br-ex
        sudo ovs-vsctl add-br br-int
        ifconfig eth1 down
        sudo ovs-vsctl add-br br-ex
        ip add flush eth1
        ifconfig down eth1
        sudo ovs-vsctl add-port br-ex eth1
        ifconfig eth1 promisc up
        ifconfig br-ex 192.168.100.122 netmask 255.255.255.0 broadcast 192.168.100.255
        route add default gw 192.168.100.1 br-ex
        ip addr add 172.16.100.122/24 brd 172.16.100.255 dev br-ex
        echo 'nameserver 9.0.148.50' > /etc/resolv.conf

          Note: it will throw the error "SIOCADDRT: No such process" if use the command "ip addr add 192.168.100.122/24 broadcast 192.168.100.255 dev br-ex"
          to set ip when running the command "route add default gw 192.168.100.1 br-ex"

          Note: we can't use following bridge configuration to set ip for openvswitch bridge
                because in redhat there are no pre-up and pre-down scripts to configure eth1 into promisc mode.
            vi /etc/sysconfig/network-scripts/ifcfg-br-ex
                DEVICE="br-ex"
        NM_CONTROLLED="no"
        ONBOOT="yes"
        TYPE="Ethernet"
        BOOTPROTO=static
        IPADDR=192.168.100.122
        GATEWAY=192.168.100.1
        NETMASK=255.255.255.0
        DNS1=9.0.148.50
       5) cat /etc/hosts
          172.16.100.122  openstack
          [root@openstack ~]# hostname
           openstack


2 Install openvswitch by source code way

  1) yum install gcc make python-devel openssl-devel kernel-devel kernel-debug-devel
       2) wget http://openvswitch.org/releases/openvswitch-1.7.1.tar.gz
          tar xvfz openvswitch-1.7.1.tar.gz
          cd openvswitch-1.7.1
          ./configure --with-linux=/lib/modules/`uname -r`/build

       3) Then fix a bug, edit skbuff.h around line 242 by commenting out the following method
          vi datapath/linux/compat/include/linux/skbuff.h
            241 #if LINUX_VERSION_CODE < KERNEL_VERSION(3,2,0)
        242 //static inline struct page *skb_frag_page(const skb_frag_t *frag)
        243 //{
        244 //      return frag->page;
        245 //}
        246 #endif

       4) make && make install

       5) Now that you got it to build cleanly you need to make sure the linux bridge kernel module is not loaded. /sbin/rmmod bridge
          Then insert the openvswitch.ko kernel module.
          insmod datapath/linux/openvswitch.ko

          insmod datapath/linux/brcompat.ko  ( Note: if you want to use brctl command, need first insmod brcompatd.ko, then run ovs-brcompatd --detach --pidfile )

          If you do not remove the Linux bridge module you will get ths follwoing error.
          [root@openstack openvswitch-1.7.1]# insmod datapath/linux/openvswitch.ko
          insmod: error inserting 'datapath/linux/openvswitch.ko': -1 Invalid module format
      [root@openstack openvswitch-1.7.1]# dmesg |tail
      openvswitch: exports duplicate symbol ovs_dp_ioctl_hook (owned by openvswitch_mod)

        6) Init OVS DB configuration, only one time
           touch /usr/local/etc/ovs-vswitchd.conf
           mkdir -p /usr/local/etc/openvswitch
           ovsdb-tool create /usr/local/etc/openvswitch/conf.db vswitchd/vswitch.ovsschema

        7) start OVS DB
           ovsdb-server /usr/local/etc/openvswitch/conf.db --remote=punix:/usr/local/var/run/openvswitch/db.sock --remote=db:Open_vSwitch,manager_options --private-key=db:SSL,private_key --certificate=db:SSL,certificate --bootstrap-ca-cert=db:SSL,ca_cert --pidfile
--detach --log-file

        8) Init OVS DB data
           ovs-vsctl --no-wait init
       
        9) Start vSwitch daemon
           ovs-vswitchd --pidfile --detach
           ovs-vsctl show

        10) Configure the Open vSwitch Bridge and Network
            ovs agent need a bridge "br-int",
            In addtion, l3 agent need a bridge "br-ex" that will be used to uplink this node running quantum-l3-agent to the external network.
            ovs-vsctl add-br br-int
            ovs-vsctl add-br br-ex
            sudo ifconfig eth1 0
            sudo ovs-vsctl add-port br-ex eth1

            sudo ifconfig br-ex 192.168.100.122 netmask 255.255.255.0  / ip addr add 192.168.100.122/24 dev br-ex
            route add default gw 192.168.100.1 br-ex
            or vi /etc/sysconfig/network-scripts/ifcfg-br-ex
                DEVICE="br-ex"
        NM_CONTROLLED="no"
        ONBOOT="yes"
        TYPE="Ethernet"
        BOOTPROTO=static
        IPADDR=192.168.100.122
        GATEWAY=192.168.100.1
        NETMASK=255.255.255.0

        DNS1=9.0.148.50

        Bellow is a example to use two kvm VMs to set up two openvswitch testing env:

node1:
br-ex  -->  eth0   192.168.100.108
eth1               172.16.100.108
br-int

node2:
eth0               172.16.100.109
br-int

1)  first create two virtual switch in kvm ( Note: must without dhcp )
          default, Forwording to physical device by NAT mode,   192.168.100.0/24  
          vSwitch1, Isolated virtual network,  172.16.100.0/24

2) node1:
        [root@node1 ~]# cat /etc/sysconfig/network-scripts/ifcfg-br-ex
        DEVICE=br-ex
        NM_CONTROLLED=no
        ONBOOT=yes
        DEVICETYPE=ovs
        TYPE=OVSBridge
        BOOTPROTO=static
        IPADDR=192.168.100.108
        GATEWAY=192.168.100.1
        BROADCAST=192.168.100.255
        NETMASK=255.255.255.0
        DNS1=9.0.148.50
        IPV6INIT=no
        [root@node1 ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
        DEVICE=eth0
        #HWADDR=52:54:00:8C:04:42
        NM_CONTROLLED=no
        ONBOOT=yes
        DEVICETYPE=ovs
        TYPE=OVSPort
        IPV6INIT=no
        OVS_BRIDGE=br-ex
        [root@node1 ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth1
        DEVICE=eth1
        NM_CONTROLLED=no
        ONBOOT=yes
        #DEVICETYPE=eth
        TYPE=Ethernet
        BOOTPROTO=static
        IPADDR=172.16.100.108
        #GATEWAY=172.16.100.108
        BROADCAST=172.16.100.255
        NETMASK=255.255.255.0
        IPV6INIT=no
        [root@node1 ~]# cat /etc/sysconfig/network
        HOSTNAME=node1
        [root@node1 ~]# cat /etc/hosts
        192.168.100.108  pubnode
        172.16.100.108   node1
        172.16.100.109   node2
        [root@node1 ~]# sysctl -w net.ipv4.ip_forward=1
        [root@node1 ~]# route add -net 172.16.100.0 netmask 255.255.255.0 dev eth1
        [root@node1 ~]# route add -net 192.168.100.0 netmask 255.255.255.0 gw 192.168.100.1 dev br-ex
        [root@node1 ~]# iptables -t nat -A POSTROUTING --out-interface br-ex -j MASQUERADE
        [root@node1 ~]# sudo ovs-vsctl add-br br-int

    

        As for ovs bridge creatation, it equals following scripts:

        sudo ovs-vsctl add-br br-int
        ifconfig eth1 down
        sudo ovs-vsctl add-br br-ex
        ip addr flush eth1
        ifconfig eth1 down
        sudo ovs-vsctl add-port br-ex eth1
        ifconfig eth1 promisc up
        ifconfig br-ex 192.168.100.122 netmask 255.255.255.0 broadcast 192.168.100.255
        route add default gw 192.168.100.1 br-ex
        ip addr add 172.16.100.122/24 brd 172.16.100.255 dev br-ex
        echo 'nameserver 9.0.148.50' > /etc/resolv.conf

3) node2:
        [root@node2 ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
        DEVICE=eth0
        NM_CONTROLLED=no
        ONBOOT=yes
        TYPE=Ethernet
        BOOTPROTO=static
        IPADDR=172.16.100.109
        GATEWAY=172.16.100.108
        BROADCAST=172.16.100.255
        NETMASK=255.255.255.0
        DNS1=9.0.148.50
        IPV6INIT=no
        [root@node2 ~]# cat /etc/hosts
        192.168.100.108  pubnode
        172.16.100.108   node1
        172.16.100.109   node2
        [root@node2 ~]# route add default gw 172.16.100.108
        [root@node2 ~]# sudo ovs-vsctl add-br br-int

finnaly, in a work, give a script to automatic install ovs

  1. wget http://openvswitch.org/releases/openvswitch-1.7.1.tar.gz
  2. tar xf openvswitch-1.7.1.tar.gz
  3. cd openvswitch-1.7.1
  4. sed -i '241,246d' datapath/linux/compat/include/linux/skbuff.h
  5. ./configure --prefix=/usr --exec-prefix=/usr --datarootdir=/usr/share --with-linux=/usr/src/kernels/$(uname -r) --enable-ssl
  6. make && make install
  7. make -C /usr/src/kernels/$(uname -r) M=/opt/openvswitch-1.7.1/datapath/linux modules_install
  8. cd rhel/
  9. cp etc_sysconfig_network-scripts_ifdown-ovs /etc/sysconfig/network-scripts/ifdown-ovs
  10. cp etc_sysconfig_network-scripts_ifup-ovs /etc/sysconfig/network-scripts/ifup-ovs
  11. cp etc_init.d_openvswitch /etc/init.d/openvswitch
  12. cp usr_share_openvswitch_scripts_sysconfig.template /etc/sysconfig/openvswitch
  13. sed -i 's/# BRCOMPAT=yes/BRCOMPAT=yes/g' /etc/sysconfig/openvswitch
  14. #删除default.xml为了防止bridge和openvswitch模块冲突
  15. rm -rf /etc/libvirt/qemu/networks/autostart/default.xml
  16. ifconfig virbr0 down
  17. rmmod bridge

抱歉!评论已关闭.