binary and source way on rhe6.3 ( by quqi99 )"/>
Install Openvswitch by binary and source way on rhe6.3 ( by quqi99 )
Install Openvswitch by rpm binary and source code way on rhe6.3 ( by quqi99 )
作者:张华 发表于:2012-12-30
版权声明:可以任意转载,转载时请务必以超链接形式标明文章原始出处和作者信息及本版权声明
( )
1 Install openvswitch by rpm binary way
cat /etc/yum.repos.d/base.repo
[rhel]
name=rhel
baseurl=/
enabled=1
gpgcheck=0
[centos]
name=centos
baseurl=
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 .4.2-1.el6.x86_64.rpm
rpm -ivh .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 .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
- wget .7.1.tar.gz
- tar xf openvswitch-1.7.1.tar.gz
- cd openvswitch-1.7.1
- sed -i '241,246d' datapath/linux/compat/include/linux/skbuff.h
- ./configure --prefix=/usr --exec-prefix=/usr --datarootdir=/usr/share --with-linux=/usr/src/kernels/$(uname -r) --enable-ssl
- make && make install
- make -C /usr/src/kernels/$(uname -r) M=/opt/openvswitch-1.7.1/datapath/linux modules_install
- cd rhel/
- cp etc_sysconfig_network-scripts_ifdown-ovs /etc/sysconfig/network-scripts/ifdown-ovs
- cp etc_sysconfig_network-scripts_ifup-ovs /etc/sysconfig/network-scripts/ifup-ovs
- cp etc_init.d_openvswitch /etc/init.d/openvswitch
- cp usr_share_openvswitch_scripts_sysconfig.template /etc/sysconfig/openvswitch
- sed -i 's/# BRCOMPAT=yes/BRCOMPAT=yes/g' /etc/sysconfig/openvswitch
- #删除default.xml为了防止bridge和openvswitch模块冲突
- rm -rf /etc/libvirt/qemu/networks/autostart/default.xml
- ifconfig virbr0 down
- rmmod bridge
20140409添加, 在rhel6.4上源码安装openvswitch 2.1 RPM Repository:
/
1) upgrade autoconf from 2.63 to 2.64
yum remove automake
wget .64.tar.gz
tar xzf autoconf-2.64.tar.gz && cd autoconf-2.64
./configure --prefix=/usr && make && make install
2) yum install automake libtool
3) prepare for kernel-headers
yum install compat-glibc compat-glibc-headers gcc gcc-c++ glibc-devel glibc-headers libnetfilter_conntrack-devel libnfnetlink-devel libtool
rpm ivh .5/os/x86_64/Packages/ kernel-headers-2.6.32-431.el6.x86_64.rpm
rpm ivh / kernel-devel-2.6.32-431.el6.x86_64.rpm
ln -s /usr/src/kernels/2.6.32-431.el6.x86_64/ /lib/modules/2.6.32-431.el6.x86_64/build
wget .1.0.tar.gz
tar -xf openvswitch-2.1.0 && cd openvswitch-2.1.0
./boot.sh
./configure --with-linux=/lib/modules/`uname -r`/build - -prefix=/usr
make -j && sudo make install
修改文件./datapath/linux/Makefile.main.in和./datapath/linux/Makefile.main, 将路径generated/linux/utsrelease.h改成include/linux/utsrelease.h
make -C /usr/src/kernels/$(uname -r) M=./datapath/linux modules_install
cp rhel/etc_sysconfig_network-scripts_ifdown-ovs /etc/sysconfig/network-scripts/ifdown-ovs
cp rhel/etc_sysconfig_network-scripts_ifup-ovs /etc/sysconfig/network-scripts/ifup-ovs
cp rhel/etc_init.d_openvswitch /etc/init.d/openvswitch
cp rhel/usr_share_openvswitch_scripts_sysconfig.template /etc/sysconfig/openvswitch
sed -i 's/# BRCOMPAT=yes/BRCOMPAT=yes/g' /etc/sysconfig/openvswitch
#删除default.xml为了防止bridge和openvswitch模块冲突
rm -rf /etc/libvirt/qemu/networks/autostart/default.xml
ifconfig virbr0 down
rmmod bridge
modprobe openvswitch
modprobe libcrc32c
更多推荐
Install Openvswitch by binary and source way on rhe6.3 ( by quqi99 )
发布评论