第 2 章 创建 RHEL KVM 或 RHOSP 兼容镜像

要创建可在 Red Hat OpenStack Platform (RHOSP)镜像服务(glance)中管理的镜像,您可以使用 Red Hat Enterprise Linux (RHEL)基于内核的虚拟机(KVM)实例镜像,也可以使用 RHEL ISO 文件或 Windows ISO 文件手动创建与 RHOSP 兼容的镜像。

2.1. 创建 RHEL KVM 镜像

使用 Red Hat Enterprise Linux (RHEL)基于内核的虚拟机(KVM)实例镜像来创建您可以在 Red Hat OpenStack Platform (RHOSP)镜像服务(glance)中管理的镜像。

2.1.1. 在 Red Hat OpenStack Platform 中使用 RHEL KVM 实例镜像

您可以在 Red Hat OpenStack Platform (RHOSP)中使用以下 Red Hat Enterprise Linux (RHEL)基于内核的虚拟机(KVM)实例镜像之一:

这些 QCOW2 镜像使用 cloud-init 配置,且必须具有与 EC2 兼容的元数据服务才能置备 Secure Shell (SSH)密钥才能正常工作。

QCOW2 格式的就绪 Windows KVM 实例镜像不可用。

注意

对于 KVM 实例镜像:

  • 镜像中的 root 帐户将被停用,但 sudo 访问权限被授予一个名为 cloud-user 的特殊用户。
  • 此镜像没有设置 root 密码。

通过将 !! 放置到第二个字段中,将 root 密码锁定在 /etc/shadow 中。

对于 RHOSP 实例,从 RHOSP 仪表板或命令行生成 SSH 密钥对,并使用该组合键以 root 用户身份对实例执行 SSH 公共身份验证。

当您启动实例时,此公钥会注入到其中。然后,您可以使用您在创建密钥对时下载的私钥进行身份验证。

2.1.2. 为裸机实例创建基于 RHEL 的根分区镜像

要为裸机实例创建自定义根分区镜像,请下载基本 Red Hat Enterprise Linux KVM 实例镜像,然后将镜像上传到镜像服务(glance)。

流程

  1. 从客户门户网站下载 基本 Red Hat Enterprise Linux KVM 实例镜像。
  2. 定义 DIB_LOCAL_IMAGE 作为下载的镜像:

    $ export DIB_LOCAL_IMAGE=rhel-<ver>-x86_64-kvm.qcow2
    • <ver > 替换为镜像的 RHEL 版本号。
  3. 根据您的注册方法设置您的注册信息:

    • 红帽客户门户网站:

      $ export REG_USER='<username>'
      $ export REG_PASSWORD='<password>'
      $ export REG_AUTO_ATTACH=true
      $ export REG_METHOD=portal
      $ export https_proxy='<IP_address:port>' (if applicable)
      $ export http_proxy='<IP_address:port>' (if applicable)
    • Red Hat Satellite:

      $ export REG_USER='<username>'
      $ export REG_PASSWORD='<password>'
      $ export REG_SAT_URL='<satellite-url>'
      $ export REG_ORG='<satellite-org>'
      $ export REG_ENV='<satellite-env>'
      $ export REG_METHOD=<method>
    • 将尖括号 & lt;> 中的值替换为您的红帽客户门户网站或 Red Hat Satellite 注册的正确值。
  4. 可选:如果您有任何离线存储库,您可以将 DIB_YUM_REPO_CONF 定义为本地存储库配置:

    $ export DIB_YUM_REPO_CONF=<file-path>
    • <file-path > 替换为本地存储库配置文件的路径。
  5. 使用 diskimage-builder 工具将内核提取为 rhel-image.vmlinuz,初始 RAM 磁盘为 rhel-image.initrd

    $ export DIB_RELEASE=<ver>
    $ disk-image-create rhel baremetal \
      -o rhel-image
  6. 将镜像上传到镜像服务:

    $ KERNEL_ID=$(openstack image create \
      --file rhel-image.vmlinuz --public \
      --container-format aki --disk-format aki \
      -f value -c id rhel-image.vmlinuz)
    $ RAMDISK_ID=$(openstack image create \
      --file rhel-image.initrd --public \
      --container-format ari --disk-format ari \
      -f value -c id rhel-image.initrd)
    $ openstack image create \
      --file rhel-image.qcow2   --public \
      --container-format bare \
      --disk-format qcow2 \
      --property kernel_id=$KERNEL_ID \
      --property ramdisk_id=$RAMDISK_ID \
      rhel-root-partition-bare-metal-image

2.1.3. 为裸机实例创建基于 RHEL 的整个磁盘用户镜像

要为裸机实例创建完整磁盘用户镜像,请下载基本 Red Hat Enterprise Linux KVM 实例镜像,然后将镜像上传到镜像服务(glance)。

流程

  1. 从客户门户网站下载 基本 Red Hat Enterprise Linux KVM 实例镜像。
  2. 定义 DIB_LOCAL_IMAGE 作为下载的镜像:

    $ export DIB_LOCAL_IMAGE=rhel-<ver>-x86_64-kvm.qcow2
    • <ver > 替换为镜像的 RHEL 版本号。
  3. 根据您的注册方法设置您的注册信息:

    • 红帽客户门户网站:

      $ export REG_USER='<username>'
      $ export REG_PASSWORD='<password>'
      $ export REG_AUTO_ATTACH=true
      $ export REG_METHOD=portal
      $ export https_proxy='<IP_address:port>' (if applicable)
      $ export http_proxy='<IP_address:port>' (if applicable)
    • Red Hat Satellite:

      $ export REG_USER='<username>'
      $ export REG_PASSWORD='<password>'
      $ export REG_SAT_URL='<satellite-url>'
      $ export REG_ORG='<satellite-org>'
      $ export REG_ENV='<satellite-env>'
      $ export REG_METHOD=<method>
    • 将尖括号 & lt;> 中的值替换为您的红帽客户门户网站或 Red Hat Satellite 注册的正确值。
  4. 可选:如果您有任何离线存储库,您可以将 DIB_YUM_REPO_CONF 定义为本地存储库配置:

    $ export DIB_YUM_REPO_CONF=<file-path>
    • <file-path > 替换为本地存储库配置文件的路径。
  5. 将镜像上传到镜像服务:

    $ openstack image create \
      --file rhel-image.qcow2 --public \
      --container-format bare \
      --disk-format qcow2 \
      rhel-whole-disk-bare-metal-image