openvswitchをソースコードからビルドしてサービス登録する-ubuntu 22.04 ver.

  • バイナリのインストール

sudo su -
apt-get install -y build-essential < /dev/null
wget https://www.openvswitch.org/releases/openvswitch-2.17.7.tar.gz
tar xvfz openvswitch-2.17.7.tar.gz
cd openvswitch-2.17.7/
./configure
make
make install
  • systemd unitファイルのインストール

cat <<'EOF' > /etc/systemd/system/openvswitch-switch.service
[Unit]
Description=Open vSwitch
Before=network.target
After=network-pre.target ovsdb-server.service ovs-vswitchd.service
PartOf=network.target
Requires=ovsdb-server.service
Requires=ovs-vswitchd.service

[Service]
Type=oneshot
ExecStart=/bin/true
ExecReload=/usr/local/share/openvswitch/scripts/ovs-systemd-reload
ExecStop=/bin/true
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target
Also=ovs-record-hostname.service
EOF
cat <<'EOF' > /etc/systemd/system/ovsdb-server.service
[Unit]
Description=Open vSwitch Database Unit
After=systemd-journald.socket network-pre.target dpdk.service local-fs.target
Before=network.target networking.service
PartOf=openvswitch-switch.service
DefaultDependencies=no

[Service]
LimitNOFILE=1048576
Type=forking
Restart=on-failure
EnvironmentFile=-/etc/default/openvswitch-switch
ExecStart=/usr/local/share/openvswitch/scripts/ovs-ctl \
          --no-ovs-vswitchd --no-monitor --system-id=random \
          --no-record-hostname \
          start $OVS_CTL_OPTS
ExecStop=/usr/local/share/openvswitch/scripts/ovs-ctl --no-ovs-vswitchd stop
ExecReload=/usr/local/share/openvswitch/scripts/ovs-ctl --no-ovs-vswitchd \
          --no-record-hostname \
          --no-monitor restart $OVS_CTL_OPTS
RuntimeDirectory=openvswitch
RuntimeDirectoryMode=0755
RuntimeDirectoryPreserve=yes
EOF
cat <<'EOF' > /etc/systemd/system/ovs-vswitchd.service
[Unit]
Description=Open vSwitch Forwarding Unit
After=ovsdb-server.service network-pre.target systemd-udev-settle.service
Before=network.target networking.service
Requires=ovsdb-server.service
ReloadPropagatedFrom=ovsdb-server.service
AssertPathIsReadWrite=/usr/local/var/run/openvswitch/db.sock
PartOf=openvswitch-switch.service
DefaultDependencies=no

[Service]
LimitNOFILE=1048576
Type=forking
Restart=on-failure
Environment=HOME=/var/run/openvswitch
EnvironmentFile=-/etc/default/openvswitch-switch
ExecStart=/usr/local/share/openvswitch/scripts/ovs-ctl \
          --no-ovsdb-server --no-monitor --system-id=random \
          --no-record-hostname \
          start $OVS_CTL_OPTS
ExecStop=/usr/local/share/openvswitch/scripts/ovs-ctl --no-ovsdb-server stop
ExecReload=/usr/local/share/openvswitch/scripts/ovs-ctl --no-ovsdb-server \
          --no-monitor --system-id=random \
          --no-record-hostname \
          restart $OVS_CTL_OPTS
TimeoutSec=300
EOF
cat <<'EOF' > /etc/systemd/system/ovs-record-hostname.service
[Unit]
Description=Open vSwitch Record Hostname
After=ovsdb-server.service ovs-vswitchd.service network-online.target
Requires=ovsdb-server.service
Requires=ovs-vswitchd.service
Requires=network-online.target
AssertPathIsReadWrite=/usr/local/var/run/openvswitch/db.sock

[Service]
Type=oneshot
ExecStart=/usr/local/share/openvswitch/scripts/ovs-ctl record-hostname-if-not-set
ExecStop=/bin/true
ExecReload=/usr/local/share/openvswitch/scripts/ovs-ctl record-hostname-if-not-set
TimeoutSec=300
RemainAfterExit=yes

[Install]
RequiredBy=openvswitch-switch.service
EOF
cat <<'EOF' > /etc/systemd/system/openvswitch-ipsec.service
[Unit]
Description=Open vSwitch IPsec daemon
Requires=openvswitch-switch.service
After=openvswitch-switch.service

[Service]
Type=forking
PIDFile=/run/openvswitch/ovs-monitor-ipsec.pid
ExecStart=/usr/local/share/openvswitch/scripts/ovs-ctl \
                    --ike-daemon=strongswan start-ovs-ipsec
ExecStop=/usr/local/share/openvswitch/scripts/ovs-ctl stop-ovs-ipsec

[Install]
WantedBy=multi-user.target
EOF
cat <<'EOF' > /etc/default/openvswitch
# This is a POSIX shell fragment                -*- sh -*-

# FORCE_COREFILES: If 'yes' then core files will be enabled.
# FORCE_COREFILES=yes

# OVS_CTL_OPTS: Extra options to pass to ovs-ctl.  This is, for example,
# a suitable place to specify --ovs-vswitchd-wrapper=valgrind.
# OVS_CTL_OPTS=

# DPDK options are now configured via ovs-vsctl/ovsdb.
# dpdk-extra is the fallback for users who formerly set e.g.
#  '--vhost-owner libvirt-qemu:kvm --vhost-perm 0664'
# here or any other DPDK EAL arguments via DPDK_OPTS which are not covered by
# the default switches provided by ovs-vsctl.
# This is an arbitrary string that will get appended to the EAL commandline.
# For more on the new ovsdb based configuration of DPDK features, see:
# `man ovs-vswitchd.conf.db`
EOF
systemctl daemon-reload
  • systemd serviceの設定

systemctl enable openvswitch-switch.service
systemctl start openvswitch-switch.service

この記事が気に入ったらサポートをしてみませんか?