1. 程式人生 > >Ubuntu 16.04 原始碼安裝 openVswitch 2.10.0

Ubuntu 16.04 原始碼安裝 openVswitch 2.10.0

環境

Ubuntu 16.04 核心版本 4.8.0-36-generic openVswitch 2.10.0

下載ovs程式碼

# wget http://openvswitch.org/releases/openvswitch-2.10.0.tar.gz
# tar -zxvf openvswitch-2.10.0.tar.gz

安裝必備的工具

# apt-get install automake autoconf gcc uml-utilities libtool build-essential pkg-config linux-headers-`uname –r`

編譯安裝ovs

# cd openvswitch-2.10.0
# ./boot.sh
# ./configure  --with-linux=/lib/modules/`uname -r`/build
# make
# make install

安裝ovs核心模組

 # insmod datapath/linux/openvswitch.ko

如果提示unknown symbol, 表示缺少一些依賴

# modinfo openvswitch
filename:       /lib/modules/4.8.0-36-generic/kernel/net/openvswitch/openvswitch.ko
license:        GPL
description:    Open vSwitch switching datapath
srcversion:     0DCA09B6BCF4444097F8069
depends:        nf_conntrack,nf_nat,libcrc32c,nf_nat_ipv6,nf_nat_ipv4,nf_defrag_ipv6
intree:         Y
vermagic:       4.8.0-36-generic SMP mod_unload modversions  

可以看到openvswitch.ko依賴nf_conntrack等等模組, 於是載入這些模組,然後再安裝openvswitch.ko

# modprobe nf_conntrack
# modprobe nf_nat
# modprobe libcrc32c
# modprobe nf_nat_ipv6
# modprobe nf_nat_ipv4
# modprobe nf_defrag_ipv6

# insmod datapath/linux/openvswitch.ko
# lsmod | grep open
openvswitch           106496  2
nf_defrag_ipv6         36864  2 nf_conntrack_ipv6,openvswitch
nf_nat_ipv6            16384  1 openvswitch
libcrc32c              16384  1 openvswitch
nf_nat_ipv4            16384  2 openvswitch,iptable_nat
nf_nat                 28672  4 openvswitch,nf_nat_ipv6,nf_nat_masquerade_ipv4,nf_nat_ipv4
nf_conntrack          110592  9 nf_conntrack_ipv6,openvswitch,nf_conntrack_ipv4,nf_conntrack_netlink,nf_nat_ipv6,nf_nat_masquerade_ipv4,xt_conntrack,nf_nat_ipv4,nf_nat 

初始化ovsdb

利用自帶的schema,建立資料庫

# mkdir -p /etc/openvswitch
# ovsdb-tool create /etc/openvswitch/conf.db vswitchd/vswitch.ovsschema

啟動ovsdb-server程序

# ovsdb-server /etc/openvswitch/conf.db -vconsole:emer -vsyslog:err -vfile:info --remote=punix:/usr/local/var/run/openvswitch/db.sock --private-key=db:Open_vSwitch,SSL,private_key --certificate=db:Open_vSwitch,SSL,certificate --bootstrap-ca-cert=db:Open_vSwitch,SSL,ca_cert --no-chdir --log-file=/usr/local/var/log/openvswitch/ovsdb-server.log --pidfile=/usr/local/var/run/openvswitch/ovsdb-server.pid --detach --monitor  

如果提示file or directory not exist, 那就手動建立對應的目錄

啟動ovsdb-vswitchd程序

# ovs-vswitchd unix:/usr/local/var/run/openvswitch/db.sock -vconsole:emer -vsyslog:err -vfile:info --mlockall --no-chdir --log-file=/usr/local/var/log/openvswitch/ovs-vswitchd.log --pidfile=/usr/local/var/run/openvswitch/ovs-vswitchd.pid --detach --monitor 

啟動完成

# ps -aux | grep ovs
root       3403  0.0  0.0   9120   144 ?        Ss   03:51   0:00 ovsdb-server: monitoring pid 3404 (healthy)
root       3404  0.0  0.2   9372  2516 ?        S    03:51   0:00 ovsdb-server /etc/openvswitch/conf.db -vconsole:emer -vsyslog:err -vfile:info --remote=punix:/usr/local/var/run/openvswitch/db.sock --private-key=db:Open_vSwitch,SSL,private_key --certificate=db:Open_vSwitch,SSL,certificate --bootstrap-ca-cert=db:Open_vSwitch,SSL,ca_cert --no-chdir --log-file=/usr/local/var/log/openvswitch/ovsdb-server.log --pidfile=/usr/local/var/run/openvswitch/ovsdb-server.pid --detach --monitor
root       3406  0.0  0.1  14168  1828 ?        Ss   03:52   0:00 ovs-vswitchd: monitoring pid 3407 (healthy)
root       3407  0.0  3.1 235852 31168 ?        SLl  03:52   0:06 ovs-vswitchd unix:/usr/local/var/run/openvswitch/db.sock -vconsole:emer -vsyslog:err -vfile:info --mlockall --no-chdir --log-file=/usr/local/var/log/openvswitch/ovs-vswitchd.log --pidfile=/usr/local/var/run/openvswitch/ovs-vswitchd.pid --detach --monitor
root       3836  0.0  0.0  14224   972 pts/8    S+   06:02   0:00 grep --color=auto ovs 

Enjoy it ~