如何在 Incus 中设置 OVN¶
有关如何设置基本 OVN 网络(作为独立网络或托管小型 Incus 集群)的信息,请参阅以下部分。
设置独立的 OVN 网络¶
完成以下步骤以创建独立的 OVN 网络,该网络连接到受管的 Incus 父桥接网络(例如,incusbr0
)以进行出站连接。
在本地服务器上安装 OVN 工具
sudo apt install ovn-host ovn-central
配置 OVN 集成桥接
sudo ovs-vsctl set open_vswitch . \ external_ids:ovn-remote=unix:/run/ovn/ovnsb_db.sock \ external_ids:ovn-encap-type=geneve \ external_ids:ovn-encap-ip=127.0.0.1
创建 OVN 网络
incus network set <parent_network> ipv4.dhcp.ranges=<IP_range> ipv4.ovn.ranges=<IP_range> incus network create ovntest --type=ovn network=<parent_network>
创建使用
ovntest
网络的实例incus init images:ubuntu/22.04 c1 incus config device override c1 eth0 network=ovntest incus start c1
运行
incus list
以显示实例信息user@host:~$
incus list
+------+---------+---------------------+----------------------------------------------+-----------+-----------+
| NAME | STATE | IPV4 | IPV6 | TYPE | SNAPSHOTS |
+------+---------+---------------------+----------------------------------------------+-----------+-----------+
| c1 | RUNNING | 192.0.2.2 (eth0) | 2001:db8:cff3:5089:216:3eff:fef0:549f (eth0) | CONTAINER | 0 |
+------+---------+---------------------+----------------------------------------------+-----------+-----------+
在 OVN 上设置 Incus 集群¶
完成以下步骤以设置使用 OVN 网络的 Incus 集群。
与 Incus 一样,OVN 的分布式数据库必须运行在由奇数个成员组成的集群上。以下说明使用最少的三个服务器,它们同时运行 OVN 的分布式数据库和 OVN 控制器。此外,您可以将任何数量的服务器添加到运行仅 OVN 控制器的 Incus 集群中。
在您要运行 OVN 的分布式数据库的三个机器上完成以下步骤。
安装 OVN 工具
sudo apt install ovn-central ovn-host
将 OVN 服务标记为已启用,以确保机器启动时启动它们。
systemctl enable ovn-central systemctl enable ovn-host
暂时停止 OVN。
systemctl stop ovn-central
记下机器的 IP 地址。
ip -4 a
打开
/etc/default/ovn-central
进行编辑。粘贴以下配置之一(将
<server_1>
、<server_2>
和<server_3>
替换为相应机器的 IP 地址,并将<local>
替换为您的机器的 IP 地址)。对于第一台机器
OVN_CTL_OPTS=" \ --db-nb-addr=<local> \ --db-nb-create-insecure-remote=yes \ --db-sb-addr=<local> \ --db-sb-create-insecure-remote=yes \ --db-nb-cluster-local-addr=<local> \ --db-sb-cluster-local-addr=<local> \ --ovn-northd-nb-db=tcp:<server_1>:6641,tcp:<server_2>:6641,tcp:<server_3>:6641 \ --ovn-northd-sb-db=tcp:<server_1>:6642,tcp:<server_2>:6642,tcp:<server_3>:6642"
对于第二台和第三台机器
OVN_CTL_OPTS=" \ --db-nb-addr=<local> \ --db-nb-cluster-remote-addr=<server_1> \ --db-nb-create-insecure-remote=yes \ --db-sb-addr=<local> \ --db-sb-cluster-remote-addr=<server_1> \ --db-sb-create-insecure-remote=yes \ --db-nb-cluster-local-addr=<local> \ --db-sb-cluster-local-addr=<local> \ --ovn-northd-nb-db=tcp:<server_1>:6641,tcp:<server_2>:6641,tcp:<server_3>:6641 \ --ovn-northd-sb-db=tcp:<server_1>:6642,tcp:<server_2>:6642,tcp:<server_3>:6642"
启动 OVN
systemctl start ovn-central
在其余机器上,仅安装
ovn-host
并确保它已启用。sudo apt install ovn-host systemctl enable ovn-host
在所有机器上,配置 Open vSwitch(替换如上所述的变量)。
sudo ovs-vsctl set open_vswitch . \ external_ids:ovn-remote=tcp:<server_1>:6642,tcp:<server_2>:6642,tcp:<server_3>:6642 \ external_ids:ovn-encap-type=geneve \ external_ids:ovn-encap-ip=<local>
通过在所有机器上运行
incus admin init
创建 Incus 集群。在第一台机器上,创建集群。然后通过在第一台机器上运行incus cluster add <machine_name>
并指定令牌来加入其他机器,并在其他机器上初始化 Incus 时指定令牌。在第一台机器上,创建和配置上行链路网络
incus network create UPLINK --type=physical parent=<uplink_interface> --target=<machine_name_1> incus network create UPLINK --type=physical parent=<uplink_interface> --target=<machine_name_2> incus network create UPLINK --type=physical parent=<uplink_interface> --target=<machine_name_3> incus network create UPLINK --type=physical parent=<uplink_interface> --target=<machine_name_4> incus network create UPLINK --type=physical \ ipv4.ovn.ranges=<IP_range> \ ipv6.ovn.ranges=<IP_range> \ ipv4.gateway=<gateway> \ ipv6.gateway=<gateway> \ dns.nameservers=<name_server>
要确定所需的值
- 上行链路接口
高可用性 OVN 集群需要一个共享的二层网络,以便活动 OVN 底盘可以在集群成员之间移动(这实际上允许 OVN 路由器的外部 IP 从不同的主机访问)。
因此,您必须指定一个非管理桥接接口或一个未使用的物理接口作为用于 OVN 上行链路的物理网络的父级。这些说明假设您使用的是手动创建的非管理桥接。有关如何设置此桥接的说明,请参阅 如何配置网络桥接。
- 网关
运行
ip -4 route show default
和ip -6 route show default
。- 名称服务器
运行
resolvectl
。- IP 范围
根据分配的 IP 使用合适的 IP 范围。
仍在第一台机器上,配置 Incus 以便能够与 OVN DB 集群通信。为此,在
/etc/default/ovn-central
中找到ovn-northd-nb-db
的值,并使用以下命令将其提供给 Incusincus config set network.ovn.northbound_connection <ovn-northd-nb-db>
最后,创建实际的 OVN 网络(在第一台机器上)
incus network create my-ovn --type=ovn
要测试 OVN 网络,请创建一些实例并检查网络连接。
incus launch images:ubuntu/22.04 c1 --network my-ovn incus launch images:ubuntu/22.04 c2 --network my-ovn incus launch images:ubuntu/22.04 c3 --network my-ovn incus launch images:ubuntu/22.04 c4 --network my-ovn incus list incus exec c4 -- bash ping <IP of c1> ping <nameserver> ping6 -n www.example.com
将 OVN 日志发送到 Incus¶
完成以下步骤,使 OVN 控制器将日志发送到 Incus。
启用 syslog 套接字
incus config set core.syslog_socket=true
打开
/etc/default/ovn-host
进行编辑。粘贴以下配置
OVN_CTL_OPTS=" \ --ovn-controller-log='-vsyslog:info --syslog-method=unix:/var/lib/incus/syslog.socket'"
重启 OVN 控制器
systemctl restart ovn-controller.service
您现在可以使用 incus monitor
查看来自 OVN 控制器的记录的网络 ACL 流量
incus monitor --type=network-acls
您也可以将日志发送到 Loki。为此,将 network-acl
值添加到 loki.types
配置键中,例如
incus config set loki.types=network-acl
提示
您还可以包括 OVN northd
、OVN 北向 ovsdb-server
和 OVN 南向 ovsdb-server
的日志。为此,请编辑 /etc/default/ovn-central
OVN_CTL_OPTS=" \
--ovn-northd-log='-vsyslog:info --syslog-method=unix:/var/lib/incus/syslog.socket' \
--ovn-nb-log='-vsyslog:info --syslog-method=unix:/var/lib/incus/syslog.socket' \
--ovn-sb-log='-vsyslog:info --syslog-method=unix:/var/lib/incus/syslog.socket'"
sudo systemctl restart ovn-central.service