Install OpenVSwitch into CentOS 7 userspace
背景
之前写过一篇较详细的CentOS 6下安装openvswitch的文章.
http://blog.163.com/digoal@126/blog/static/16387704020147111358858/
这里简单的介绍一下在centos 7下的安装, 其实差不多. 只是目前openvswitch没有针对CentOS7或rhel7的spec中, 只能生成userspace 安装包, 不能生成kmod包.
使用Docker加OpenVSwitch可以很方便的模拟一些应用场景, OpenVswitch相比bridge多了很多交换机的功能, 例如VLAN, GRE等等.
安装步骤
环境 :
CentOS 7
未开启selinux.
下载源码包
http://openvswitch.org/download/
当前版本 :
http://openvswitch.org/releases/openvswitch-2.3.0.tar.gz
安装详情请参考源码包中的INSTALL.RHEL
1. 安装依赖包
[root@localhost openvswitch-2.3.0]# uname -r
3.10.0-123.el7.x86_64
yum install -y gcc make python-devel openssl-devel graphviz \
autoconf automake rpm-build redhat-rpm-config \
libtool \
kernel-devel-3.10.0-123.el7.x86_64 kernel-debug-devel-3.10.0-123.el7.x86_64
2. 修复内核BUG. version为内核版本.
cd /lib/modules/<version>
应该看到这个链接, 否则是内核BUG, 需要修复 :
lrwxrwxrwx. 1 root root 38 Nov 26 18:15 build -> /usr/src/kernels/3.10.0-123.el7.x86_64
如果没有这个软链接, 那么需要修复如下 :
cd /lib/modules/<version>
rm build
ln -s /usr/src/kernels/<target> build
3. 创建rpmbuild源码目录
mkdir -p /root/rpmbuild/SOURCES
4. 安装
[root@localhost soft_bak]# cp openvswitch-2.3.0.tar.gz /root/rpmbuild/SOURCES/
[root@localhost soft_bak]# cd openvswitch-2.3.0
生成userspace rpm, 因为依赖kmod包, 但是kmod包又无法生成, 所以必须修改一下spec.
[root@localhost openvswitch-2.3.0]# sed 's/openvswitch-kmod, //g' rhel/openvswitch.spec >rhel/openvswitch_no_kmod.spec
[root@localhost openvswitch-2.3.0]# rpmbuild -bb --without check rhel/openvswitch_no_kmod.spec
[root@localhost x86_64]# ll /root/rpmbuild/RPMS/x86_64
total 9488
-rw-r--r-- 1 root root 2010312 Dec 6 19:06 openvswitch-2.3.0-1.x86_64.rpm
-rw-r--r-- 1 root root 7702836 Dec 6 19:06 openvswitch-debuginfo-2.3.0-1.x86_64.rpm
生成kernel module rpm, 失败.(有异常)
[root@localhost openvswitch-2.3.0]# cp rhel/openvswitch-kmod.files /root/rpmbuild/SOURCES/
[root@localhost openvswitch-2.3.0]# uname -r
3.10.0-123.el7.x86_64
[root@localhost openvswitch-2.3.0]# rpmbuild -bb \
-D "kversion 3.10.0-123.el7.x86_64" \
-D "kflavors default debug kdump" \ # 需删除debug, kdump内核选项才能编译, 但是照样编译错误
rhel/openvswitch-kmod-rhel6.spec
报错比较多
In file included from /root/rpmbuild/BUILD/openvswitch-2.3.0/_default/../datapath/linux/compat/include/net/gre.h:10:0,
from /root/rpmbuild/BUILD/openvswitch-2.3.0/_default/datapath/linux/vport-gre.c:44:
include/net/gre.h: In function 'gre_handle_offloads':
include/net/gre.h:42:2: error: implicit declaration of function 'iptunnel_handle_offloads' [-Werror=implicit-function-declaration]
return iptunnel_handle_offloads(skb, gre_csum, SKB_GSO_GRE);
^
include/net/gre.h:42:2: warning: return makes pointer from integer without a cast [enabled by default]
cc1: some warnings being treated as errors
make[2]: *** [/root/rpmbuild/BUILD/openvswitch-2.3.0/_default/datapath/linux/vport.o] Error 1
make[2]: *** [/root/rpmbuild/BUILD/openvswitch-2.3.0/_default/datapath/linux/vport-gre.o] Error 1
make[2]: *** [/root/rpmbuild/BUILD/openvswitch-2.3.0/_default/datapath/linux/datapath.o] Error 1
make[1]: *** [_module_/root/rpmbuild/BUILD/openvswitch-2.3.0/_default/datapath/linux] Error 2
make[1]: Leaving directory `/usr/src/kernels/3.10.0-123.el7.x86_64'
make: *** [default] Error 2
make: Leaving directory `/root/rpmbuild/BUILD/openvswitch-2.3.0/_default/datapath/linux'
error: Bad exit status from /var/tmp/rpm-tmp.gf6noy (%build)
安装userspace rpm
[root@localhost x86_64]# rpm -ivh openvswitch-2.3.0-1.x86_64.rpm
Preparing... ################################# [100%]
Updating / installing...
1:openvswitch-2.3.0-1 ################################# [100%]
[root@localhost x86_64]# chkconfig --list openvswitch
Note: This output shows SysV services only and does not include native
systemd services. SysV configuration data might be overridden by native
systemd configuration.
If you want to list systemd services use 'systemctl list-unit-files'.
To see services enabled on particular target use
'systemctl list-dependencies [target]'.
openvswitch 0:off 1:off 2:on 3:on 4:on 5:on 6:off
[root@localhost x86_64]# service openvswitch status
ovsdb-server is not running
ovs-vswitchd is not running
[root@localhost x86_64]# service openvswitch start
Starting openvswitch (via systemctl): [ OK ]
[root@localhost x86_64]# ovs-vsctl show
f345b7e3-fcb0-4ef3-8295-36d3ef69ceef
ovs_version: "2.3.0"
参考
1. http://blog.163.com/digoal@126/blog/static/16387704020147111358858/
2.
openvswitch-2.3.0
-rw-rw-r-- 1 ceph ceph 22691 Aug 15 04:34 INSTALL
-rw-rw-r-- 1 ceph ceph 3162 Aug 15 04:33 INSTALL.Debian
-rw-rw-r-- 1 ceph ceph 3200 Aug 15 04:34 INSTALL.DPDK
-rw-rw-r-- 1 ceph ceph 1862 Aug 15 04:34 INSTALL.Fedora
-rw-rw-r-- 1 ceph ceph 2584 Aug 15 04:17 INSTALL.KVM
-rw-rw-r-- 1 ceph ceph 2273 Oct 19 2013 INSTALL.Libvirt
-rw-rw-r-- 1 ceph ceph 1106 Aug 15 04:34 INSTALL.NetBSD
-rw-rw-r-- 1 ceph ceph 4886 Aug 15 04:34 INSTALL.RHEL
-rw-rw-r-- 1 ceph ceph 12806 Aug 15 04:28 INSTALL.SSL
-rw-rw-r-- 1 ceph ceph 3101 Jul 14 18:28 INSTALL.userspace
-rw-rw-r-- 1 ceph ceph 7926 Aug 15 04:34 INSTALL.XenServer