你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

为 Ubuntu Server 18.04 创建 VMware vSphere 模板

本文提供有关创建 Ubuntu Server 18.04 VMware vSphere 虚拟机模板的指南。

先决条件

注意

本指南假定你对 VMware vSphere 有一些了解。 指南的目的并非查看 VMware 或 Ubuntu 最佳做法。

创建 Ubuntu 18.04 VM 模板

部署和安装 Ubuntu

  • 部署新虚拟机

    A screenshot of how to create a new VMware vSphere virtual machine.

    Second screenshot of how to create a new VMware vSphere virtual machine.

    Third screenshot of how to create a new VMware vSphere virtual machine.

    Fourth screenshot of how to create a new VMware vSphere virtual machine.

    Fifth screenshot of how to create a new VMware vSphere virtual machine.

    Sixth screenshot of how to create a new VMware vSphere virtual machine.

  • 确保选择“Ubuntu Linux (64 位)”作为来宾 OS。

    A screenshot of Ubuntu Linux (64-bit) guest OS.

  • 指向 Ubuntu Server ISO 文件位置。

    Seventh screenshot of how to create a new VMware vSphere virtual machine.

    Eighth screenshot of how to create a new VMware vSphere virtual machine.

  • 打开 VM 并开始安装 Ubuntu。 此处没有具体说明,但需注意以下项:

    • 考虑使用静态 IP 地址

    • 安装 OpenSSH 服务器

      First screenshot of an Ubuntu installation

      Second screenshot of an Ubuntu installation.

      Third screenshot of an Ubuntu installation.

      Fourth screenshot of an Ubuntu installation.

      Fifth screenshot of an Ubuntu installation.

      Sixth screenshot of an Ubuntu installation.

      Seventh screenshot of an Ubuntu installation.

      Eighth screenshot of an Ubuntu installation.

      Ninth screenshot of an Ubuntu installation.

      Tenth screenshot of an Ubuntu installation.

      Eleventh screenshot of an Ubuntu installation.

      Twelfth screenshot of an Ubuntu installation.

      Thirteenth screenshot of an Ubuntu installation.

      Fourteenth screenshot of an Ubuntu installation.

      Fifteenth screenshot of an Ubuntu installation.

      Sixteenth screenshot of an Ubuntu installation.

      Seventeenth screenshot of an Ubuntu installation.

      Eighteenth screenshot of an Ubuntu installation.

      Nineteenth screenshot of an Ubuntu installation.

      Twentieth screenshot of an Ubuntu installation.

      Twenty-first screenshot of an Ubuntu installation.

安装后

在将 VM 转换为模板之前,需执行几项操作。

  • 更新 OS 包:

    sudo apt-get update
    sudo apt-get upgrade -y
    
  • 防止 cloudconfig 保留原始主机名,并重置主机名:

    sudo sed -i 's/preserve_hostname: false/preserve_hostname: true/g' /etc/cloud/cloud.cfg
    sudo truncate -s0 /etc/hostname
    sudo hostnamectl set-hostname localhost
    
  • 删除当前网络配置:

    sudo rm /etc/netplan/50-cloud-init.yaml
    
  • 清理 shell 历史记录并关闭 VM:

    cat /dev/null > ~/.bash_history && history -c
    sudo shutdown now
    

转换为模板

将 VM CPU 计数和内存资源降至最低,并将 VM 转换为模板;将 CD/DVD 驱动器切换到客户端设备,同时断开连接,并将 VM 转换为模板。

A screenshot of how to reduce a virtual machine's CPU count and memory.

A screenshot of how to convert a virtual machine to a template.