OpenVSwitch

来自 Alpine Linux

本文档描述了如何在 Alpine Linux 中配置 OpenVSwitch。

安装 OVS

apk add openvswitch
rc-update add ovs-modules
rc-update add ovsdb-server
rc-update add ovs-vswitchd
rc-service ovs-modules start
rc-service ovsdb-server start
rc-service ovs-vswitchd start

使用 ovs-vsctl

Open VSwitch 通过 ovs-vsctl 命令手动管理。

要手动创建一个名为 "lan" 的交换机

ovs-vsctl add-br lan

要将接口 eth0 添加到交换机 "lan"

ovs-vsctl add-port lan eth0

注意:您需要在添加的接口上将链路状态设置为up

ip link set dev eth0 up

要查看定义了哪些 OVS

ovs-vsctl list-br

要查看哪些接口链接到 lan OVS

ovs-vsctl list-ports lan

要启用生成树协议(如果需要)

ovs-vsctl set bridge lan stp_enable=true

LACP 定时器设置为 'fast' 模式

ovs-vsctl set port bond0 other_config:lacp-time=fast

使用 OVS appctl

ovs-appctl lacp/show bond0

配置文件

配置在 /etc/network/interfaces

auto eth0 lan
iface eth0 inet manual
 up ifconfig eth0 0.0.0.0 up
 down ifconfig eth0 down

iface lan inet dhcp

OVS 和 qemu

助手脚本

ovs-ifup-

#!/bin/sh
switch=$(echo $0|/usr/bin/cut -d- -f3)
[ -z ${switch} ] && echo "Please define some symlink with suffix to use." && exit 1
[ $# -lt 1 ] && echo "Too few params. Must be 1 and is $#." && exit 2
/sbin/ifconfig $1 0.0.0.0 up
ovs-vsctl add-port ${switch} $1
logger "qemu: $1 added to ${switch} at startup of VM"

ovs-ifdown-

#!/bin/sh
switch=$(echo $0|/usr/bin/cut -d- -f3)
[ -z ${switch} ] && echo "Please define some symlink with suffix to use." && exit 1
[ $# -lt 1 ] && echo "Too few params. Must be 1 and is $#." && exit 2
/sbin/ifconfig $1 0.0.0.0 down
ovs-vsctl del-port ${switch} $1
logger "qemu: $1 removed from ${switch} at shutdown of VM"

OVS 和 LXC

助手脚本

lxc-ovs-ifdown-

#!/bin/sh
switch=$(echo $0|/usr/bin/cut -d- -f4)
[ -z ${switch} ] && echo "Please define some symlink with suffix to use." && return 1
[ $# -lt 5 ] && echo "Too few params. Must be 5 and is $#." && exit 2
nic=$5
/usr/bin/ovs-vsctl del-port ${switch} ${nic}
/usr/bin/logger "lxc: ${nic} removed from ${switch} at shutdown of VM."

注意事项

确保您在下次重启时 OVS 软件包文件可用!当从没有缓存的 RAM 运行时,这可能是一个问题...