我正在尝试使用 cloud-init 来设置 kvm 来宾(目前是 Debian 11 和 CentOS Stream 8),我正在寻求有关更正元数据和用户数据文件的帮助。其他一切似乎都有效,但网络接口设置未设置,但我确实看到 cloud-init 日志显示它们已设置。请看下面:
对于 debian:
cat << EOF > /var/lib/libvirt/images/$meta_data_file
instance-id: $vm_name
local-hostname: $vm_name
hostname: $vm_name
fqdn: $vm_name
manage_etc_hosts: true
EOF
cat << EOF > /var/lib/libvirt/images/$cloud_config_file
#cloud-config
# Hostname management
preserve_hostname: false
hostname: $vm_name
fqdn: $vm_name
network:
version: 2
ethernets:
eth0:
match:
name: e*
dhcp4: false
addresses:
- 10.10.0.25/24
gateway4: 10.10.0.254
nameservers:
addresses:
- 10.50.0.23
- 10.50.0.17
- 10.50.0.18
search: [testing,production,admin,internal]
routes:
- to: 10.50.0.0/24
via: 10.10.0.249
users:
- default
- name: admin
sudo: ALL=(ALL) NOPASSWD:ALL
groups: wheel, sudo, admin
home: /home/admin
shell: /bin/bash
hashed_passwd: $adminpasswd
lock_passwd: false
ssh_pwauth: True
chpasswd: { expire: False }
ssh-authorized-keys:
- ssh-rsa ...
- ssh-rsa ...
# only cert auth via ssh (console access can still login)
ssh_pwauth: True
disable_root: false
chpasswd:
list: |
root:$rtpwd
expire: False
runcmd:
# disable dhcp for eth0
- [ sh, -c, sed -e '/iface eth0 inet dhcp/s/^/#/g' -i /etc/network/interfaces ]
bootcmd:
- cloud-init-per always fix-debian-autonet rm /etc/udev/rules.d/75-cloud-ifupdown.rules
- cloud-init-per always fix-debian-netconfig rm /run/network/interfaces.d/*
- cloud-init-per once ifdown ifdown ens3
- cloud-init-per once bugfix rm /run/network/interfaces.d/ens3
- cloud-init-per once ifup ifup ens3
# Configure where output will go
output:
all: ">> /var/log/cloud-init.log"
# configure interaction with ssh server
ssh_svcname: ssh
ssh_deletekeys: True
ssh_genkeytypes: ['rsa', 'ecdsa']
package_update: true
package_upgrade: true
packages:
- bind9-utils
- vim
- freeipa-client
- cloud-utils-growpart
power_state:
delay: "+2" #minutes
mode: reboot
message: Run completed
timeout: 120 #seconds
condition: True
EOF
对于 Centos Stream 8:
cat << EOF > /var/lib/libvirt/images/$cloud_config_file
#cloud-config
# Hostname management
preserve_hostname: false
hostname: $vm_name
fqdn: $vm_name
network:
version: 2
ethernets:
eth0:
match:
name: e*
dhcp4: false
addresses:
- 10.50.0.26/24
gateway4: 10.50.0.254
nameservers:
addresses:
- 10.15.0.23
- 10.15.0.17
- 10.15.0.18
search: [testing,production,admin,internal]
routes:
- to: 10.15.0.0/24
via: 10.50.0.249
users:
- default
- name: admin
sudo: ALL=(ALL) NOPASSWD:ALL
groups: wheel, sudo, admin
home: /home/admin
shell: /bin/bash
hashed_passwd: $adminpasswd
lock_passwd: false
ssh_pwauth: True
chpasswd: { expire: False }
ssh-authorized-keys:
- ssh-rsa ...
- ssh-rsa ...
ssh_pwauth: True
disable_root: false
chpasswd:
list: |
root:$rtpwd
expire: False
# Configure where output will go
output:
all: ">> /var/log/cloud-init.log"
# configure interaction with ssh server
ssh_svcname: ssh
ssh_deletekeys: True
ssh_genkeytypes: ['rsa', 'ecdsa']
package_update: true
package_upgrade: true
packages:
- bind9-utils
- vim
- freeipa-client
- cloud-utils-growpart
power_state:
delay: "+2" #minutes
mode: reboot
message: Run completed
timeout: 120 #seconds
condition: True
EOF
请问我做错了什么?
我的第一个错误似乎是将网络配置添加到
user-data
. 让它与 network(network-config
) 的单独配置文件和 debian 和 centos 的适当 ENI 版本一起使用。对于 debian:
对于 centos:
我们将看到 Ubuntu 映像会发生什么(并修复包“更新”和安装)。