To ensure that the ECS instance running a custom image can initialize the configurations, we recommend that you install cloud-init on the source server when you create the custom Linux image. This topic describes how to install Alibaba Cloud cloud-init and the native cloud-init.
Background information
cloud-init is open-source software used by cloud platforms to initialize Linux virtual machines. All major public cloud platforms such as Alibaba Cloud, Amazon Web Services (AWS), Microsoft Azure, and OpenStack support cloud-init. Alibaba Cloud cloud-init initializes the configurations of instances when the system is starting up and executes user data scripts. These configurations include NTP, software repositories, hostnames, and SSH key pairs. For more information, visit cloud-init Documentation.
- Linux servers will be migrated to the cloud but are not installed with cloud-init.
Note Proceed with caution when you install Alibaba Cloud cloud-init on servers that you do not plan to migrate to the cloud.
- Linux servers are installed with cloud-init of versions earlier than 0.7.9.
- Alibaba Cloud ECS instances are not installed with cloud-init.
Description
Different cloud platforms may use different versions of cloud-init. Select an appropriate
version and configure it with the appropriate data source (datasource). The latest version of Alibaba Cloud cloud-init is 19.1.2, and the data source is
Aliyun
.
Aliyun
.
- 0.7.6a: the initial version of Alibaba Cloud cloud-init, which depends on Python 2.7
for the Python environment. Some early public images still use cloud-init 0.7.6a.
If you need to install cloud-init 0.7.6a for your images, see the (Optional) Install Alibaba Cloud cloud-init 0.7.6a15 section.
Note The Python community no longer provides technical support for Python 2.7. Therefore, we recommend that you use later versions of cloud-init to avoid potential risks associated with dependency libraries.
- 0.7.9 and earlier: initial versions of the native cloud-init, which are not applicable to initializing ECS instances and must be upgraded.
- 18: cloud-init 18 and later automatically initialize network configurations. The code
for network configuration is
BOOTPROTO=dhcp DEVICE=eth0 ONBOOT=yes STARTMODE=auto TYPE=Ethernet USERCTL=no
. If you want to customize network configurations after you install cloud-init, see the (Optional) Customize network configuration section. - 19.1: Alibaba Cloud public images are upgrading to be installed with cloud-init 19.1, which depends on Python 3.6 for the Python environment.
Check the cloud-init version
(Recommended) Install Alibaba Cloud cloud-init 19.1.2
Perform the following operations to download cloud-init 19.1.2 whose data source is
Aliyun
:
- CentOS 6 and CentOS 7
# Check whether the python3-pip dependency library is installed. If not, install it. if ! python3 -c 'import setuptools' >& /dev/null; then yum -y install python3-pip fi # Back up cloud-init of an earlier version. test -d /etc/cloud && mv /etc/cloud /etc/cloud-old # Download and decompress Alibaba Cloud cloud-init. wget https://ecs-image-utils.oss-cn-hangzhou.aliyuncs.com/cloudinit/cloud-init-19.1.2.tgz tar -zxvf ./cloud-init-19.1.2.tgz # Install cloud-init. issue_major=$( cat /etc/redhat-release | grep -Eo '[0-9]+\.?[ 0-9]+' | head -1 | awk -F'.' '{printf $1}') bash ./cloud-init-*/tools/deploy.sh centos "$issue_major"
- Red Hat Enterprise Linux 6 and Red Hat Enterprise Linux 7
# Check whether the python3-pip dependency library is installed. If not, install it. if ! python3 -c 'import setuptools' >& /dev/null; then yum -y install python3-pip fi # Back up cloud-init of an earlier version. test -d /etc/cloud && mv /etc/cloud /etc/cloud-old # Download and decompress Alibaba Cloud cloud-init. wget https://ecs-image-utils.oss-cn-hangzhou.aliyuncs.com/cloudinit/cloud-init-19.1.2.tgz tar -zxvf ./cloud-init-19.1.2.tgz # Install cloud-init. issue_major=$( cat /etc/os-release | grep VERSION_ID | grep -Eo '[0-9]+\.?[ 0-9]+' | head -1 | awk -F'.' '{printf $1}') bash ./cloud-init-*/tools/deploy.sh rhel "$issue_major"
- Ubuntu 14, Ubuntu 16, and Ubuntu 18
# Check whether the python3-pip dependency library is installed. If not, install it. if ! python3 -c 'import setuptools' >& /dev/null; then apt-get install python36 python3-pip -y fi # Back up cloud-init of an earlier version. test -d /etc/cloud && mv /etc/cloud /etc/cloud-old # Download and decompress Alibaba Cloud cloud-init. wget https://ecs-image-utils.oss-cn-hangzhou.aliyuncs.com/cloudinit/cloud-init-19.1.2.tgz tar -zxvf ./cloud-init-19.1.2.tgz # Install cloud-init. issue_major=$( cat /etc/os-release | grep VERSION_ID | grep -Eo '[0-9]+\.?[ 0-9]+' | head -1 | awk -F'.' '{printf $1}') bash ./cloud-init-*/tools/deploy.sh ubuntu "$issue_major"
- Debian 8 and Debian 9
# Check whether the python3-pip dependency library is installed. If not, install it. if ! python3 -c 'import setuptools' >& /dev/null; then apt-get -y install python3-pip fi # Back up cloud-init of an earlier version. test -d /etc/cloud && mv /etc/cloud /etc/cloud-old # Download and decompress Alibaba Cloud cloud-init. wget https://ecs-image-utils.oss-cn-hangzhou.aliyuncs.com/cloudinit/cloud-init-19.1.2.tgz tar -zxvf ./cloud-init-19.1.2.tgz # Install cloud-init. issue_major=$( cat /etc/os-release | grep VERSION_ID | grep -Eo '[0-9]+\.?[ 0-9]+' | head -1 | awk -F'.' '{printf $1}') bash ./cloud-init-*/tools/deploy.sh debian "$issue_major"
- SUSE 11 and SUSE 12
# Check whether the python3-pip dependency library is installed. If not, install it. if ! python3 -c 'import setuptools'>& /dev/null; then zypper -n install python3-pip fi # Back up cloud-init of an earlier version. test -d /etc/cloud && mv /etc/cloud/etc/cloud-old # Download and decompress Alibaba Cloud cloud-init. wget https://ecs-image-utils.oss-cn-hangzhou.aliyuncs.com/cloudinit/cloud-init-19.1.2.tgz tar -zxvf ./cloud-init-19.1.2.tgz # Install cloud-init. issue_major=$( cat /etc/os-release | grep VERSION_ID | grep -Eo '[0-9]+\.?[ 0-9]+' | head -1 | awk -F'.' '{printf $1}') bash ./cloud-init-*/tools/deploy.sh sles "$issue_major"
- openSUSE 13 and openSUSE 42
# Check whether the python3-pip dependency library is installed. If not, install it. if ! python3 -c 'import setuptools'>& /dev/null; then zypper -n install python3-pip fi # Back up cloud-init of an earlier version. test -d /etc/cloud && mv /etc/cloud/etc/cloud-old # Download and decompress Alibaba Cloud cloud-init. wget https://ecs-image-utils.oss-cn-hangzhou.aliyuncs.com/cloudinit/cloud-init-19.1.2.tgz tar -zxvf ./cloud-init-19.1.2.tgz # Install cloud-init. issue_major=$( cat /etc/os-release | grep VERSION_ID | grep -Eo '[0-9]+\.?[ 0-9]+' | head -1 | awk -F'.' '{printf $1}') bash ./cloud-init-*/tools/deploy.sh opensuse"$issue_major"
(Optional) Install Alibaba Cloud cloud-init 0.7.6a15
cloud-init-0.7.6a15.tgz
. If you need to test how to install cloud-init-0.7.6a15.tgz, run the mv /etc/cloud/cloud.cfg /etc/cloud/cloud.cfg_bak command to back up files in the images.
(Optional) Install the native cloud-init
(Optional) Customize network configuration
Troubleshooting
- The libraries that are missing may vary based on images. You can use pip to install the libraries and then install cloud-init again.
- If the default software package manager (such as YUM) and the pip manager are installed with different versions of dependency libraries, library version conflicts may occur and cause cloud-init to run abnormally. We recommend that you download the dependency libraries based on the error message.
Error message | Cause | Troubleshooting command |
---|---|---|
no setuptools module in python |
The python setuptools module is not installed. | Python 3.6 is used in the following examples:
|
File "/root/cloud-init/cloudinit/log.py", line 19, in <module> import six ImportError: No module named six ) |
The six dependency library is not installed. |
|
File "/root/cloud-init/cloudinit/url_helper.py", line 20, in <module> import oauthlib.oauth1 as oauth1 ImportError: No module named oauthlib.oauth1 ) |
The oauthlib dependency library is not installed. |
|
No uninstalled dependency libraries specified | The error message is not mapped. | Run the following command to install all dependency libraries that are listed in the
requirements.txt file of cloud-init:
|
What to do next
- For Linux servers that will be migrated to the cloud:
You can migrate the servers by using the Cloud Migration tool or importing the custom images. For more information, see Migrate a server to Alibaba Cloud by using the Cloud Migration tool or Import custom images.
- For Alibaba Cloud ECS instances that already run Linux custom images:
You can restart the system to check the installation result. If the system automatically configures the hostname, software repositories, and NTP, cloud-init is installed. For example, if the network configuration file shows the following result, cloud-init is installed:
[root@iZbp1ios3psx4hoi******Z ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0 # Created by cloud-init on instance boot automatically, do not edit. # BOOTPROTO=dhcp DEVICE=eth0 ONBOOT=yes STARTMODE=auto TYPE=Ethernet USERCTL=no