CentOS 7 – Installing Openvswitch 2.3.1 LTS

Openvswitch 2.3.1 was released on December 2014 and this post explains how to quickly generate an RPM to install Openvswitch command-line tools. I’ll be using the Openvswitch’s kernel module that comes with CentOS kernel so no kernel module is compiled.

As the root user let’s install some packages and add a new user:

yum -y install wget openssl-devel gcc make python-devel openssl-devel kernel-devel graphviz kernel-debug-devel autoconf automake rpm-build redhat-rpm-config libtool

adduser ovs

su - ovs

Now as the ovs user we’ll generate the rpm file. In this post I’m skipping the rpmbuild tests included with openvswitch as I’m solving some dependency problems.

mkdir -p ~/rpmbuild/SOURCES

wget http://openvswitch.org/releases/openvswitch-2.3.1.tar.gz

cp openvswitch-2.3.1.tar.gz ~/rpmbuild/SOURCES/

tar xfz openvswitch-2.3.1.tar.gz

sed 's/openvswitch-kmod, //g' openvswitch-2.3.1/rhel/openvswitch.spec > openvswitch-2.3.1/rhel/openvswitch_no_kmod.spec

rpmbuild -bb --nocheck ~/openvswitch-2.3.1/rhel/openvswitch_no_kmod.spec

exit

Finally we install the rpm package:

 yum localinstall /home/ovs/rpmbuild/RPMS/x86_64/openvswitch-2.3.1-1.x86_64.rpm

Let’s check that the command-line tools are ready:

ovs-vsctl -V
ovs-vsctl (Open vSwitch) 2.3.1
Compiled Jan 25 2015 02:13:00
DB Schema 7.6.2

UPDATE: If you’re using SELinux in enfocing mode, if you try to start the service (systemctl start openvswitch.service) you’ll find some errors: install: cannot change owner and permissions of ‘/etc/openvswitch’: No such file or directory andCreating empty database /etc/openvswitch/conf.db ovsdb-tool: I/O error: /etc/openvswitch/conf.db: failed to lock lockfile (No such file or directory). This is how I solved them (the commands are executed as root):

yum install policycoreutils-python
mkdir /etc/openvswitch
semanage fcontext -a -t openvswitch_rw_t "/etc/openvswitch(/.*)?"
restorecon -Rv /etc/openvswitch

UPDATE: If you run the ovs-vsctl show command and you receive the following error, please check that your openvswitch service has been started (use systemctl start openvswitch.service)

  • ovs-vsctl: unix:/var/run/openvswitch/db.sock: database connection failed (No such file or directory)

Done!

22 thoughts on “CentOS 7 – Installing Openvswitch 2.3.1 LTS

  1. Simon Beaulieu says:

    Hi,

    I’m using CentOS 7 ( mininal install ).

    I reproduced the steps up above and everything worked fine, except one little detail. It seems that the OVSDB server is not initialised and that the database is not created, even though the openvswitch.service seems to start well and the status is “active (running)”.

    The following lines show at the bottom after the execution of “sudo statut openvswitch.service”

    “Jan 26 13:47:42 openvswitch.openflow openvswitch[29845]: /etc/openvswitch/conf.db does not exist … (warning).
    Jan 26 13:47:42 openvswitch.openflow openvswitch[29845]: install: cannot change owner and permissions of ‘/etc/openvswitch’: No such file or directory
    Jan 26 13:47:42 openvswitch.openflow openvswitch[29845]: Creating empty database /etc/openvswitch/conf.db ovsdb-tool: I/O error: /etc/openvswitch/conf.db: failed to lo…directory)
    Jan 26 13:47:42 openvswitch.openflow openvswitch[29845]: [FAILED]
    Jan 26 13:47:42 openvswitch.openflow openvswitch[29845]: ovs-vswitchd is already running.
    Jan 26 13:47:42 openvswitch.openflow openvswitch[29845]: Enabling remote OVSDB managers 2015-01-26T18:47:42Z|00001|daemon_unix|WARN|/var/run/openvswitch/ovsdb-server.p… directory
    Jan 26 13:47:42 openvswitch.openflow openvswitch[29845]: ovs-appctl: cannot read pidfile “/var/run/openvswitch/ovsdb-server.pid” (No such file or directory)
    Jan 26 13:47:42 openvswitch.openflow openvswitch[29845]: [FAILED]
    Jan 26 13:47:42 openvswitch.openflow systemd[1]: Started LSB: Open vSwitch switch.
    Jan 26 14:00:30 openvswitch.openflow systemd[1]: Started LSB: Open vSwitch switch.”

    Any ideas ? :/
    Thanks a lot for your blog by the way, it’s very helpful !

    Like

    • n40lab says:

      Hi Simon,
      thanks for your kind words. I’m sorry but I forgot to add some lines about SELinux in the post that were included in my old post. Please re-read the updated post and let me know if you still have problems.

      Cheers!

      Like

      • Simon Beaulieu says:

        Hi,

        Thank you for your response ! I came to the same conclusion 2 minutes after writing my comment because I read your older post. It didn’t work but I will retry those steps with a clean install of CentOS. I already compiled and installed OpenVSwitch from scratch before and I think I didn’t remove it properly.

        I’ll let you know how it goes !
        Thanks again,

        Like

      • n40lab says:

        Ok! If you need help I have my virtual machine ready to start some tests and improve the post with your feedback.

        Like

      • Simon Beaulieu says:

        Hi !

        I re-did all the steps with a clean install of CentOS ( minimal install ).

        Small exception, I did not create the ovs user.
        For the rest I pretty much copied & pasted all your commands.
        I did the steps with semanage as well, using root.

        I absolutely have to start my openvswitch.service as root though.
        Using sudo with a regular user is ineffective.

        Anyways, everything is up and running now !
        Thanks a lot ! 🙂

        Like

    • n40lab says:

      Hi Salvatore!,
      the Linux/CentOS Kernel already provides from 6.4+ version an openvswitch kernel module, however CentOS is not providing (as far as I know) a package containing the tools you need to manage an openvswitch configuration (ovsdb, ovs-vsctl…) so this post explains how to create an RPM package, using Nicira specs, to get those utilities and use them with the old kernel module support.

      Of course that’s not the best and complete solution as you’re using new tools with an older module but it has always worked for me and for others as far as I know.

      Obviously you can try to compile the upstream with make, gcc, autoconf… In my case I wanted to rpmbuild the kernel module but CentOS kernel uses backports so it’s a little tricky to build as many compiling error arises about kernel functions being redefined an other stuff, but I’m no expert on building RPMs so I’m sure that with patience and time it can be done.

      Thanks for reading and for your feedback!

      Like

  2. Morgan Yang says:

    I have a question in regard to the centOS ovs kernel module, do I have to do reconfigure the kernel to enable that?

    Like

    • n40lab says:

      No you don’t have to reconfigure the kernel. CentOS already provides a kernel module so if you create an install the openvswitch package you’ll have the tools and services to use the kernel module. Cheers!

      Like

  3. BillScott says:

    Still getting the db error…
    ovs-vsctl: unix:/var/run/openvswitch/db.sock: database connection failed (No such file or directory)

    Any suggestions on how to correct?
    I even tried to use 2.3.2 and I got the same thing…

    Like

    • n40lab says:

      Sorry, I forgot to add that before using ovs-vsctl the openvswitch service must be started. Use systemctl start openvswitch and re-run the commando ovs-vsctl show. I’ve added that part to the post and I’ve created a new post for Openvswitch 2.3.2 LTS. Thanks for your feedback it’s really useful for keeping my posts updated.

      Cheers!

      Like

  4. CS Liu says:

    I have been searching for the doc for the openvswitch installation, but had little luck until I read your blog. This is the most complete with the clear detailed documentation for installing the openvswitch service.
    I just got my centOS7’s host installed with the openvswitch and vhost within an hour. Excellent doc and info sharing! Thanks a lot!

    Like

    • n40lab says:

      Thanks for your kind words, it means a lot to me. I love to hear that my notes are helpful, so please don’t hesitate to send me any doubt or suggestion to improve this info.

      Cheers!

      Like

Leave a comment