Environment Preparation

Prerequisites

To encapsulate a CentOS 8 template, obtain an ISO image in advance and add it to ZStack Cloud. Notice the following points when you perform this operation:
  • You need to obtain a CentOS 8 installation image from the official website by yourself. Ensure your compliance of relevant authorizations and permissions.
  • This Tutorial references CentOS-8.4.2105-x86_64-DVD1.iso.

About this task

To prepare for CentOS 8 template encapsulation, follow these steps:
  1. Add an installation image.
  2. Create a disk offering.

Procedure

  1. Add an installation image.

    On the main menu of ZStack Cloud, choose Resource Center > Resource Pool > Compute Configuration > Image. On the Image page, click Add Image. Then, the Add Image page is displayed.

    On the displayed page, set the following parameters:
    • Name: Enter a name for the image.
    • Description: Optional. Enter a description for the image.
    • Image Type: Select an image type. Here, select System Image.
    • Image Format: Select an image format. Here, Select iso.
    • CPU Architecture: Select a CPU architecture for the image. VM instances created from the image use this CPU architecture.
    • Platform: Select an image platform. Here, select Linux.
    • OS: Select an operating system that is consistent with the image.
    • VirtIO: Choose whether to enable VirtIO according to your actual operating system and platform. Here, enable VirtIO.
    • Backup Storage: Select a backup storage added before.
    • Image Path: Specify an image URL or upload a local file.
      • URL: Enter a specified URL to add an image. You can enter a URL by using either of the following syntax:
        • A URL starting with http or https:
          • Syntax: http://host[:port]/path/file or https://host[:port]/path/file.
        • A URL starting with ftp:
          • Syntax that does not specify the user: ftp://hostname[:port]/path/file.
          • Syntax that specifies the user: ftp://user:password@hostname[:port]/path/file.
        • A URL starting with sftp:
          • Syntax that specifies the user identity: sftp://user:password@hostname[:port]/path/file.
          • User-identity-free syntax: sftp://user@hostname[:port]/path/file.
        • The absolute path of an image file that is stored on a backup storage. The backup storage can be an ImageStore backup storage.

          Syntax: file:///path/file.

        Note:
        • Make sure that the URL entered is accessible to the backup storage and the image file exists.
        • When using a URL that starts with stfp and does not specify user identity, make sure that you enable mutual password-free SSH login between the backup storage and the SFTP server.
        • For the progress bar and resumption from breakpoints features:
          • Both ImageStore and Ceph backup storages support a progress bar to display the upload progress. And both ImageStore and Ceph backup storages support the resumption from breakpoints.
        • If you specify a URL with the file:/// syntax to add an image:
          • Ceph backup storage does not support the file:/// syntax currently.
          • The three forward slashes (/) in file:/// represents the absolute path of a file on a backup storage. For example, if you want to specify the URL file:///opt/dvd/image-1.4.qcow2, the /opt/dvd path of the backup storage must contain such a file named image-1.4.qcow2.
      • Local file: Select a local image file that the current browser can access to and upload the image file to the specified backup storage. The backup storage that stores the image file can be an ImageStore or a Ceph backup storage.
        Note: When you add a local file as an image, your local browser is serving as a transit point to upload the image. Do not refresh or close the current browser, nor stop the service of the management node. Otherwise, the operation may fail.
    • BIOS Mode: Select a BIOS mode. Here, select Legacy.
    Figure 1. Add an Image


  2. Create a disk offering.

    On the main menu of ZStack Cloud, choose Resource Center > Resource Pool > Compute Configuration > Disk Offering. On the Disk Offering page, click Create Disk Offering. Then, the Create Disk Offering page is displayed.

    On the displayed page, set the following parameters:
    • Name: Enter a name for the disk offering.
    • Description: Optional. Enter a description for the disk offering.
    • Disk Size: Set the capacity of a volume.
      Note: Select an appropriate disk size as needed. This disk size will serve to create the system disks for the CentOS 8 VM instances.
      • If you are installing a command line interface of CentOS 8, we recommend that you choose a disk size greater or equal to 40 GB.
      • If you are installing a graphical interface of CentOS 8 (GNOME), we recommend that you choose a disk size greater or equal to 60 GB.
    • Set Disk Bandwidth: Optional. Set an upper limit for the I/O bandwidth of a volume.
    • Set Disk IOPS: Optional. Set an upper limit of the disk reads/writes per second (IOPS).
    • Advanced Parameter: Optional. You can set this parameter by configuring a JSON file.
    Figure 2. Create a Disk Offering


Template

Install an Operating System

About this task

To install an operating system, follow these steps:
  1. Create a VM instance.
  2. Install CentOS 8.

Procedure

  1. Create a VM instance.
    For the detailed information about how to create a VM instance on ZStack Cloud, and how to use an installation image to boot the VM instance, see the chapter "Create a VM Instance" in User Guide.
    Note: To install and apply CentOS 8, make sure that you choose a memory of at least 2 GB for the VM instance. We recommend that you choose a memory greater or equal to 4 GB.
  2. Install CentOS 8.
    1. Select the boot item.

      Launch the VM console, and the CentOS 8 installation page appears. Then, select Install CentOS Linux 8 to begin the operating system installation.

      Figure 3. CentOS 8 Installation Page


    2. Choose an installation language.

      This tutorial chooses English as the default language for the installer and the system. You can choose other languages as needed.

    3. Configure parameters on the INSTALLATION SUMMARY page.
      This page displays system installation configurations. You can set the following configurations based on your needs:
      • LOCALIZATION: Set the keyboard, language, and time zone for the system.
      • SOFTWARE: Select the installation source and software.
      • SYSTEM: Set the installation destination, network, host name, and security policy. Select whether to enable Kdump.
      • USER SETTINGS: Set the root password. Complete the user creation.
      Figure 4. Installation Summary


    4. (Optional) Configure disk partitioning.

      This tutorial selects Automatically configure partitioning to complete the installation. If you want to customize partitioning, click INSTALLATION DESTINATION on the INSTALLATION SUMMARY page, and begin customized configuration on the INSTALLATION DESTINATION page.

      Figure 5. Disk Partitioning


    5. Install the system.

      After finishing disk partitioning, go back to the INSTALLATION SUMMARY page, and click Begin Installation at the bottom right of the page to begin system installation. After finishing system installation, click Reboot to restart the system. Then, click I accept the license agreement to enter the system.

Configure the Template System

About this task

To configure the template system, follow these steps:
  1. Specify the hostname.
  2. Configure the network.
  3. Install the QEMU Guest Agent.
  4. (Optional) Install the cloud-init.
  5. (Optional) Install the GuestTools.
  6. (Optional) Close vulnerability patches.

Procedure

  1. Specify the hostname.

    In the CentOS 8, run hostnamectl set-hostname localhost.localdomain && bash. This command specifies the hostname of the VM instance created with the template as the IP address of the NIC.

  2. Configure the network.
    To enable the VM instance created with the template to automatically obtain an IP address, you need to modify the NIC configurations. Run the following commands:
    [root@localhost ~]# sed -i '/ONBOOT=/cONBOOT=yes' /etc/sysconfig/network-scripts/ifcfg-ens3     #Set the NIC to be activated automatically at boot
    [root@localhost ~]# sed -i '/^UUID'/d /etc/sysconfig/network-scripts/ifcfg-ens3    #Delete the UUID in the NIC configuration file
    [root@localhost ~]# sed -i '/^HWADDR'/d /etc/sysconfig/network-scripts/ifcfg-ens3    #Delete the MAC in the NIC configuration file
  3. Install the QEMU Guest Agent.
    1. Run yum install qemu-guest-agent -y to install the QGA.
      Note: You can also install the QEMU Guest Agent for a CentOS 8.0 VM instance by installing the VM GuestTools. For detailed information, see (Optional) Install the GuestTools.
    2. Run systemctl enable qemu-guest-agent to enable the QGA whenever the VM instance starts.
    3. Run getenforce to check the status of SELINUX. If it returns Enforcing, run vi /etc/selinux/config to change the status of SELINUX to disabled. Then, save the change and exit.
  4. (Optional) Install the cloud-init.
    To ensure the customized configuration features such as User Data and SSH Public Key are available when you create a VM instance with the template, you need to install the cloud-init before encapsulating the template. We recommend that you install the cloud-init of 0.7.9, 17.1, 19.4 or latter versions. You can select and install the version you need.
    Note: Notice the following points when installing the cloud-init:
    • Please install the versions recommended, otherwise, the User Data or SSH Public Key may become unavailable during VM instance creation.
    • SSH key authentication is disabled by default after you install the cloud-init. If you want to enable the authentication, please run vi /etc/cloud/cloud.cfg to set the value of ssh_pwauth as 1.
  5. (Optional) Install VM GuestTools
    1. Attach GuestTools ISO to the VM instance.
      Click to install GuestTools on the VM details page and install the GuestTools ISO.
    2. Run installation commands.
      Run the following command on the VM instance console to finish the installation.
      [root@localhost ~]# mkdir /mnt/cdrom    #Create a monut point.
      [root@localhost ~]# mount /dev/cdrom /mnt/cdrom    #Attach CD-ROM image.
      [root@localhost ~]# cd /mnt/cdrom/
      bash ./zs-tools-install.sh     #Install GuestTools.
      [root@localhost ~]# cd ~
      umount /mnt/cdrom    #Unmount CD-ROM (optional).
    Note: Notice the following points:
    • Run yum install tar -y to install the tar command before installing the GuestTools.
    • If you attach data volumes to the Linux system image created, do not write the attachment information of the data volumes into /etc/fstab. Otherwise, the VM instances created with this template may fail to start.
    • If you want to attach the data volumes to a VM instance when it starts, we recommend the following method:
      [root@localhost ~]# echo "mount -t ext4 -U "d0shC2-2GO1-Vyuc-XKXf-Pb3c-uvG5-92Fzeu" /mnt" >> /etc/rc.d/rc.local
      [root@localhost ~]# # -t indicates the file system of the disk; -U indicates using UUID to attach the disk;/mnt indicates the mount path
      [root@localhost ~]# # run blkid to obtain the device UUID
      [root@localhost ~]# chmod +x /etc/rc.d/rc.local
      [root@localhost ~]# # We recommend you to attach the disk with the device UUID instead of the disk symbol such as /dev/vdb.
  6. (Optional) Close vulnerability patches.
    For CentOS 8.x, closing the patches for spectre and meltdown can effectively improve the performance of the VM instances. To close the patches, follow these steps:
    1. Check whether the patch is on.
      Run grep . /sys/devices/system/cpu/vulnerabilities/*. You can check whether the patch is on by viewing /sys. For example:
      # grep . /sys/devices/system/cpu/vulnerabilities/*
      /sys/devices/system/cpu/vulnerabilities/itlb_multihit:KVM: Mitigation: Split huge pages
      /sys/devices/system/cpu/vulnerabilities/l1tf:Mitigation: PTE Inversion; VMX: conditional cache flushes, SMT disabled
      /sys/devices/system/cpu/vulnerabilities/mds:Mitigation: Clear CPU buffers; SMT Host state unknown
      /sys/devices/system/cpu/vulnerabilities/meltdown:Mitigation: PTI
      /sys/devices/system/cpu/vulnerabilities/spec_store_bypass:Mitigation: Speculative Store Bypass disabled via prctl and seccomp
      /sys/devices/system/cpu/vulnerabilities/spectre_v1:Mitigation: usercopy/swapgs barriers and __user pointer sanitization
      /sys/devices/system/cpu/vulnerabilities/spectre_v2:Mitigation: Full generic retpoline, IBPB: conditional, IBRS_FW, STIBP: disabled, RSB filling
      /sys/devices/system/cpu/vulnerabilities/srbds:Not affected
      /sys/devices/system/cpu/vulnerabilities/tsx_async_abort:Mitigation: Clear CPU buffers; SMT Host state unknown

      You can check the patch status through the last result returned. Mitigation means that the patch is on, while vulnerable means the patch is closed.

    2. View the vulnerability fix method.
      If the patch is on, check the bug fix method through the last result returned in the previous step. There are two bug fix methods: Retpoline without IBPB and Enhanced IBRS.
      • Retpoline without IBPB: This method has a smaller impact on the performance of the system. You can either close the patch or keep it on. This depends on your needs.
      • Enhanced IBRS: This method has a greater impact on the performance of the system. We recommend that you close the patch to improve the system performance. (The performance can improve by about 30% as measured.)
    3. Close the vulnerability patch.
      To close the vulnerability patch, following these steps:
      1. In the /etc/default/grub file, set the value as noibrs noibpb nopti spectre_v2=off nospectre_v1 l1tf=off nospec_store_bypass_disable no_stf_barrier mds=off mitigations=off for the parameter GRUB_CMDLINE_LINUX.
      2. Run grub2-mkconfig > /boot/grub2/grub.cfg to apply the configuration.
      3. Reboot the VM instance to make the configuration effective.
      Refer to the following example:
      [root@10-0-5-87 ~]# cat /etc/default/grub      #view /etc/default/grub file configuration.Make configurations based on your needs.
      GRUB_TIMEOUT=5
      GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
      GRUB_DEFAULT=saved
      GRUB_DISABLE_SUBMENU=true
      GRUB_TERMINAL_OUTPUT="console"
      GRUB_CMDLINE_LINUX="crashkernel=auto rd.lvm.lv=zstack/root rd.lvm.lv=zstack/swap rhgb quiet noibrs noibpb nopti spectre_v2=off nospectre_v1 l1tf=off nospec_store_bypass_disable
              no_stf_barrier mds=off mitigations=off"
      GRUB_DISABLE_RECOVERY="true"
      [root@10-0-5-87 ~]# grub2-mkconfig > /boot/grub2/grub.cfg     #Apply the configuration
      [root@10-0-5-87 ~]# reboot     #Restart the VM instance to make the configuration effective

Create a System Template

About this task

To create a system template, follow these steps:
  1. Create an image.
  2. Export the image.

Procedure

  1. Create an Image.

    On the details page of the VM instance created, choose Actions > Snapshot and Image > Create Image. Then, the Create Image page is displayed.

    On the displayed page, set the following parameters:
    • Name: Enter a name for the image.
    • Description: Optional. Enter a description for the image.
    • Image Type: Select System Image here.
    • Backup Storage: Select a backup storage created before.
    Figure 6. Create an Image


  2. Export the image.
    You can use the image exported to create VM instances on other cloud platforms directly. The method to export images varies according to backup storage types.
    • ImageStore backup storage.

      On the Image page, choose Actions > Export Image. This button helps export the image.

      After generating the image, you can copy the URL of the image exported on the Overview page to download the image. Or, you can copy the URL of the exported image on the Exported page. You can also click Download on the page to download the image directly.

    • Ceph backup storage. If you use a Ceph backup storage, you can export the image on the UI or from the backup storage.
      • Export on the UI:

        On the Image page, choose Actions > Export Image. This button helps export the image.

        After generating the image, you can copy the URL of the image exported on the Overview page to download the image. Or, you can copy the URL of the exported image on the Exported page. You can also click Download on the page to download the image directly.

      • Export from the backup storage:
        1. On the Overview page of the created image, copy Installation Path.
        2. Login to the terminal of the Ceph backup storage, run rbd export to export the image. For example:
          If you obtain the installation path ceph://bak-t-cac5eee23a204c1a914d1743f1584644/7232237c0059409babcd1c7a69452b98, you can run the following commands to export the image:
          [root@ceph-node1 ~]# rbd export bak-t-cac5eee23a204c1a914d1743f1584644/7232237c0059409babcd1c7a69452b98 /root/export-test.qcow2
          [root@ceph-node1 ~]# # bak-t indicates the installation path of the image
          [root@ceph-node1 ~]# # /root/export-test.qcow2 indicates the target path and the file name of the exported image
          Note: The command rbd export does not include such a prefix as ceph://.

What to do next

Now, you have completed the encapsulation of a CentOS 8 system template. You can use this image to create VM instances in bulk.
CentOS 8 Template Tutorial | 4.8.38 | ZStack Cloud · ZCF | ZStack Resource Center