安装并配置计算节点¶
本节描述了如何在计算节点上安装和配置 Compute 服务。
注意
本节假定您正在逐步按照本指南中的说明配置第一个计算节点。如果您想配置其他计算节点,请以类似的方式准备它们。每个额外的计算节点需要一个唯一的 IP 地址。
先决条件¶
在安装和配置 Zun 之前,您必须在计算节点上正确安装 Docker 和 Kuryr-libnetwork。请参阅 获取 Docker 以获取 Docker 安装说明,以及 Kuryr libnetwork 安装指南
安装和配置组件¶
创建 zun 用户和必要的目录
创建用户
# groupadd --system zun # useradd --home-dir "/var/lib/zun" \ --create-home \ --system \ --shell /bin/false \ -g zun \ zun
创建目录
# mkdir -p /etc/zun # chown zun:zun /etc/zun
创建 CNI 目录
# mkdir -p /etc/cni/net.d # chown zun:zun /etc/cni/net.d
安装以下依赖项
对于 Ubuntu,运行
# apt-get install python3-pip git numactl
对于 CentOS,运行
# yum install python3-pip git python3-devel libffi-devel gcc openssl-devel numactl
克隆并安装 zun
# cd /var/lib/zun # git clone https://opendev.org/openstack/zun.git # chown -R zun:zun zun # git config --global --add safe.directory /var/lib/zun/zun # cd zun # pip3 install -r requirements.txt # python3 setup.py install
生成示例配置文件
# su -s /bin/sh -c "oslo-config-generator \ --config-file etc/zun/zun-config-generator.conf" zun # su -s /bin/sh -c "cp etc/zun/zun.conf.sample \ /etc/zun/zun.conf" zun # su -s /bin/sh -c "cp etc/zun/rootwrap.conf \ /etc/zun/rootwrap.conf" zun # su -s /bin/sh -c "mkdir -p /etc/zun/rootwrap.d" zun # su -s /bin/sh -c "cp etc/zun/rootwrap.d/* \ /etc/zun/rootwrap.d/" zun # su -s /bin/sh -c "cp etc/cni/net.d/* /etc/cni/net.d/" zun
为
zun用户配置 sudoers注意
CentOS 可能会将二进制文件安装到
/usr/bin/。如果是这样,请在以下命令中将/usr/local/bin/目录替换为正确的目录。# echo "zun ALL=(root) NOPASSWD: /usr/local/bin/zun-rootwrap \ /etc/zun/rootwrap.conf *" | sudo tee /etc/sudoers.d/zun-rootwrap
编辑
/etc/zun/zun.conf在
[DEFAULT]部分中,配置RabbitMQ消息队列访问[DEFAULT] ... transport_url = rabbit://openstack:RABBIT_PASS@controller
将
RABBIT_PASS替换为您为RabbitMQ中的openstack帐户选择的密码。在
[DEFAULT]部分,配置 Zun 用于存储状态的路径[DEFAULT] ... state_path = /var/lib/zun
在
[database]部分,配置数据库访问[database] ... connection = mysql+pymysql://zun:ZUN_DBPASS@controller/zun
将
ZUN_DBPASS替换为您为 zun 数据库选择的密码。在
[keystone_auth]部分,配置 Identity 服务访问[keystone_auth] memcached_servers = controller:11211 www_authenticate_uri = http://controller:5000 project_domain_name = default project_name = service user_domain_name = default password = ZUN_PASS username = zun auth_url = http://controller:5000 auth_type = password auth_version = v3 auth_protocol = http service_token_roles_required = True endpoint_type = internalURL
在
[keystone_authtoken]部分中,配置 Identity 服务访问[keystone_authtoken] ... memcached_servers = controller:11211 www_authenticate_uri= http://controller:5000 project_domain_name = default project_name = service user_domain_name = default password = ZUN_PASS username = zun auth_url = http://controller:5000 auth_type = password
将 ZUN_PASS 替换为您在 Identity 服务中为 zun 用户选择的密码。
在
[oslo_concurrency]部分,配置lock_path[oslo_concurrency] ... lock_path = /var/lib/zun/tmp
(可选) 如果您想在此计算节点上运行容器和 nova 实例,请在
[compute]部分,配置host_shared_with_nova[compute] ... host_shared_with_nova = true
注意
确保
/etc/zun/zun.conf仍然具有正确的权限。您可以再次使用以下命令设置权限:# chown zun:zun /etc/zun/zun.conf
配置 Docker 和 Kuryr
创建目录
/etc/systemd/system/docker.service.d# mkdir -p /etc/systemd/system/docker.service.d
创建文件
/etc/systemd/system/docker.service.d/docker.conf。配置 docker 监听 2375 端口以及默认的 unix socket[Service] ExecStart= ExecStart=/usr/bin/dockerd --group zun -H tcp://compute1:2375 -H unix:///var/run/docker.sock
重启 Docker
# systemctl daemon-reload # systemctl restart docker
编辑 Kuryr 配置文件
/etc/kuryr/kuryr.conf。将process_external_connectivity设置为False[DEFAULT] ... process_external_connectivity = False
重启 Kuryr-libnetwork
# systemctl restart kuryr-libnetwork
配置 containerd
生成 containerd 的配置文件
# containerd config default > /etc/containerd/config.toml
编辑
/etc/containerd/config.toml。在[grpc]部分,配置gid为zun用户的组 ID[grpc] ... gid = ZUN_GROUP_ID
将
ZUN_GROUP_ID替换为zun用户的实际组 ID。您可以通过以下方式检索 ID(例如):# getent group zun | cut -d: -f3
注意
确保
/etc/containerd/config.toml仍然具有正确的权限。您可以再次使用以下命令设置权限:# chown zun:zun /etc/containerd/config.toml
重启 containerd
# systemctl restart containerd
配置 CNI
下载并安装标准环回插件
# mkdir -p /opt/cni/bin # curl -L https://github.com/containernetworking/plugins/releases/download/v0.7.1/cni-plugins-amd64-v0.7.1.tgz \ | tar -C /opt/cni/bin -xzvf - ./loopback
安装 Zun CNI 插件
# install -o zun -m 0555 -D /usr/local/bin/zun-cni /opt/cni/bin/zun-cni
注意
CentOS 可能会将二进制文件安装到
/usr/bin/。如果是这样,请在上述命令中将/usr/local/bin/zun-cni替换为正确的路径。
完成安装¶
为 zun compute 创建一个 upstart 配置文件,可以命名为
/etc/systemd/system/zun-compute.service注意
CentOS 可能会将二进制文件安装到
/usr/bin/。如果是这样,请在以下示例文件中将/usr/local/bin/目录替换为正确的目录。[Unit] Description = OpenStack Container Service Compute Agent [Service] ExecStart = /usr/local/bin/zun-compute User = zun [Install] WantedBy = multi-user.target
为 zun cni daemon 创建一个 upstart 配置文件,可以命名为
/etc/systemd/system/zun-cni-daemon.service注意
CentOS 可能会将二进制文件安装到
/usr/bin/,如果是这样,请在以下示例文件中将/usr/local/bin/目录替换为正确的目录。[Unit] Description = OpenStack Container Service CNI daemon [Service] ExecStart = /usr/local/bin/zun-cni-daemon User = zun [Install] WantedBy = multi-user.target
启用并启动 zun-compute
# systemctl enable zun-compute # systemctl start zun-compute
启用并启动 zun-cni-daemon
# systemctl enable zun-cni-daemon # systemctl start zun-cni-daemon
验证 zun-compute 和 zun-cni-daemon 服务是否正在运行
# systemctl status zun-compute # systemctl status zun-cni-daemon
启用 Kata 容器(可选)¶
默认情况下,runc 用作容器运行时。如果您想使用 Kata 容器,本节描述了额外的配置步骤。
注意
Kata 容器需要嵌套虚拟化或裸机。有关详细信息,请参阅 官方文档。
启用 Kata 容器的仓库
对于 Ubuntu,运行
# curl -sL http://download.opensuse.org/repositories/home:/katacontainers:/releases:/$(arch):/2025.2/xUbuntu_$(lsb_release -rs)/Release.key | apt-key add - # add-apt-repository "deb http://download.opensuse.org/repositories/home:/katacontainers:/releases:/$(arch):/2025.2/xUbuntu_$(lsb_release -rs)/ /"
对于 CentOS,运行
# yum-config-manager --add-repo "http://download.opensuse.org/repositories/home:/katacontainers:/releases:/$(arch):/2025.2/CentOS_7/home:katacontainers:releases:$(arch):master.repo"
安装 Kata 容器
对于 Ubuntu,运行
# apt-get update # apt install kata-runtime kata-proxy kata-shim
对于 CentOS,运行
# yum install kata-runtime kata-proxy kata-shim
配置 Docker 以添加 Kata 容器作为运行时
编辑文件
/etc/systemd/system/docker.service.d/docker.conf。附加--add-runtime选项以将 kata-runtime 添加到 Docker[Service] ExecStart= ExecStart=/usr/bin/dockerd --group zun -H tcp://compute1:2375 -H unix:///var/run/docker.sock --add-runtime kata=/usr/bin/kata-runtime
重启 Docker
# systemctl daemon-reload # systemctl restart docker
配置 containerd 以添加 Kata 容器作为运行时
编辑
/etc/containerd/config.toml。在[plugins.cri.containerd]部分,添加 kata 运行时配置[plugins] ... [plugins.cri] ... [plugins.cri.containerd] ... [plugins.cri.containerd.runtimes.kata] runtime_type = "io.containerd.kata.v2"
重启 containerd
# systemctl restart containerd
配置 Zun 以使用 Kata 运行时
编辑
/etc/zun/zun.conf。在[DEFAULT]部分,将container_runtime配置为 kata[DEFAULT] ... container_runtime = kata
重启 zun-compute
# systemctl restart zun-compute