Compile OpenvSwitch

Environment

  • OS: Ubuntu 14.04.5 Server LTS X86_64
  • Kernel version: 4.4.0-59-generic

Pre-install

1
apt install dh-autoreconf libssl-dev openssl

Compile OpenvSwitch

1
2
3
4
5
6
7
8
9
git clone https://github.com/openvswitch/ovs
git checkout branch-2.7
./boot.sh
./configure --with-linux=/lib/modules/`uname -r`/build
make
sudo make install
sudo make modules_install
sudo modprobe openvswitch
sudo modprobe libcrc32c
  • 使用 lsmod |grep openvswitch 確認ovs正確地掛載起來
  • ./configure 部份其實還可以下一個 --prefix= 參數, 可以讓openvswitch 完全裝在該目錄底下而不會亂掉

Setting ovsdb

1
2
mkdir -p /usr/local/etc/openvswitch
ovsdb-tool create /usr/local/etc/openvswitch/conf.db /usr/local/share/openvswitch/vswitch.ovsschema
  • 建立一次即可, 如果設定有問題的話可以把conf.db砍掉重建

(二選一) Start ovsdb-server (Non-SSL)

1
2
3
4
mkdir -p /usr/local/var/run/openvswitch
ovsdb-server --remote=punix:/usr/local/var/run/openvswitch/db.sock \
--remote=db:Open_vSwitch,Open_vSwitch,manager_options \
--pidfile --detach --log-file
  • cat /usr/local/var/log/openvswitch/ovsdb-server.log 可查到 ovsdb log

(二選一) Start ovsdb-server (SSL)

1
2
3
4
5
6
7
mkdir -p /usr/local/var/run/openvswitch
ovsdb-server --remote=punix:/usr/local/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
  • 若要使用 ssl 連線, 務必在編譯前要先準備好 libssl-devopenssl, 否則會噴出 Private key specified but Open vSwitch was built without SSL support 的錯誤
  • OpenvSwitch Lab 6$ TLS SSL

Launch ovs-vsctl

1
ovs-vsctl --no-wait init

Start ovs-switchd

1
ovs-vswitchd --pidfile --detach --log-file
  • /usr/local/var/log/openvswitch/ovs−vswitchd.log 可查到 ovs-vswitchd log

觀察

  • ps aux |grep ovs

ovs_install_complete.png

開機自動化

設定開機自動 load module

1
2
echo "openvswitch " >> /etc/modules
echo "libcrc32c" >> /etc/modules

設定開機自動啟動

1
2
3
4
5
6
7
8
9
cat >> /etc/init.d/openvswitch << EOF
#!/bin/sh
start-stop-daemon -q -S -x /usr/local/sbin/ovsdb-server -- --remote=punix:/usr/local/var/run/openvswitch/db.sock --remote=db:Open_vSwitch,Open_vSwitch,manager_options --pidfile --detach --log-file
sleep 3 # waiting ovsdb-server
start-stop-daemon -q -S -x /usr/local/bin/ovs-vsctl -- --no-wait init
start-stop-daemon -q -S -x /usr/local/sbin/ovs-vswitchd -- --pidfile --detach --log-file
EOF
chmod +x /etc/init.d/openvswitch
update-rc.d -f openvswitch defaults

修改 Failsafe

vim /etc/init/failsafe.conf

1
2
3
4
5
6
7
...
$PLYMOUTH message --text="Waiting for network configuration..." || :
sleep 1
$PLYMOUTH message --text="Waiting up to 60 more seconds for network configuration..." || :
sleep 1
$PLYMOUTH message --text="Booting system without full network configuration..." || :
...

References

Update