หน้านี้ยังไม่พร้อมใช้งานในภาษาท้องถิ่นของคุณ เรากำลังพยายามอย่างหนักเพื่อเพิ่มเวอร์ชันภาษาอื่น ๆ เพิ่มเติม ขอบคุณสำหรับการสนับสนุนเสมอมา

Compute
Elastic Cloud Server
Huawei Cloud Flexus
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Cloud Phone Host
Huawei Cloud EulerOS
Networking
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
VPC Endpoint
Cloud Connect
Enterprise Router
Enterprise Switch
Global Accelerator
Management & Governance
Cloud Eye
Identity and Access Management
Cloud Trace Service
Resource Formation Service
Tag Management Service
Log Tank Service
Config
OneAccess
Resource Access Manager
Simple Message Notification
Application Performance Management
Application Operations Management
Organizations
Optimization Advisor
IAM Identity Center
Cloud Operations Center
Resource Governance Center
Migration
Server Migration Service
Object Storage Migration Service
Cloud Data Migration
Migration Center
Cloud Ecosystem
KooGallery
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP Filing
Support Plans
My Credentials
Customer Operation Capabilities
Partner Support Plans
Professional Services
Analytics
MapReduce Service
Data Lake Insight
CloudTable Service
Cloud Search Service
Data Lake Visualization
Data Ingestion Service
GaussDB(DWS)
DataArts Studio
Data Lake Factory
DataArts Lake Formation
IoT
IoT Device Access
Others
Product Pricing Details
System Permissions
Console Quick Start
Common FAQs
Instructions for Associating with a HUAWEI CLOUD Partner
Message Center
Security & Compliance
Security Technologies and Applications
Web Application Firewall
Host Security Service
Cloud Firewall
SecMaster
Anti-DDoS Service
Data Encryption Workshop
Database Security Service
Cloud Bastion Host
Data Security Center
Cloud Certificate Manager
Edge Security
Managed Threat Detection
Blockchain
Blockchain Service
Web3 Node Engine Service
Media Services
Media Processing Center
Video On Demand
Live
SparkRTC
MetaStudio
Storage
Object Storage Service
Elastic Volume Service
Cloud Backup and Recovery
Storage Disaster Recovery Service
Scalable File Service Turbo
Scalable File Service
Volume Backup Service
Cloud Server Backup Service
Data Express Service
Dedicated Distributed Storage Service
Containers
Cloud Container Engine
SoftWare Repository for Container
Application Service Mesh
Ubiquitous Cloud Native Service
Cloud Container Instance
Databases
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GeminiDB
GaussDB
Distributed Database Middleware
Database and Application Migration UGO
TaurusDB
Middleware
Distributed Cache Service
API Gateway
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
Multi-Site High Availability Service
EventGrid
Dedicated Cloud
Dedicated Computing Cluster
Business Applications
Workspace
ROMA Connect
Message & SMS
Domain Name Service
Edge Data Center Management
Meeting
AI
Face Recognition Service
Graph Engine Service
Content Moderation
Image Recognition
Optical Character Recognition
ModelArts
ImageSearch
Conversational Bot Service
Speech Interaction Service
Huawei HiLens
Video Intelligent Analysis Service
Developer Tools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Content Delivery & Edge Computing
Content Delivery Network
Intelligent EdgeFabric
CloudPond
Intelligent EdgeCloud
Solutions
SAP Cloud
High Performance Computing
Developer Services
ServiceStage
CodeArts
CodeArts PerfTest
CodeArts Req
CodeArts Pipeline
CodeArts Build
CodeArts Deploy
CodeArts Artifact
CodeArts TestPlan
CodeArts Check
CodeArts Repo
Cloud Application Engine
MacroVerse aPaaS
KooMessage
KooPhone
KooDrive

Installing Cloud-Init

Updated on 2024-10-31 GMT+08:00

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.

  • You need to download Cloud-Init from its official website. Therefore, you must bind an EIP to the ECS.
  • If Cloud-Init is not installed, you cannot configure an ECS. As a result, you can only use the password in the image file to log in to the created ECSs.
  • By default, ECSs created from a public image have Cloud-Init installed. You do not need to install or configure Cloud-Init on such ECSs.
  • For ECSs created using an external image file, install and configure Cloud-Init by performing the operations in this section. For how to configure Cloud-Init, see Configuring Cloud-Init.
NOTE:

Cloud-Init is open-source software. If the installed version has security vulnerabilities, you are advised to upgrade it to the latest version.

Prerequisites

  • An EIP has been bound to the ECS.
  • You have logged in to the ECS.
  • The ECS uses DHCP to obtain IP addresses.

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 in any of the following ways: (Recommended) Install Cloud-Init Using the Official Installation Package, Install Cloud-Init Using the Official Source Code Package and pip, and Install Cloud-Init Using the Official GitHub Source Code.

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.

  • If you are in a Python 3 environment, run the following command to check whether Cloud-Init is installed (Ubuntu 22.0.4 is used as an example):

    which cloud-init

    • If information similar to the following is displayed, Cloud-Init has been installed:
      /usr/bin/cloud-init
    • If information similar to the following is displayed, Cloud-Init is not installed:
      /usr/bin/which: no cloud-init in (/usr/local/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin)
  • If you are in a Python 2 environment, run the following command to check whether Cloud-Init is installed (CentOS 6 is used as an example):

    which 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 no information is returned, Cloud-Init is not installed.
      NOTE:

      To confirm Cloud-Init is really not installed, you are advised to run rpm -qa |grep cloud-init to check again. If either of which cloud-init and rpm -qa |grep cloud-init shows that Cloud-Init has been installed, Cloud-Init is installed.

If Cloud-Init has been installed, perform the following operations:
  • Check whether to use the SSH 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/*

NOTE:

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.

  • SUSE Linux

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

    https://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 12 as an example. Perform the following steps to install Cloud-Init:

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

      zypper ar https://ftp5.gwdg.de/pub/opensuse/repositories/Cloud:/Tools/SLE_12_SP3/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

      CAUTION:

      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
    Table 1 lists the Cloud-Init installation paths for CentOS. Select the required installation package from the following addresses.
    1. Run the following commands to install Cloud-Init:

      yum install Cloud-Init installation package address/epel-release-x-y.noarch.rpm

      yum install cloud-init

      NOTE:

      Cloud-Init installation package address indicates the address of the Cloud-Init epel-release installation package, and x-y indicates the version of the Cloud-Init epel-release required by the current OS. Replace them with the actual values according to Table 1.

      • Take CentOS 6 64-bit as an example. If the version is 6.8, the command is as follows:

        yum install https://archives.fedoraproject.org/pub/archive/epel/6/x86_64/epel-release-6-8.noarch.rpm

      • Take CentOS 7 64-bit as an example. If the version is 7.14, the command is as follows:

        yum install https://archives.fedoraproject.org/pub/archive/epel/7/x86_64/Packages/e/epel-release-7-14.noarch.rpm

    2. Run the following commands to enable Cloud-Init to automatically start upon system boot:

      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

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

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

      yum install cloud-init

    2. Run the following commands to enable Cloud-Init to automatically start upon system boot:

      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

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

    1. Run the following commands to install Cloud-Init:

      apt-get update

      apt-get install cloud-init

    2. Run the following commands to enable Cloud-Init to automatically start upon system boot:

      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

    Cloud-Init-23.2.2 is used as an example to describe how to install Cloud-Init on CentOS, Fedora, Ubuntu, Debian, and SUSE.

    Download the cloud-init-23.2.2.tar.gz source code package from https://launchpad.net/cloud-init/trunk/23.2.2/+download/cloud-init-23.2.2.tar.gz.

  • Centos 7/Fedora Server 36
    NOTICE:

    Ensure that Python 3 has been installed.

    1. Check whether Cloud-Init has been installed. If any command output is displayed, Cloud-Init has been installed.
      cloud-init -v
    2. Delete the cache directory of Cloud-Init.
      rm -rf /var/lib/cloud/*
    3. Install dependency packages of Cloud-Init.
      yum install python3-pip -y
      yum install python3-devel
    4. Download the Cloud-Init package.
      wget https://launchpad.net/cloud-init/trunk/23.2.2/+download/cloud-init-23.2.2.tar.gz
    5. Decompress the Cloud-Init package.
      tar -zxvf cloud-init-23.2.2.tar.gz
    6. Go to the cloud-init-23.2.2 directory and install dependent libraries:
      cd cloud-init-23.2.2
      pip3 install -r requirements.txt
    7. Install Cloud-Init.
      python3 setup.py build
      python3 setup.py install --init-system systemd
    8. (Optional) Diable Cloud-Init's network configuration capability by modifying the /etc/cloud/cloud.cfg file.
      vi /etc/cloud/cloud.cfg

      Add the following content to the file:

      network:
        config: disabled
    9. Restart Cloud-Init and check its status.
      systemctl restart 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

    10. Enable Cloud-Init related services to automatically start upon system boot.
      systemctl enable cloud-init-local.service cloud-init.service cloud-config.service cloud-final.service
    11. Check whether Cloud-Init is running properly.
      cloud-init -v
      cloud-init init --local 

  • Ubuntu 22.0.4/Debian 11
    NOTICE:

    Ensure that Python 3 has been installed.

    1. Check and delete redundant Cloud-Init configuration files.
      rm -rf /var/lib/cloud/*
      rm -f /var/log/cloud-init*

      Delete all files except log-related configuration files from the /etc/cloud/cloud.cfg.d/ directory.

    2. Update your package list and check whether Wget is installed. If it is not, install it.
      sudo apt update
      sudo apt install wget 
    3. Install dependency packages.
      apt-get install cloud-guest-utils -y
      apt-get install python3-pip -y
      apt-get install python3-devel
    4. Download the Cloud-Init package.
      wget https://launchpad.net/cloud-init/trunk/23.2.2/+download/cloud-init-23.2.2.tar.gz
    5. Decompress the Cloud-Init package.
      tar -zxvf cloud-init-23.2.2.tar.gz
    6. Go to the cloud-init directory.
      cd cloud-init-23.2.2
    7. Install dependent libraries.
      pip3 install -r requirements.txt
    8. Install Cloud-Init.
      python3 setup.py install
    9. (Optional) Disable Cloud-Init's network configuration capability.

      You need to do so when the Cloud-Init version is 0.7.9 or later and you want to configure the network.

      NOTE:

      1. Open the /etc/cloud/cloud.cfg file.

      vi /etc/cloud/cloud.cfg

      2. Enter i and configure network. (If there is no such a configuration item, add it.)

      network:
        config: disabled
    10. Restart Cloud-Init and check its status.
      systemctl restart 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
    11. Enable Cloud-Init related services to automatically start upon system boot.
      systemctl enable cloud-init-local.service cloud-init.service cloud-config.service cloud-final.service
    12. Check whether Cloud-Init is running properly.
      cloud-init -v
      cloud-init init --local

  • SUSE Enterprise Linux Server 15
    NOTICE:

    Ensure that Python 3 has been installed.

    1. View existing SUSE repositories.
      zypper lr
    2. Delete the SUSE repositories.
      zypper rr No. of repositories listed in 1
    3. Configure a SUSE repository.
    4. Refresh the SUSE repository.
      zypper refresh
    5. Install Cloud-Init.
      zypper install cloud-init
    6. Run cloud-init -v. If error messages similar to the following are displayed, install the dependency packages.

      pip install requests pyyaml oauthlib jsonschema jsonpatch jinja2 configobj
    7. Check whether Cloud-Init is successfully installed. If the following error message is displayed, configure datasource_list in /etc/cloud/cloud.cfg.
      datasource_list: [ OpenStack ]
      datasource:
        OpenStack:
          metadata_urls: ['http://169.254.169.254']
          max_wait: 120
          timeout: 5
          apply_network_config: false
    8. Modify the configuration file, restart Cloud-Init, and check the Cloud-Init status.
      systemctl restart 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
    9. Enable Cloud-Init related services to automatically start upon system boot.
      systemctl enable cloud-init-local.service cloud-init.service cloud-config.service cloud-final.service

    10. Check whether Cloud-Init is running properly.
      cloud-init -v
      cloud-init init --local

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

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

    NOTE:

    For details about how to install a Cloud-Init source code package, see Cloud-Init Documentation

  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

CAUTION:

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.

Install Cloud-Init Using the Official GitHub Source Code

You can obtain the Cloud-Init source code from GitHub at https://github.com/canonical/cloud-init/

  1. Run the following commands to download the source code package and copy it to the /tmp/CLOUD-INIT folder:

    wget https://github.com/canonical/cloud-init/archive/refs/tags/0.7.6.zip

    mkdir /tmp/CLOUD-INIT

    cp cloud-init-0.7.6.zip /tmp/CLOUD-INIT

    cd /tmp/CLOUD-INIT

  2. Run the following command to decompress the package:

    unzip cloud-init-0.7.6.zip

  3. Run the following command to enter the cloud-init-0.7.6 folder:

    cd cloud-init-0.7.6

  4. (Optional) If the Cloud-Init version is 18.3 to 22.3, run the following commands:

    sed -i '/VALID_DMI_ASSET_TAGS =/a\VALID_DMI_ASSET_TAGS += ["HUAWEICLOUD"]' cloudinit/sources/DataSourceOpenStack.py

    cat cloudinit/sources/DataSourceOpenStack.py | grep VALID_DMI_ASSET_TAGS

    If the following information is displayed, the execution is successful.

  5. Install Cloud-Init. The commands vary depending on the OS type.
    • For CentOS 6.x or SUSE 11.x, run the following commands:

      python setup.py build

      python setup.py install --init-system sysvinit

    • For CentOS 7.x or SUSE 12.x, run the following commands:

      python setup.py build

      python setup.py install --init-system systemd

    NOTE:

    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

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

  7. Run the following commands to check whether Cloud-Init has been installed:

    cloud-init -v

    cloud-init init --local

    Cloud-Init is successfully installed if the following information is displayed:

    cloud-init 0.7.6

เราใช้คุกกี้เพื่อปรับปรุงไซต์และประสบการณ์การใช้ของคุณ การเรียกดูเว็บไซต์ของเราต่อแสดงว่าคุณยอมรับนโยบายคุกกี้ของเรา เรียนรู้เพิ่มเติม

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback