适用于 VMware 上 AL2023 的 VMware 客户机信息 cloud-init 配置 - Amazon Linux 2023
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

适用于 VMware 上 AL2023 的 VMware 客户机信息 cloud-init 配置

VMware 环境没有 Amazon EC2 实例元数据服务 (IMDS),因此需要一种配置 AL2023 的替代方法。这部分介绍如何使用 VMware vSphere 中可用的 seed.iso 虚拟 CD-ROM 驱动器的替代配置机制。

此配置方法使用 VMware extraconfig 机制向 cloud-init 提供配置数据。对于以下每个键,必须提供相应的 keyname.encoding 属性。

以下键可提供给 VMware extraconfig 机制。

guestinfo.metadata

包含 cloud-init 元数据的 JSON 或 YAML

guestinfo.userdata

包含 cloud-config 格式的 cloud-init 用户数据的 YAML 文档。

guestinfo.vendordata(可选)

YAML 包含 cloud-init 供应商数据

相应的编码属性(guestinfo.metadata.encodingguestinfo.userdata.encodingguestinfo.vendordata.encoding)可以包含:

base64

属性的内容用 base64 编码。

gzip+base64

属性的内容先用 base64 编码再用 gzip 压缩。

注意

seed.iso 方法支持一个独立的(可选的)network-config 配置文件。VMware guestinfo 在网络配置的提供方式上有所不同。更多信息在以下部分提供。

如果需要一个明确的网络配置,则应以两个 YAML 或 JSON 属性的形式将其嵌入到 metadata 中:

network

包含 JSON 或 YAML 格式的编码网络配置。

network.encoding

包含上述网络配置数据的编码。对于 guestinfo 数据,cloud-init 支持的编码是相同的:base64gzip+base64

例 使用 VMware vSphere govc CLI 工具通过 guestinfo 传递配置
  1. 按照 KVM 和 VMware 上的 Amazon Linux 2023 的 NoCloud (seed.iso) cloud-init 配置 中的说明准备 meta-datauser-data 和可选的 network-config 配置文件。

  2. 将配置文件转换为 VMware guestinfo 可用的格式。

    # 'meta-data', `user-data` and `network-config` are the configuration # files in the same format that would be used by a NoCloud (seed.iso) # data source, read-them and convert them to VMware guestinfo # # The VM_NAME variable is assumed to be set to the name of the VM # It is assumed that the necessary govc environment (credentials etc...) are already set metadata=$(cat "meta-data") userdata=$(cat "user-data") if [ -e "network-config" ] ; then # We need to embed the network config inside the meta-data netconf=$(base64 -w0 "network-config") metadata=$(printf "%s\nnetwork: %s\nnetwork.encoding: base64" "$metadata" "$netconf") fi metadata=$(base64 -w0 <<< "$metadata") govc vm.change -vm "$VM_NAME" \ -e guestinfo.metadata="$metadata" \ -e guestinfo.metadata.encoding="base64" userdata=$(base64 -w0 <<< "$userdata") govc vm.change -vm "$VM_NAME" \ -e guestinfo.userdata="$userdata" \ -e guestinfo.userdata.encoding="base64"