tencent cloud

Feedback

Installing Cloud-Init on Linux

Last updated: 2024-01-08 09:37:01

    Overview

    This document describes how to install the cloud-init service. Cloud-init allows you to customize configurations during the first initialization of an instance. Options to install cloud-init:

    Prerequisites

    Connect the server that you want to install cloud-init to the public network.

    How It Works

    Download the cloud-init binary package
    Manual download
    Using software source
    Note:
    cloud-init depends on qcloud-python, which is a software package recompiled by Tencent Cloud. qcloud-python is a separate python environment and is only used for cloud-init. It is installed under the directory of /usr/local/qcloud/python, and it does not conflict with the default python in the system.
    cloud-init is developed by Tencent Cloud based on the community v20.1. It is adapted to Tencent Cloud operation environment.
    The cloud-init binary package supports the following operating systems:
    Type
    OS
    Version
    x86_64
    arm64
    qcloud-python
    cloud-init
    qcloud-python
    cloud-init
    rpm
    CentOS
    7
    8
    Fedora
    36
    N/A
    N/A
    Kylin
    20sp1
    openSUSE
    15.4
    N/A
    N/A
    deb
    Debian
    11
    10
    N/A
    N/A
    9
    N/A
    N/A
    8
    N/A
    N/A
    Ubuntu
    22.04
    N/A
    N/A
    20.04
    18.04
    16.04
    N/A
    N/A
    

    Downloading cloud-init binary package

    1. Download the installation package.
    2. If cloud-init already exists, run the following command to clear it.
    rm -rf /var/lib/cloud
    rm -rf /etc/cloud
    rm -rf /usr/local/bin/cloud*
    3. Run the following commands based on the OS.
    For deb type, run the following command.
    dpkg -i *.deb
    For rpm type, run the following command.
    rpm -ivh *.rpm
    4. Check whether the version is installed properly.
    cloud-init qcloud -v
    /usr/bin/cloud-init qcloud 0011
    5. Restart.

    Downloading the cloud-init source package

    Note:
    The cloud-init-20.1.0011 version is most compatible with Tencent Cloud. It ensures that all configuration items of CVMs created through the image can be initialized properly. We recommend that you install cloud-init-20.1.0011.tar.gz. You can also click here to download other versions. This document uses cloud-init-20.1.0011 as an example.
    Run the following command to download the cloud-init source package:
    wget https://gerryguan-1306210569.cos.ap-chongqing.myqcloud.com/cloud-init/src/cloud-init-20.1.0011.tar.gz

    Installing cloud-init

    1. Run the following command to decompress the cloud-init installation package.
    Note:
    If you are using the Ubuntu operating system, run this command with the “root” account.
    tar -zxvf cloud-init-20.1.0011.tar.gz
    2. Run the following command to enter the decompressed cloud-init installation package directory, that is, the cloud-init-20.1.0011 directory:
    cd cloud-init
    3. Install Python-pip according to the operating system version.
    For CentOS 6/7, run the following command:
    yum install python3-pip -y
    For Ubuntu, run the following command:
    apt-get -y install python3-pip
    During installation, if an error such as “failed to install” or “installation package not found” occurs, see resolving Python-pip installation failure to troubleshoot it.
    4. Run the following command to upgrade pip.
    python3 -m pip install --upgrade pip
    5. Run the following command to install dependencies.
    Note:
    Python 2.6 is not supported when cloud-init uses requests 2.20.0 or later. If the Python interpreter installed in the image environment is Python version 2.6 or earlier, run the pip install 'requests<2.20.0' command to install requests 2.20.0 or later before installing the cloud-init dependencies.
    pip3 install -r requirements.txt
    6. Install the cloud-utils components corresponding to your OS version.
    For CentOS 6, run the following command:
    yum install cloud-utils-growpart dracut-modules-growroot -y
    dracut -f
    For CentOS 7, run the following command:
    yum install cloud-utils-growpart -y
    For Ubuntu, run the following command:
    apt-get install cloud-guest-utils -y
    7. Run the following command to install cloud-init:
    python3 setup.py build
    python3 setup.py install --init-system systemd
    Note:
    The --init-system can be followed by any of systemd, sysvinit, sysvinit_deb, sysvinit_freebsd, sysvinit_openrc, sysvinit_suse, upstart, or None (default). Choose one according to the auto-start service management method of the operating system. Otherwise the cloud-init service cannot automatically start upon system startup.
    Select sysvinit for the CentOS 6 and earlier versions, and select systemd for CentOS 7 and later versions. This document uses systemd as an example.

    Modifying the cloud-init configuration file

    1. Download cloud.cfg for your operating system.
    2. Replace the content of /etc/cloud/cloud.cfg with that of the downloaded cloud.cfg file.

    Adding syslog user

    Run the following command to add a syslog user:
    useradd syslog

    Configuring the auto-start of the cloud-init service on boot

    If your operating system uses the systemd auto-start service management method, run the following command.
    Note:
    To check whether the operating system uses systemd, run the strings /sbin/init | grep "/lib/system" command, and you will receive a return message.
    Run the following command in Ubuntu or Debian.
    ln -s /usr/local/bin/cloud-init /usr/bin/cloud-init
    Run the following commands in all operating systems.
    systemctl enable cloud-init-local.service
    systemctl start cloud-init-local.service
    systemctl enable cloud-init.service
    systemctl start cloud-init.service
    systemctl enable cloud-config.service
    systemctl start cloud-config.service
    systemctl enable cloud-final.service
    systemctl start cloud-final.service
    systemctl status cloud-init-local.service
    systemctl status cloud-init.service
    systemctl status cloud-config.service
    systemctl status cloud-final.service
    Run the following commands in CentOS or Redhat. Replace the content of /lib/systemd/system/cloud-init-local.service with the following:
    [Unit]
    Description=Initial cloud-init job (pre-networking)
    Wants=network-pre.target
    After=systemd-remount-fs.service
    Before=NetworkManager.service
    Before=network-pre.target
    Before=shutdown.target
    Conflicts=shutdown.target
    RequiresMountsFor=/var/lib/cloud
    [Service]
    Type=oneshot
    ExecStart=/usr/bin/cloud-init init --local
    ExecStart=/bin/touch /run/cloud-init/network-config-ready
    RemainAfterExit=yes
    TimeoutSec=0
    # Output needs to appear in instance console output
    StandardOutput=journal+console
    [Install]
    WantedBy=cloud-init.target
    Replace the content of /lib/systemd/system/cloud-init.service with the following:
    [Unit]
    Description=Initial cloud-init job (metadata service crawler)
    Wants=cloud-init-local.service
    Wants=sshd-keygen.service
    Wants=sshd.service
    After=cloud-init-local.service
    After=systemd-networkd-wait-online.service
    After=networking.service
    After=systemd-hostnamed.service
    Before=network-online.target
    Before=sshd-keygen.service
    Before=sshd.service
    Before=systemd-user-sessions.service
    Conflicts=shutdown.target
    [Service]
    Type=oneshot
    ExecStart=/usr/bin/cloud-init init
    RemainAfterExit=yes
    TimeoutSec=0
    # Output needs to appear in instance console output
    StandardOutput=journal+console
    [Install]
    WantedBy=cloud-init.target
    If your operating system uses the sysvinit auto-start service management method, run the following commands:
    Note:
    To check whether the operating system uses sysvinit, run the strings /sbin/init | grep "sysvinit" command, and you will receive a return message.
    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

    Installing cloud-init

    Run the following command to install cloud-init:
    apt-get/yum install cloud-init
    Note:
    By default, the cloud-init version installed by running apt-get or yum is the default cloud-init version in the software source configured for the operating system. Some configuration items of instances created by using the image whose cloud-init is installed this way may not be initialized as expected. Therefore, we recommend that you install the service by manually downloading the cloud-init source package.

    Modifying the cloud-init configuration file

    1. Download cloud.cfg for your operating system.
    2. Replace the content of /etc/cloud/cloud.cfg with that of the downloaded cloud.cfg file.

    More

    Note:
    Do not restart the server after performing the following operations. Otherwise, you will need to perform them again.
    1. Run the following command to check whether the cloud-init configuration is successful.
    cloud-init init --local
    If the following information is returned, it indicates that the cloud-init has been successfully configured.
    Cloud-init v. 20.1.0011 running 'init-local' at Fri, 01 Apr 2022 01:26:11 +0000. Up 38.70 seconds.
    2. Run the following command to delete the cache records of cloud-init.
    rm -rf /var/lib/cloud
    3. Run the following command in Ubuntu or Debian.
    rm -rf /etc/network/interfaces.d/50-cloud-init.cfg
    4. For Ubuntu or Debian, modify the content of /etc/network/interfaces to the following:
    # This file describes the network interfaces available on your system
    # and how to activate them. For more information, see interfaces(5).
    source /etc/network/interfaces.d/*

    Appendix

    Resolving Python-pip installation failure

    During installation, if an error such as “failed to install” or “installation package not found” occurs, troubleshoot it based on the operating system as follows:
    CentOS 6/7:
    Ubuntu:
    1. Run the following command to configure the EPEL storage repository.
    yum install epel-release -y
    2. Run the following command to install Python-pip.
    yum install python3-pip -y
    1. Run the following command to clear the cache.
    apt-get clean all
    2. Run the following command to update the software package list.
    apt-get update -y
    3. Run the following command to install Python-pip.
    apt-get -y install python3-pip
    
    Contact Us

    Contact our sales team or business advisors to help your business.

    Technical Support

    Open a ticket if you're looking for further assistance. Our Ticket is 7x24 avaliable.

    7x24 Phone Support