您现在访问的是微软AZURE全球版技术文档网站,若需要访问由世纪互联运营的MICROSOFT AZURE中国区技术文档网站,请访问 https://docs.azure.cn.

为 Azure 准备 SLES 或 openSUSE 虚拟机Prepare a SLES or openSUSE virtual machine for Azure

备注

Azure 具有用于创建和处理资源的两个不同的部署模型:Resource Manager 和经典Azure has two different deployment models for creating and working with resources: Resource Manager and classic. 这篇文章介绍如何使用这两种模型,但 Microsoft 建议大多数最新部署使用 Resource Manager 模型。This article covers using both models, but Microsoft recommends that most new deployments use the Resource Manager model.

先决条件Prerequisites

本文假定已在虚拟硬盘中安装了 SUSE 或 openSUSE Linux 操作系统。This article assumes that you have already installed a SUSE or openSUSE Linux operating system to a virtual hard disk. 存在多个用于创建 .vhd 文件的工具,例如 Hyper-V 等虚拟化解决方案。Multiple tools exist to create .vhd files, for example a virtualization solution such as Hyper-V. 有关说明,请参阅安装 Hyper-V 角色和配置虚拟机For instructions, see Install the Hyper-V Role and Configure a Virtual Machine.

SLES/openSUSE 安装说明SLES / openSUSE installation notes

  • 另请参阅常规 Linux 安装说明,获取更多有关如何为 Azure 准备 Linux 的提示。Please see also General Linux Installation Notes for more tips on preparing Linux for Azure.
  • Azure 不支持 VHDX 格式,仅支持固定大小的 VHDThe VHDX format is not supported in Azure, only fixed VHD. 可使用 Hyper-V 管理器或 convert-vhd cmdlet 将磁盘转换为 VHD 格式。You can convert the disk to VHD format using Hyper-V Manager or the convert-vhd cmdlet.
  • 在安装 Linux 系统时,建议使用标准分区而不是 LVM(通常是许多安装的默认值)。When installing the Linux system it is recommended that you use standard partitions rather than LVM (often the default for many installations). 这会避免 LVM 与克隆 VM 发生名称冲突,特别是在 OS 磁盘需要连接到另一台 VM 以进行故障排除的情况下。This will avoid LVM name conflicts with cloned VMs, particularly if an OS disk ever needs to be attached to another VM for troubleshooting. 如果需要,可以在数据磁盘上使用 LVMRAIDLVM or RAID may be used on data disks if preferred.
  • 不要在操作系统磁盘上配置交换分区。Do not configure a swap partition on the OS disk. 可以配置 Linux 代理,以在临时资源磁盘上创建交换文件。The Linux agent can be configured to create a swap file on the temporary resource disk. 可以在下面的步骤中找到有关此内容的详细信息。More information about this can be found in the steps below.
  • 所有 VHD 的大小必须是 1 MB 的倍数。All of the VHDs must have sizes that are multiples of 1 MB.

使用 SUSE StudioUse SUSE Studio

SUSE Studio 可以轻松地创建和管理 Azure 和 Hyper-V 的 SLES 和 openSUSE 映像。SUSE Studio can easily create and manage your SLES and openSUSE images for Azure and Hyper-V. 这是自定义用户自己的 SUSE 和 openSUSE 映像的推荐方法。This is the recommended approach for customizing your own SLES and openSUSE images.

作为构建用户自己的 VHD 的替代方法,SUSE 也会为 VMDepot 中的 SLES 发布 BYOS(自带订阅)映像。As an alternative to building your own VHD, SUSE also publishes BYOS (Bring Your Own Subscription) images for SLES at VMDepot.

准备 SUSE Linux Enterprise Server 11 SP4Prepare SUSE Linux Enterprise Server 11 SP4

  1. 在 Hyper-V 管理器的中间窗格中,选择虚拟机。In the center pane of Hyper-V Manager, select the virtual machine.
  2. 单击“连接”打开虚拟机窗口。Click Connect to open the window for the virtual machine.
  3. 注册 SUSE Linux Enterprise 系统以允许其下载更新并安装程序包。Register your SUSE Linux Enterprise system to allow it to download updates and install packages.
  4. 使用最新修补程序更新系统:Update the system with the latest patches:

     # sudo zypper update
    
  5. 从 SLES 存储库安装 Azure Linux 代理:Install the Azure Linux Agent from the SLES repository:

     # sudo zypper install WALinuxAgent
    
  6. 在 chkconfig 中检查 waagent 是否设置为“on”,如果不是,请启用它以便自动启动:Check if waagent is set to "on" in chkconfig, and if not, enable it for autostart:

     # sudo chkconfig waagent on
    
  7. 检查 waagent 服务是否正在运行,如果没有,请启动它:Check if waagent service is running, and if not, start it:

     # sudo service waagent start
    
  8. 在 grub 配置中修改内核引导行,以使其包含 Azure 的其他内核参数。Modify the kernel boot line in your grub configuration to include additional kernel parameters for Azure. 为此,请在文本编辑器中打开“/boot/grub/menu.lst”,并确保默认内核包含以下参数:To do this open "/boot/grub/menu.lst" in a text editor and ensure that the default kernel includes the following parameters:

     console=ttyS0 earlyprintk=ttyS0 rootdelay=300
    

    这会确保所有控制台消息都发送到第一个串行端口,从而可以协助 Azure 支持人员调试问题。This will ensure all console messages are sent to the first serial port, which can assist Azure support with debugging issues.

  9. 确认 /boot/grub/menu.lst 和 /etc/fstab 是否都使用其 UUID (by-uuid) 而不是磁盘 ID (by-id) 引用磁盘。Confirm that /boot/grub/menu.lst and /etc/fstab both reference the disk using its UUID (by-uuid) instead of the disk ID (by-id).

    获取磁盘 UUIDGet disk UUID

     # ls /dev/disk/by-uuid/
    

    如果使用了 /dev/disk/by-id/,请使用正确的 uuid 值更新 /boot/grub/menu.lst 和 /etc/fstabIf /dev/disk/by-id/ is used, update both /boot/grub/menu.lst and /etc/fstab with the proper by-uuid value

    更改之前Before change

     root=/dev/disk/by-id/SCSI-xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxxx-part1
    

    更改之后After change

     root=/dev/disk/by-uuid/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
    
  10. 修改 udev 规则,以避免产生以太网接口的静态规则。Modify udev rules to avoid generating static rules for the Ethernet interface(s). 在 Microsoft Azure 或 Hyper-V 中克隆虚拟机时,这些规则可能会引发问题:These rules can cause problems when cloning a virtual machine in Microsoft Azure or Hyper-V:

    # sudo ln -s /dev/null /etc/udev/rules.d/75-persistent-net-generator.rules
    # sudo rm -f /etc/udev/rules.d/70-persistent-net.rules
    
  11. 建议编辑文件“/etc/sysconfig/network/dhcp”,并将 DHCLIENT_SET_HOSTNAME 参数更改为以下值:It is recommended to edit the file "/etc/sysconfig/network/dhcp" and change the DHCLIENT_SET_HOSTNAME parameter to the following:

    DHCLIENT_SET_HOSTNAME="no"DHCLIENT_SET_HOSTNAME="no"

  12. 在“/etc/sudoers”中,注释掉或删除以下行(如果存在):In "/etc/sudoers", comment out or remove the following lines if they exist:

    Defaults targetpw # 要求提供目标用户(即 root)的密码 ALL ALL=(ALL) ALL # 警告!Defaults targetpw # ask for the password of the target user i.e. root ALL ALL=(ALL) ALL # WARNING! 仅将此项与“Defaults targetpw”一起使用!Only use this together with 'Defaults targetpw'!

  13. 请确保已安装 SSH 服务器且已将其配置为在引导时启动。Ensure that the SSH server is installed and configured to start at boot time. 这通常是默认设置。This is usually the default.
  14. 不要在 OS 磁盘上创建交换空间。Do not create swap space on the OS disk.

    Azure Linux 代理可使用在 Azure 上设置后附加到虚拟机的本地资源磁盘自动配置交换空间。The Azure Linux Agent can automatically configure swap space using the local resource disk that is attached to the VM after provisioning on Azure. 请注意,本地资源磁盘是临时磁盘,并可能在取消预配 VM 时被清空。Note that the local resource disk is a temporary disk, and might be emptied when the VM is deprovisioned. 在安装 Azure Linux 代理(请参见前一步骤)后,相应地在 /etc/waagent.conf 中修改以下参数:After installing the Azure Linux Agent (see previous step), modify the following parameters in /etc/waagent.conf appropriately:

    ResourceDisk.Format=y ResourceDisk.Filesystem=ext4 ResourceDisk.MountPoint=/mnt/resource ResourceDisk.EnableSwap=y ResourceDisk.SwapSizeMB=2048 ## 注意:将此项设置为所需的内容。ResourceDisk.Format=y ResourceDisk.Filesystem=ext4 ResourceDisk.MountPoint=/mnt/resource ResourceDisk.EnableSwap=y ResourceDisk.SwapSizeMB=2048 ## NOTE: set this to whatever you need it to be.

  15. 运行以下命令可取消对虚拟机的设置并且对其进行准备以便在 Azure 上进行设置:Run the following commands to deprovision the virtual machine and prepare it for provisioning on Azure:

    sudo waagent -force -deprovisionsudo waagent -force -deprovision

    export HISTSIZE=0export HISTSIZE=0

    logoutlogout

  16. 在 Hyper-V 管理器中单击“操作”->“关闭”。Click Action -> Shut Down in Hyper-V Manager. Linux VHD 现已准备好上传到 Azure。Your Linux VHD is now ready to be uploaded to Azure.

准备 openSUSE 13.1+Prepare openSUSE 13.1+

  1. 在 Hyper-V 管理器的中间窗格中,选择虚拟机。In the center pane of Hyper-V Manager, select the virtual machine.
  2. 单击“连接”打开虚拟机窗口。Click Connect to open the window for the virtual machine.
  3. 在 shell 上,运行命令“zypper lr”。On the shell, run the command 'zypper lr'. 如果此命令返回了类似于下面的输出,则表示已按预期配置了存储库 - 不需要进行任何调整(请注意版本号可能有所不同):If this command returns output similar to the following, then the repositories are configured as expected--no adjustments are necessary (note that version numbers may vary):

     # | Alias                 | Name                  | Enabled | Refresh
     --+-----------------------+-----------------------+---------+--------
     1 | Cloud:Tools_13.1      | Cloud:Tools_13.1      | Yes     | Yes
     2 | openSUSE_13.1_OSS     | openSUSE_13.1_OSS     | Yes     | Yes
     3 | openSUSE_13.1_Updates | openSUSE_13.1_Updates | Yes     | Yes
    

    如果该命令返回“未定义存储库...”,则使用以下命令来添加这些存储库:If the command returns "No repositories defined..." then use the following commands to add these repos:

     # sudo zypper ar -f http://download.opensuse.org/repositories/Cloud:Tools/openSUSE_13.1 Cloud:Tools_13.1
     # sudo zypper ar -f http://download.opensuse.org/distribution/13.1/repo/oss openSUSE_13.1_OSS
     # sudo zypper ar -f http://download.opensuse.org/update/13.1 openSUSE_13.1_Updates
    

    然后,可以通过再次运行命令“zypper lr”验证已添加存储库。You can then verify the repositories have been added by running the command 'zypper lr' again. 如果未启用某个相关的更新存储库,请使用以下命令启用该存储库:In case one of the relevant update repositories is not enabled, enable it with following command:

     # sudo zypper mr -e [NUMBER OF REPOSITORY]
    
  4. 将内核更新为可用的最新版本:Update the kernel to the latest available version:

     # sudo zypper up kernel-default
    

    或使用所有最新修补程序更新系统:Or to update the system with all the latest patches:

     # sudo zypper update
    
  5. 安装 Azure Linux 代理。Install the Azure Linux Agent.

    sudo zypper install WALinuxAgentsudo zypper install WALinuxAgent

  6. 在 grub 配置中修改内核引导行,以使其包含 Azure 的其他内核参数。Modify the kernel boot line in your grub configuration to include additional kernel parameters for Azure. 为此,请在文本编辑器中打开“/boot/grub/menu.lst”,并确保默认内核包含以下参数:To do this, open "/boot/grub/menu.lst" in a text editor and ensure that the default kernel includes the following parameters:

    console=ttyS0 earlyprintk=ttyS0 rootdelay=300console=ttyS0 earlyprintk=ttyS0 rootdelay=300

    这会确保所有控制台消息都发送到第一个串行端口,从而可以协助 Azure 支持人员调试问题。This will ensure all console messages are sent to the first serial port, which can assist Azure support with debugging issues. 此外,从内核引导行删除以下参数(如果它们存在):In addition, remove the following parameters from the kernel boot line if they exist:

    libata.atapi_enabled=0 reserve=0x1f0,0x8libata.atapi_enabled=0 reserve=0x1f0,0x8

  7. 建议编辑文件“/etc/sysconfig/network/dhcp”,并将 DHCLIENT_SET_HOSTNAME 参数更改为以下值:It is recommended to edit the file "/etc/sysconfig/network/dhcp" and change the DHCLIENT_SET_HOSTNAME parameter to the following:

    DHCLIENT_SET_HOSTNAME="no"DHCLIENT_SET_HOSTNAME="no"

  8. 重要提示:在“/etc/sudoers”中,注释掉或删除以下行(如果存在):Important: In "/etc/sudoers", comment out or remove the following lines if they exist:

    Defaults targetpw # 要求提供目标用户(即 root)的密码 ALL ALL=(ALL) ALL # 警告!Defaults targetpw # ask for the password of the target user i.e. root ALL ALL=(ALL) ALL # WARNING! 仅将此项与“Defaults targetpw”一起使用!Only use this together with 'Defaults targetpw'!

  9. 请确保已安装 SSH 服务器且已将其配置为在引导时启动。Ensure that the SSH server is installed and configured to start at boot time. 这通常是默认设置。This is usually the default.
  10. 不要在 OS 磁盘上创建交换空间。Do not create swap space on the OS disk.

    Azure Linux 代理可使用在 Azure 上设置后附加到虚拟机的本地资源磁盘自动配置交换空间。The Azure Linux Agent can automatically configure swap space using the local resource disk that is attached to the VM after provisioning on Azure. 请注意,本地资源磁盘是临时磁盘,并可能在取消预配 VM 时被清空。Note that the local resource disk is a temporary disk, and might be emptied when the VM is deprovisioned. 在安装 Azure Linux 代理(请参见前一步骤)后,相应地在 /etc/waagent.conf 中修改以下参数:After installing the Azure Linux Agent (see previous step), modify the following parameters in /etc/waagent.conf appropriately:

    ResourceDisk.Format=y ResourceDisk.Filesystem=ext4 ResourceDisk.MountPoint=/mnt/resource ResourceDisk.EnableSwap=y ResourceDisk.SwapSizeMB=2048 ## 注意:将此项设置为所需的内容。ResourceDisk.Format=y ResourceDisk.Filesystem=ext4 ResourceDisk.MountPoint=/mnt/resource ResourceDisk.EnableSwap=y ResourceDisk.SwapSizeMB=2048 ## NOTE: set this to whatever you need it to be.

  11. 运行以下命令可取消对虚拟机的设置并且对其进行准备以便在 Azure 上进行设置:Run the following commands to deprovision the virtual machine and prepare it for provisioning on Azure:

    sudo waagent -force -deprovisionsudo waagent -force -deprovision

    export HISTSIZE=0export HISTSIZE=0

    logoutlogout

  12. 确保在启动时运行 Azure Linux 代理:Ensure the Azure Linux Agent runs at startup:

    # sudo systemctl enable waagent.service
    
  13. 在 Hyper-V 管理器中单击“操作”->“关闭”。Click Action -> Shut Down in Hyper-V Manager. Linux VHD 现已准备好上传到 Azure。Your Linux VHD is now ready to be uploaded to Azure.

后续步骤Next steps

现在,可以使用 SUSE Linux 虚拟硬盘在 Azure 中创建新的 Azure 虚拟机了。You're now ready to use your SUSE Linux virtual hard disk to create new virtual machines in Azure. 如果这是第一次将 .vhd 文件上传到 Azure,请参阅创建和上传包含 Linux 操作系统的虚拟硬盘中的步骤 2 和步骤 3。If this is the first time that you're uploading the .vhd file to Azure, see steps 2 and 3 in Creating and uploading a virtual hard disk that contains the Linux operating system.