AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 1130287
Accepted
Unpossible
Unpossible
Asked: 2023-05-04 02:12:43 +0800 CST2023-05-04 02:12:43 +0800 CST 2023-05-04 02:12:43 +0800 CST

kvm 来宾(Debian 和 Centos)中的 cloud-init 未设置界面设置

  • 772

我正在尝试使用 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

请问我做错了什么?

centos
  • 1 1 个回答
  • 18 Views

1 个回答

  • Voted
  1. Best Answer
    Unpossible
    2023-05-07T19:56:12+08:002023-05-07T19:56:12+08:00

    我的第一个错误似乎是将网络配置添加到user-data. 让它与 network( network-config) 的单独配置文件和 debian 和 centos 的适当 ENI 版本一起使用。

    对于 debian:

    cat << EOF > $network_config
      version: 1
      config:
        - type: physical
          name: eth0
          subnets:
            - type: static
              address: 10.10.0.26
              gateway: 10.10.0.254
        - type: route
          destination: 10.100.0.0/24
          gateway: 10.10.0.249
        - type: nameserver
          address:
            - 10.100.0.23
            - 10.100.0.17
            - 10.100.0.18
          search:
            - testing.mydom
            - production.mydom
            - admin.mydom
    EOF
    

    对于 centos:

    cat << EOF > $network_config
      version: 1
      config:
        - type: physical
          name: eth0
          subnets:
            - type: static
              address: 10.10.0.26
              gateway: 10.10.0.254
        - type: route
          destination: 10.100.0.0/24
          gateway: 10.10.0.249
        - type: nameserver
          address:
            - 10.100.0.23
            - 10.100.0.17
            - 10.100.0.18
          search:
            - testing.mydom
            - production.mydom
            - admin.mydom
    EOF
    

    我们将看到 Ubuntu 映像会发生什么(并修复包“更新”和安装)。

    • 0

相关问题

  • 如何在 Linux 机器上找到有关硬件的详细信息?

  • 使用 crontab 和 /etc/cron.hourly,daily,weekly 的区别

  • 持续监控许多服务器运行状况的简单方法?

  • Hudson 无法在 tomcat5 中启动

  • CentOS 的依赖挑战

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve