本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
VMware 環境沒有 Amazon EC2 執行個體中繼資料服務 (IMDS),因此需要設定 AL2023 的替代方法。本節說明如何對 VMware vSphere 中可用的seed.iso
虛擬 CD-ROM 磁碟機使用替代組態機制。
此組態方法使用 VMwareextraconfig
機制將組態資料提供給 cloud-init
。對於下列每個金鑰,必須提供對應的
屬性。keyname
.encoding
以下金鑰可以提供給 VMwareextraconfig
機制。
-
guestinfo.metadata
-
JSON 或包含
cloud-init
中繼資料的 YAML -
guestinfo.userdata
-
包含
cloud-config
格式cloud-init
使用者資料的 YAML 文件。 -
guestinfo.vendordata
(選用) -
YAML 包含
cloud-init
廠商資料
對應的編碼屬性 (guestinfo.metadata.encoding
、guestinfo.userdata.encoding
和 guestinfo.vendordata.encoding
) 可以包含:
-
base64
-
屬性的內容已
base64
編碼。 -
gzip+base64
-
base64
編碼後,會以gzip
壓縮屬性的內容。
注意
seed.iso
方法支援單獨的 (選用) network-config
組態檔案。 提供聯網組態的方式VMwareguestinfo
有所不同。以下章節提供其他資訊。
如果需要明確的網路組態,應該以兩個 YAML 或 JSON 屬性的形式嵌入 metadata
:
-
network
-
包含 JSON 或 YAML 格式的編碼網路組態。
-
network.encoding
-
包含上述網路組態資料的編碼。
cloud-init
支援的編碼與guestinfo
資料的編碼相同:base64
和gzip+base64
。
範例 使用 VMware vSphere CLI govc
工具透過 傳遞組態 guestinfo
-
準備
meta-data
、user-data
和選用network-config
組態檔案,如 中所述在 KVM 和 VMware 上適用於 Amazon Linux 2023 的 NoCloud (seed.iso) cloud-init 組態。 -
將組態檔案轉換為 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"