Installing Cloud-Init

Scenarios

To ensure that you can use the user data injection function to inject initial custom information into ECSs created from a private image (such as setting the ECS login password), install Cloud-Init on the ECS used to create the image.

Prerequisites

Procedure

  1. Check whether Cloud-Init has been installed.

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

  2. Install Cloud-Init.

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

Check Whether Cloud-Init Has Been Installed

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

The methods of checking whether Cloud-Init is installed vary depending on the OSs. Take CentOS 6 as an example. Run the following command to check whether Cloud-Init is installed:

rpm -qa |grep cloud-init

If information similar to the following is displayed, Cloud-Init has been installed:

cloud-init-0.7.5-10.el6.centos.2.x86_64
If Cloud-Init has been installed, perform the following operations:
  • Check whether 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, for example, /$path/$to/$root/.ssh/authorized_keys, run the following commands:

      cd /root/.ssh

      rm authorized_keys

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

      cd /home/centos/.ssh

      rm authorized_keys

  • Run the following command to delete the cache generated by Cloud-Init and ensure that the ECS created from the private image can be logged in by using the certificate:

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

Do not restart the ECS after performing the configuration. Otherwise, you need to configure it again.

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

The method of installing Cloud-Init on an ECS varies depending on the OS. Perform the installation operations as user root.

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

Install 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.9 is recommended) and upload it to the /home/ directory of 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:

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

    [global]
    index-url  = https://<$mirror>/simple/
    trusted-host = <$mirror>

    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 source code package (select --upgrade as needed during installation):

    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 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

    usermod -g adm syslog

  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: sles, distro: debian, and distro: fedora.