Cloud-init is an open source tool that runs inside a CVM instance as a non-resident service. It is executed at startup and exits immediately after execution. It does not listen to any ports.
All the Linux public images of Tencent Cloud are pre-installed with the cloud-init service. You need to run the service as the root user because the service is mainly used for the initialization of CVM instances such as configuring DNS, hostname, and IP, and the execution of some custom scripts that users specify to be executed during the first boot when creating the CVM instances.
First, log in to the instance and execute the following commands to see if any error is returned. If the execution result is returned, it means that the service is running normally. Otherwise, an error will be returned. You can troubleshoot according to the error message.
rm -rf /var/lib/cloud
cloud-init init --local
cloud-init init
cloud-init modules --mode=config
cloud-init modules --mode=final
Tencent Cloud implements all instance initialization operations through cloud-init, ensuring the transparency of the operations inside an instance. The following briefly covers some initialization operations. For more details, see cloud-init documentation.
Initialization operation | Default behavior | Customization | Notes |
---|---|---|---|
hostname initialization | During the first launch of an instance, cloud-init will set the hostname of the instance according to the hostname information in vendor_data.json . |
If you create or reinstall an instance with a custom image and you want to keep the custom hostname of the image, you can delete the configuration, - scripts-user , from /etc/cloud/cloud.cfg before creating the custom image. |
After you disable - scripts-user , the initialization script, /var/lib/cloud/instance/scripts/runcmd , inside the instance will not be run. Disabling the configuration will also affect the initialization of other sub-items such as the installation of cloud monitor and cloud security and software source settings. Also, the custom script will not be run when you create the CVM. |
/etc/hosts initialization | During the first launch of an instance, cloud-init will initialize /etc/hosts to 127.0.0.1 $hostname by default. |
If you create or reinstall an instance with a custom image and want to keep the custom /etc/hosts setting of the image, you can delete the - scripts-user and - ['update_etc_hosts', 'once-per-instance'] configurations from /etc/cloud/cloud.cfg before creating a custom image. |
|
DNS initialization (non-DHCP scenario) | During the first launch of an instance, cloud-init will set the DNS of the instance according to the nameservers information in vendor_data.json . |
If you create or reinstall an instance with a custom image and you want to keep the custom DNS setting of the image, you can delete the configuration, - resolv_conf and unverified_modules: ['resolv_conf'] , from /etc/cloud/cloud.cfg before creating the custom image. |
None. |
Software source initialization | During the first launch of an instance, cloud-init will set the software source of the instance according to the write_files information in vendor_data.json . | If you create or reinstall an instance with a custom image and you want to keep the custom software source setting of the image, you can delete the configuration, - write-files , from /etc/cloud/cloud.cfg before creating the custom image. |
None. |
NTP initialization | During the first launch of an instance, cloud-init will set the NTP server configuration of the instance according to the NTP server information in vendor_data.json and start the NTP service. |
If you create or reinstall an instance with a custom image and you want to keep the custom NTP configuration of the image, you can delete the configuration, - ntp |
None. |
Password initialization | During the first launch of an instance, cloud-init will set the default account password of the instance according to the chpasswd information in vendor_data.json . |
If you create or reinstall an instance with a custom image and you want to keep the custom default password of the image, you can delete the configuration, - set-passwords , from /etc/cloud/cloud.cfg before creating the custom image. |
None. |
Key binding | During the first launch of an instance, cloud-init will set the default account key of the instance according to the ssh_authorized_keys information in vendor_data.json . |
If you create or reinstall an instance with a custom image and you want to keep the custom default key of the image, you can delete the configuration, - users-groups , from /etc/cloud/cloud.cfg before creating the custom image. |
If you manually bind the instance to a key inside the instance, the previous key will be overwritten when the key binding operation is performed via the console. |
Network initialization (non-DHCP scenario) | During the initial launch of an instance, cloud-init will set the IP, Gateway, and Mask according to the information in network_data.json . |
If you create or reinstall an instance with a custom image and you want to keep the custom network information of the image, you can add network: {config: disabled} to /etc/cloud/cloud.cfg before creating the custom image. |
None. |
Traceback (most recent call last):
File "/usr/bin/cloud-init", line 5, in
********
raise DistributionNotFound(req)
pkg_resources.DistributionNotFound: pyyaml
/usr/bin/python
and /bin/python
, are linked to Python 2. Users may change the default Python interpreter to Python 3 inside the instance by directing the symbolic links, /usr/bin/python
and /bin/python
, to Python 3. Due to compatibility issues, an error will be returned when cloud-init is run on startup./usr/bin/cloud-init
file by changing #/usr/bin/python
or #/bin/python
to #! user/bin/python
.Do not use symbolic links. Point directly to a specific interpreter.
Like cloud-init, Cloudbase-Init is a bridge by which you can communicate with Windows CVM instances. The Cloudbase-Init service is run when an instance launches for the first time. The service will read the initialization configuration information of the instance and initialize it. Subsequent operations such as resetting the password and modifying IP addresses are also done through Cloudbase-Init.
If you forget your password or fail to reset your password because of Cloudbase-Init service exceptions, you can reset your password by following step 2.
Was this page helpful?