Get your server issues fixed by our experts for a price starting at just 25 USD/Hour. Click here to register and open a ticket with us now!

Author Topic: Install and use Open vSwitch 2.9 with KVM on CentOS 7 / RHEL 7 Server  (Read 1987 times)

0 Members and 1 Guest are viewing this topic.

akhilt

  • Guest
Install and use Open vSwitch 2.9 with KVM on CentOS 7 / RHEL 7 Server


Open vSwitch is a free and open source multi-layer software switch, which is used to manage the traffic between virtual machines and physical or logical networks.  It provides the features like traffic isolation in OpenStack tenants using the overlay techniques likes GRE, VXLAN and 802.1Q VLANs.

Using open vSwitch packet forwarding engine in kernel space or user space can be implemented and Link aggregation can also be accomplished through LACP.

Here we will discuss how to install latest version of Open vSwitch 2.9.2 on CentOS 7 and RHEL 7 Server. Apart from this we will see how open vSwitch can be used in KVM virtual machines for their networking.


Step 1) Install the required packages using yum command

Login to your CentOS 7 or RHEL 7 server as root and run the beneath yum command:
Code: [Select]
# yum install wget openssl-devel  python-sphinx 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

Step 2) Create ovs user and download Open vSwitch 2.9

Create a user with name ovs using below command

Code: [Select]
# useradd ovs
# su - ovs

Download OVS 2.9 tar file and build the openvswitch rpm using beneath commands,
Code: [Select]
$ mkdir -p ~/rpmbuild/S$ wget http://openvswitch.org/releases/openvswitch-2.9.2.tar.gzOURCES
$ cp openvswitch-2.9.2.tar.gz ~/rpmbuild/SOURCES/
$ tar xfz openvswitch-2.9.2.tar.gz
$ rpmbuild -bb --nocheck openvswitch-2.9.2/rhel/openvswitch-fedora.spec
$ exit
logout
#

Now install Open vSwitch rpm using below yum command:
Code: [Select]
# yum localinstall /home/ovs/rpmbuild/RPMS/x86_64/openvswitch-2.9.2-1.el7.x86_64.rpm -y

Step 3) Start and enable Open vSwitch Service

Use below systemctl commands to start and enable open vSwitch service
Code: [Select]
# systemctl start openvswitch.service
# systemctl enable openvswitch.service
Created symlink from /etc/systemd/system/multi-user.target.wants/openvswitch.service to /usr/lib/systemd/system/openvswitch.service.
# systemctl status openvswitch.service
● openvswitch.service - Open vSwitch
Loaded: loaded (/usr/lib/systemd/system/openvswitch.service; enabled; vendor preset: disabled)
Active: active (exited) since Sun 2018-08-05 10:16:12 EDT; 17s ago
Main PID: 73958 (code=exited, status=0/SUCCESS)
Aug 05 10:16:12 compute02 systemd[1]: Starting Open vSwitch...
Aug 05 10:16:12 compute02 systemd[1]: Started Open vSwitch.
#

Use below command to check the OVS version
Code: [Select]
# ovs-vsctl -V
ovs-vsctl (Open vSwitch) 2.9.2
DB Schema 7.15.1
#

Step:4 Create the OVS bridge and add interfaces to it.

Use the below command to create ovs bridge,
Code: [Select]
# ovs-vsctl add-br ovs-br0
Now flush or remove IP from the interface, in my case IP as was assigned to eno16777736
Code: [Select]
# ip addr flush dev eno16777736
Now assign this IP address to ovs bridge(ovs-br0)
Code: [Select]
# ip addr add 192.168.1.4/24 dev ovs-br0
Add interface as port in ovs-br0 using below command,
Code: [Select]
# ovs-vsctl add-port ovs-br0 eno16777736
Now bring up the bridge using below ‘ip link’ command,
Code: [Select]
# ip link set dev ovs-br0 up
Note : Above changes are not persistent, so make these changes persistent across the reboot, we have to create ovs bridge file, steps are shown below
Code: [Select]
# cd /etc/sysconfig/ne
# cd /etc/sysconfig/network-scripts/twork-scripts/
# cp ifcfg-eno16777736 ifcfg-ovs-br0
#
# vi ifcfg-eno16777736
DEVICE=eno16777736
HWADDR="00:0c:29:c1:c3:4e"
TYPE=OVSPort
DEVICETYPE=ovs
OVS_BRIDGE=ovs-br0
ONBOOT=yes

Save and exit the file

Code: [Select]
# vi ifcfg-ovs-br0
DEVICE=ovs-br0
DEVICETYPE=ovs
TYPE=OVSBridge
BOOTPROTO=static
IPADDR=192.168.1.4
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
ONBOOT=yes

Save & exit the file

Restart the network service using below command,

Code: [Select]
# systemctl restart network
Now Verify ovs bridge and its ports using “ovs-vsctl” command
Code: [Select]
# ovs-vsctl show
8dc5f8e7-0e54-4d9d-ba7a-cd6b9b94f470
    Bridge "ovs-br0"
        Port "ovs-br0"
            Interface "ovs-br0"
                type: internal
        Port "eno16777736"
            Interface "eno16777736"
    ovs_version: "2.9.2"
#

Step:5 ) Create and define virsh ovs network

Create ovs network file with the following contents ,
Code: [Select]
# vi /tmp/ovs-network.xml
<network>
<name>ovs-network</name>
<forward mode='bridge'/>
<bridge name='ovs-br0'/>
<virtualport type='openvswitch'/>
</network>

Now define the ovs-network using below virsh command,
Code: [Select]
# virsh net-define /tmp/ovs-network.xml
Network ovs-network defined from /tmp/ovs-network.xml
# virsh net-start ovs-network
Network ovs-network started
# virsh net-autostart ovs-network
Network ovs-network marked as autostarted
#

Now verify the virsh network using beneath command,
Code: [Select]
# virsh net-list
 Name                 State      Autostart     Persistent
----------------------------------------------------------
 default              active     yes           yes
 ovs-network          active     yes           yes
[root@compute02 ~]#

Step:6) Create Virtual machines and attach ovs-network

Let’s create two test VMs using below virt-install command, specify the network for these VMs as ovs-network,

Code: [Select]
# virt-install  -n testvm1  --description "Test VM1 for OVS "  --os-type=Linux  --os-variant=rhel7  --ram=1096  --vcpus=1  --disk path=/var/lib/libvirt/images/testvm1.img,bus=virtio,size=10  --network network:ovs-network --graphics none  --location /root/CentOS-7-x86_64-DVD-1511.iso --extra-args console=ttyS0
Similarly Create a second test vm with name “testvm2”

Code: [Select]
# virt-install  -n testvm2  --description "Test VM2 for OVS "  --os-type=Linux  --os-variant=rhel7  --ram=1096  --vcpus=1  --disk path=/var/lib/libvirt/images/testvm2.img,bus=virtio,size=10  --network network:ovs-network --graphics none  --location /root/CentOS-7-x86_64-DVD-1511.iso --extra-args console=ttyS0
Once the VMs are created then their interfaces should be added in ovs bridge (ov-br0) automatically and we can verify this from ovs-vsctl command,

Code: [Select]
# ovs-vsctl show
8dc5f8e7-0e54-4d9d-ba7a-cd6b9b94f470
    Bridge "ovs-br0"
        Port "ovs-br0"
            Interface "ovs-br0"
                type: internal
        Port "eno16777736"
            Interface "eno16777736"
        Port "vnet0"
            Interface "vnet0"
        Port "vnet1"
            Interface "vnet1"
    ovs_version: "2.9.2"
# ovs-vsctl list-ports ovs-br0
eno16777736
vnet0
vnet1
#

In the above command vnet0 & vnet1 are VMs tap interface. When we shutdown these VMS then these ports will be removed from OVS Bridge (ovs-br0) automatically. Log files for ovs (openvswitch) are kept under the folder “/var/log/openvswitch“.

This conclude this article, I hope you got an idea how to install and use Open vSwitch 2.9 with KVM on CentOS 7 and RHEL 7 Servers.

Thank You!!