• Image Management Service

ims
  1. Help Center
  2. Image Management Service
  3. User Guide
  4. Creating a Private Image
  5. Creating a System Disk Image Using a Linux ECS
  6. Installing Cloud-Init

Installing Cloud-Init

Scenarios

You are advised to install Cloud-Init on the ECS that will be used to create a private image so that new ECSs created from the private image support custom configurations.

  • Cloud-Init must be downloaded from the official website. Therefore, you need to bind an EIP to the ECS for accessing the Internet.
  • If you do not install Cloud-Init, you can log in to the ECS only with the original image password, and you will be unable to customize ECS configurations.
  • By default, ECSs created from a public image already have Cloud-Init installed. You do not need to install and configure Cloud-Init again.
  • For ECSs created from an external image file, you must install and configure Cloud-Init by following the instructions in this section. For how to configure Cloud-Init, see Configuring Cloud-Init.

Prerequisites

  • An EIP has been bound to the ECS.
  • You have logged in to the ECS.
  • DHCP has been configured for the NICs to automatically obtain an IP address.

Installation Methods

  1. Check whether Cloud-Init has been installed.

    For details, see Checking Whether Cloud-Init Has Been Installed.

  2. Install Cloud-Init.

    You can install Cloud-Init using either of the following methods: (Recommended) Installing Cloud-Init Using the Official Installation Package and Installing Cloud-Init Using the Official Source Code Package and pip.

Checking Whether Cloud-Init Has Been Installed

Perform the operations provided here to check whether Cloud-Init has been installed.

The methods for checking the Cloud-Init installation vary depending on the OSs. CentOS 6 is used as an example. Run the following command to check whether Cloud-Init has been installed:

rpm -qa |grep cloud-init

  • Cloud-Init has been installed if the following information is displayed:
    cloud-init-0.7.5-10.el6.centos.2.x86_64
    • Check whether to continue to use the certificate in the ECS OS. If the certificate is no longer used, delete it.
      • If the certificate is stored in a directory of user root, such as .ssh/authorized_keys in the /$path/$to/$root directory, run the following commands:

        cd /root/.ssh

        rm authorized_keys

      • If the certificate is not stored in a directory of user root, for example, certificate .ssh/authorized_keys in the /$path/$to/$none-root directory, run the following commands:

        cd /home/centos/.ssh

        rm authorized_keys

    • Run the following command to verify that you can use certificates to log in to ECSs created using the Linux image:

      sudo rm -rf /var/lib/cloud/*

    NOTE:

    After the configuration, do not restart the ECS. Otherwise, you have to perform the configuration again.

(Recommended) Installing Cloud-Init Using the Official Installation Package

The methods of installing Cloud-Init on ECSs vary depending on the OSs. You must perform the installation operations as user root.

The following describes how to install Cloud-Init on ECSs running SUSE Linux, CentOS, Red Hat Linux, Fedora, Debian, and Ubuntu. For other types of OS, install the required type of Cloud-Init. For example, you need to install coreos-cloudinit on ECSs running CoreOS.

  • SUSE Linux

    Paths for obtaining the Cloud-Init installation package for SUSE Linux

    http://ftp5.gwdg.de/pub/opensuse/repositories/Cloud:/Tools/

    http://download.opensuse.org/repositories/Cloud:/Tools/

    NOTE:

    Select the required repo installation package in the provided paths.

    Take SUSE Enterprise Linux Server 11 SP4 as an example. Perform the following steps to install Cloud-Init:

    1. Log in to the ECS to be used to create the Linux private image.
    2. Run the following command to install the network installation source for SUSE Enterprise Linux Server 11 SP4:

      zypper ar http://ftp5.gwdg.de/pub/opensuse/repositories/Cloud:/Tools/SLE_11_SP4/Cloud:Tools.repo

    3. Run the following command to update the network installation source:

      zypper refresh

    4. Run the following command to install Cloud-Init:

      zypper install cloud-init

    5. Run the following commands to enable Cloud-Init to automatically start upon system boot:
      • SUSE 11

      chkconfig cloud-init-local on; chkconfig cloud-init on; chkconfig cloud-config on; chkconfig cloud-final on

      service cloud-init-local status; service cloud-init status; service cloud-config status; service cloud-final status

      • SUSE 12 and openSUSE 12/13/42

      systemctl enable cloud-init-local.service cloud-init.service cloud-config.service cloud-final.service

      systemctl status cloud-init-local.service cloud-init.service cloud-config.service cloud-final.service

      For SUSE and openSUSE, perform the following steps to disable dynamic change of the ECS name:

      1. Run the following command to open the dhcp file using the vi editor:

        vi etc/sysconfig/network/dhcp

      2. Change the value of DHCLIENT_SET_HOSTNAME in the dhcp file to no.
  • CentOS and Red Hat Linux

    Table 1 lists the addresses for obtaining the Cloud-Init installation packages for CentOS and Red Hat Linux. Select the required installation package from the following addresses.

    Table 1 Cloud-Init installation package addresses

    OS Type

    Version

    How to Obtain

    CentOS, Red Hat, or Oracle Linux

    6 32-bit

    https://dl.fedoraproject.org/pub/epel/6/i386/

    6 64-bit

    https://dl.fedoraproject.org/pub/epel/6/x86_64/

    To install Cloud-Init on ECSs running CentOS 6 and 7 series, run the following commands (CentOS 6.5 64bit is used as an example):

    yum install https://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-xx-xx.noarch.rpm

    yum install cloud-init

    NOTE:

    xx-xx indicates the version of Extra Packages for Enterprise Linux (EPEL) required by the current OS.

  • Fedora

    Before installing Cloud-Init, ensure that the network installation source address has been configured for the OS by checking whether the /etc/yum.repo.d/fedora.repo file contains the installation source address of the software package. If the file does not contain the address, configure the address by following the instructions on the Fedora official website.

    Run the following command to install Cloud-Init:

    yum install cloud-init

  • Debian and Ubuntu

    Before installing Cloud-Init, ensure that the network installation source address has been configured for the OS by checking whether the /etc/apt/sources.list file contains the installation source address of the software package. If the file does not contain the address, configure the address by following the instructions on the Debian or Ubuntu official website.

    Run the following commands to install Cloud-Init:

    apt-get update

    apt-get install cloud-init

Installing Cloud-Init Using the Official Source Code Package and pip

The following operations use Cloud-Init 0.7.9 as an example to describe how to install Cloud-Init.

  1. Download the cloud-init-0.7.9.tar.gz source code package (version 0.7.5 is recommended) and upload it to the /home/ directory on the ECS.

    Download cloud-init-0.7.9.tar.gz from the following path:

    https://launchpad.net/cloud-init/trunk/0.7.9/+download/cloud-init-0.7.9.tar.gz

  2. Create a pip.conf file in the ~/.pip/ directory and edit the following content:
    NOTE:

    If the ~/.pip/ directory does not exist, run the mkdir ~/.pip command to create it.

    [global]

    index-url = https://<$mirror>/simple/

    trusted-host = <$mirror>

    NOTE:

    Replace <$mirror> with a public network PyPI source.

    Public network PyPI source: https://pypi.python.org/

  3. Run the following command to install the downloaded cloud-init-0.7.5.tar.gz source code package (during installation, select --upgrade):

    # pip install [--upgrade] /home/cloud-init-0.7.9.tar.gz

  4. Run the cloud-init -v command. Cloud-Init is installed successfully if the following information is displayed:
    cloud-init 0.7.9
  5. Enable Cloud-Init to automatically start upon system boot.
    • If the OS uses SysVinit to manage automatic start of services, run the following commands:

      # chkconfig --add cloud-init-local; chkconfig --add cloud-init; chkconfig --add cloud-config; chkconfig --add cloud-final

      # chkconfig cloud-init-local on; chkconfig cloud-init on; chkconfig cloud-config on; chkconfig cloud-final on

      # service cloud-init-local status; service cloud-init status; service cloud-config status; service cloud-final status

    • If the OS uses Systemd to manage automatic start of services, run the following commands:

      # systemctl enable cloud-init-local.service cloud-init.service cloud-config.service cloud-final.service

      # systemctl status cloud-init-local.service cloud-init.service cloud-config.service cloud-final.service

If you install Cloud-Init using the official source code package and pip, pay attention to the following:

  1. Add user syslog to the adm group during the installation. If user syslog exists, add it to the adm group. For some OSs, such as Red Hat, CentOS, and SUSE, user syslog may not exist. Run the following commands to create user syslog and add it to the adm group:

    useradd syslog

    groupadd adm

  2. Change the value of distro in system_info in the /etc/cloud/cloud.cfg file based on the OS release version, such as distro: ubuntu, distro: rhel, distro: sles, distro: debian, and distro: fedora.