4.6. 进行 Microsoft Azure 部署所需的配置更改

在将自定义基础镜像部署到 Azure 之前,您必须执行额外的配置更改,以确保虚拟机 (VM) 可以在 Azure 中正常工作。

步骤

  1. 登录到虚拟机。
  2. 注册虚拟机并启用 Red Hat Enterprise Linux 9 软件仓库。

    # subscription-manager register --auto-attach
    Installed Product Current Status:
    Product Name: Red Hat Enterprise Linux for x86_64
    Status: Subscribed
  3. 确保安装了 cloud-inithyperv-daemons 软件包。

    # dnf install cloud-init hyperv-daemons -y
  4. 创建与 Azure 服务集成的所需的 cloud-init 配置文件:

    1. 要启用登录到 Hyper-V Data Exchange Service(KVP),请创建 /etc/cloud/cloud.cfg.d/10-azure-kvp.cfg 配置文件并将以下行添加到该文件中。

      reporting:
          logging:
              type: log
          telemetry:
              type: hyperv
    2. 要将 Azure 添加为数据源,请创建 /etc/cloud/cloud.cfg.d/91-azure_datasource.cfg 配置文件,并将下面几行添加到该文件中。

      datasource_list: [ Azure ]
      datasource:
          Azure:
              apply_network_config: False
  5. 要确保特定内核模块自动被阻止,请编辑或创建 /etc/modprobe.d/blocklist.conf 文件,并将下面几行添加到该文件中。

    blacklist nouveau
    blacklist lbm-nouveau
    blacklist floppy
    blacklist amdgpu
    blacklist skx_edac
    blacklist intel_cstate
  6. 修改 udev 网络设备规则:

    1. 如果存在,请删除以下持久性网络设备规则。

      # rm -f /etc/udev/rules.d/70-persistent-net.rules
      # rm -f /etc/udev/rules.d/75-persistent-net-generator.rules
      # rm -f /etc/udev/rules.d/80-net-name-slot-rules
    2. 要确保在 Azure 上的 Accelerated Networking 可以正常工作,请创建一个新的网络设备规则 /etc/udev/rules.d/68-azure-sriov-nm-unmanaged.rules,并将其添加到其中。

      SUBSYSTEM=="net", DRIVERS=="hv_pci", ACTION=="add", ENV{NM_UNMANAGED}="1"
  7. sshd 服务设置为自动启动。

    # systemctl enable sshd
    # systemctl is-enabled sshd
  8. 修改内核引导参数:

    1. 打开 /etc/default/grub 文件,并确保 GRUB_TIMEOUT 行具有以下值:

      GRUB_TIMEOUT=10
    2. GRUB_CMDLINE_LINUX 行末尾删除以下选项(如果存在)。

      rhgb quiet
    3. 确保 /etc/default/grub 文件含有所有指定选项的以下行:

      GRUB_CMDLINE_LINUX="loglevel=3 crashkernel=auto console=tty1 console=ttyS0 earlyprintk=ttyS0 rootdelay=300"
      GRUB_TIMEOUT_STYLE=countdown
      GRUB_TERMINAL="serial console"
      GRUB_SERIAL_COMMAND="serial --speed=115200 --unit=0 --word=8 --parity=no --stop=1"
    4. 重新生成 grub.cfg 文件。

      # grub2-mkconfig -o /boot/grub2/grub.cfg --update-bls-cmdline

      如果您的系统对 grub.cfg 使用非默认位置,请相应地调整该命令。

  9. 配置 Windows Azure Linux 代理 (WALinuxAgent):

    1. 安装并启用 WALinuxAgent 软件包。

      # dnf install WALinuxAgent -y
      # systemctl enable waagent
    2. 要确保在置备的虚拟机中没有使用交换分区,请编辑 /etc/waagent.conf 文件中的以下行:

      Provisioning.DeleteRootPassword=y
      ResourceDisk.Format=n
      ResourceDisk.EnableSwap=n
  10. 为 Azure 置备准备虚拟机:

    1. 从 Red Hat Subscription Manager 取消注册虚拟机。

      # subscription-manager unregister
    2. 清理现有的置备详情。

      # waagent -force -deprovision
      注意

      这个命令会生成警告,因为 Azure 会自动处理虚拟机的置备。

    3. 清理 shell 历史记录并关闭虚拟机。

      # export HISTSIZE=0
      # poweroff