Install Openvswitch by rpm binary and source code way on rhe6.3 ( by 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
insmod datapath/linux/brcompat.ko ( Note: if you want to use brctl command, need first insmod brcompatd.ko, then run ovs-brcompatd --detach --pidfile )
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