How To : Install Open vSwitch in CentOS 7

  Virtualization

Open vSwitch is a multilayer virtual switch that been used for our KVM – QEMU server. Mostly of our Shared Hosting been setup with this technology.

Install dependencies required by Open vSwitch


[root@localhost ~]# yum install wget openssl-devel gcc make python-devel openssl-devel kernel-devel graphviz kernel-debug-devel autoconf automake rpm-build redhat-rpm-config libtool python-twisted-core python-zope-interface PyQt4 desktop-file-utils libcap-ng-devel groff checkpolicy selinux-policy-devel -y

Build the rpm of Open vSwitch.


[root@localhost ~]# adduser ovs
[root@localhost ~]# su - ovs

[ovs@localhost ~]$ mkdir -p ~/rpmbuild/SOURCES
[ovs@localhost ~]$ wget http://openvswitch.org/releases/openvswitch-2.5.4.tar.gz
[ovs@localhost ~]$ cp openvswitch-2.5.4.tar.gz ~/rpmbuild/SOURCES/
[ovs@localhost ~]$ tar xfz openvswitch-2.5.4.tar.gz
[ovs@localhost ~]$ rpmbuild -bb --nocheck /home/ovs/openvswitch-2.5.4/rhel/openvswitch-fedora.spec
[ovs@localhost ~]$ exit

Installation of Open vSwitch


[root@localhost ~]# yum localinstall -y /home/ovs/rpmbuild/RPMS/x86_64/openvswitch-2.5.4.el7.centos.x86_64.rpm
[root@localhost ~]# systemctl start openvswitch
[root@localhost ~]# systemctl enable openvswitch

Run the following command to verify Open vSwitch running or check on the version installed.


[root@localhost ~]# ovs-vsctl --version
ovs-vsctl (Open vSwitch) 2.5.4
Compiled Oct 3 2017 16:58:41
DB Schema 7.12.1

Or, you can verify Open vSwitch running with following command


9ab88687-2559-474b-880c-56ed8af65f87
ovs_version: "2.5.4"

We will set the eth0 (WAN) as a router, all WAN connection from VM will be going out thru this eth0. Please login to the server via IPMI console, because SSH session will be disconnected.


[root@localhost ~]# ovs-vsctl add-br vmbr0
[root@localhost ~]# ovs-vsctl add-port vmbr0 eth0
[root@localhost ~]# ifconfig eth0 0
[root@localhost ~]# ifconfig vmbr0 183.81.162.122 netmask 255.255.255.192 up
[root@localhost ~]# route add default gw 183.81.162.97

With ifconfig , there’s no IP address showed in the eth0, the server IP address will be tagged to vmbr0


[root@INQA09 ~]# ifconfig
eth0: flags=4163 mtu 1500
inet6 fe80::969c:25e5:3f21:c736 prefixlen 64 scopeid 0x20 ether 2c:60:0c:d0:5d:29 txqueuelen 1000 (Ethernet)
RX packets 20530733 bytes 30259565663 (28.1 GiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 2951 bytes 342820 (334.7 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
device memory 0xc7920000-c793ffff

lo: flags=73 mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10
loop txqueuelen 1 (Local Loopback)
RX packets 42 bytes 4098 (4.0 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 42 bytes 4098 (4.0 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

vmbr0: flags=4163 mtu 1500
inet 183.81.162.122 netmask 255.255.255.192 broadcast 183.81.162.127
inet6 fe80::2e60:cff:fed0:5d29 prefixlen 64 scopeid 0x20 ether 2c:60:0c:d0:5d:29 txqueuelen 1000 (Ethernet)
RX packets 2324938 bytes 29243612422 (27.2 GiB)
RX errors 0 dropped 1586 overruns 0 frame 0
TX packets 2898 bytes 341582 (333.5 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0