0%

Ubuntu16.04安装Open vSwitch

环境准备

  • 获取安装包
1
git clone https://github.com/openvswitch/ovs.git
  • 安装必要的依赖
1
apt install autoconf libtool make libssl-dev libcap-ng-dev

安装

  • 当使用源代码时,需要自己创建configure脚本
1
$ ./boot.sh
  • 配置并开启内核模块
1
$ ./configure --prefix=/usr --localstatedir=/var --sysconfdir=/etc --with-linux=/lib/modules/$(uname -r)/build
  • 安装
1
2
$ make
$ make install
  • 安装内核模块

该步骤可能会报错,请参看后文

1
$ make modules_install

官方安装文档中提到,你有可能之前已经安装了ovs的模块,为了确保使用的是你刚才编译的,则需要在/etc/depmod.d/中添加如下内容

1
2
3
4
5
6
7
$ config_file="/etc/depmod.d/openvswitch.conf"
$ for module in datapath/linux/*.ko; do
modname="$(basename ${module})"
echo "override ${modname%.ko} * extra" >> "$config_file"
echo "override ${modname%.ko} * weak-updates" >> "$config_file"
done
$ depmod -a
  • 加载内核模块
1
$ /sbin/modprobe openvswitch
  • 验证
1
2
3
4
5
6
7
8
9
$ /sbin/lsmod | grep openvswitch
openvswitch 303104 0
tunnel6 16384 1 openvswitch
nf_nat_ipv6 16384 1 openvswitch
nf_defrag_ipv6 36864 2 openvswitch,nf_conntrack_ipv6
nf_nat_ipv4 16384 2 openvswitch,iptable_nat
nf_nat 28672 6 nf_nat_redirect,openvswitch,nf_nat_ipv4,nf_nat_ipv6,xt_nat,nf_nat_masquerade_ipv4
nf_conntrack 106496 11 xt_CT,openvswitch,nf_nat,nf_nat_ipv4,nf_nat_ipv6,xt_conntrack,nf_nat_masquerade_ipv4,nf_conntrack_netlink,xt_connmark,nf_conntrack_ipv4,nf_conntrack_ipv6
libcrc32c 16384 2 raid456,openvswitch

启动服务

官方说明中提到有一个ovs-ctl的命令,然而,我安装完之后并没有这个命令。可能官方文档比较老了吧。

创建必要的目录

1
2
3
$ mkdir -p /etc/openvswitch
$ mkdir -p /var/log/openvswitch
$ mkdir -p /var/run/openvswitch

配置ovsdb-server

  • 从源文件目录创建conf.db
1
2
ovs$ ovsdb-tool create /etc/openvswitch/conf.db \
vswitchd/vswitch.ovsschema
  • 配置
1
2
3
4
5
6
ovsdb-server --remote=punix:/var/run/openvswitch/db.sock \
--remote=db:Open_vSwitch,Open_vSwitch,manager_options \
--private-key=db:Open_vSwitch,SSL,private_key \
--certificate=db:Open_vSwitch,SSL,certificate \
--bootstrap-ca-cert=db:Open_vSwitch,SSL,ca_cert \
--pidfile --detach --log-file
  • 初始化数据库
1
ovs-vsctl --no-wait init

启动ovs进程

1
ovs-vswitchd --pidfile --detach --log-file

验证

  • 创建bridge
1
$ ovs-vsctl add-br br0
  • 为br0添加接口
1
$ ovs-vsctl add-port br0 eth1
  • 查看配置
1
$ ovs-vsctl show

问题及解决

安装内核模块时出现如下错误,忽略即可(我还以为很严重,搜了一阵,发现不用管)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
$ make modules_install
cd datapath/linux && make modules_install
make[1]: Entering directory '/root/ovs/datapath/linux'
make -C /lib/modules/4.4.0-127-generic/build M=/root/ovs/datapath/linux modules_install
make[2]: Entering directory '/usr/src/linux-headers-4.4.0-127-generic'
INSTALL /root/ovs/datapath/linux/openvswitch.ko
At main.c:222:
- SSL error:02001002:system library:fopen:No such file or directory: bss_file.c:175
- SSL error:2006D080:BIO routines:BIO_new_file:no such file: bss_file.c:178
sign-file: certs/signing_key.pem: No such file or directory
INSTALL /root/ovs/datapath/linux/vport-geneve.ko
At main.c:222:
- SSL error:02001002:system library:fopen:No such file or directory: bss_file.c:175
- SSL error:2006D080:BIO routines:BIO_new_file:no such file: bss_file.c:178
sign-file: certs/signing_key.pem: No such file or directory
INSTALL /root/ovs/datapath/linux/vport-gre.ko
At main.c:222:
- SSL error:02001002:system library:fopen:No such file or directory: bss_file.c:175
- SSL error:2006D080:BIO routines:BIO_new_file:no such file: bss_file.c:178
sign-file: certs/signing_key.pem: No such file or directory
INSTALL /root/ovs/datapath/linux/vport-lisp.ko
At main.c:222:
- SSL error:02001002:system library:fopen:No such file or directory: bss_file.c:175
- SSL error:2006D080:BIO routines:BIO_new_file:no such file: bss_file.c:178
sign-file: certs/signing_key.pem: No such file or directory
INSTALL /root/ovs/datapath/linux/vport-stt.ko
At main.c:222:
- SSL error:02001002:system library:fopen:No such file or directory: bss_file.c:175
- SSL error:2006D080:BIO routines:BIO_new_file:no such file: bss_file.c:178
sign-file: certs/signing_key.pem: No such file or directory
INSTALL /root/ovs/datapath/linux/vport-vxlan.ko
At main.c:222:
- SSL error:02001002:system library:fopen:No such file or directory: bss_file.c:175
- SSL error:2006D080:BIO routines:BIO_new_file:no such file: bss_file.c:178
sign-file: certs/signing_key.pem: No such file or directory
DEPMOD 4.4.0-127-generic
make[2]: Leaving directory '/usr/src/linux-headers-4.4.0-127-generic'
depmod `sed -n 's/#define UTS_RELEASE "\([^"]*\)"/\1/p' /lib/modules/4.4.0-127-generic/build/include/generated/utsrelease.h`
make[1]: Leaving directory '/root/ovs/datapath/linux'