Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the typical application of cloud-init?

2025-02-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article is to share with you about the typical application of cloud-init, the editor thinks it is very practical, so I share it with you to learn. I hope you can get something after reading this article.

The editor introduces several typical applications of cloud-init: setting hostanme, setting the user's initial password, and installing software.

Set up hostname

By default, cloud-init sets the name of instance to hostname. But this is not very convenient, sometimes you want to be able to separate the two, you can use cloud-init 's set_hostname module to achieve. Set_hostname, which queries for hostname information in metadata, defaults to the name of instance. We can specify our own hostname by passing the following to cloud-init:

# cloud-config

Hostname: my1.cloudman.cc

Manage_etc_hosts: true

The explanation is as follows:

Cloud-init only reads data that starts with # cloud-config, so this line must be written correctly.

Hostname: my1.cloudman.cc tells cloud-init to set hostname to my1.cloudman.cc.

Manage_etc_hosts: true tells cloud-init to update the / etc/hosts file.

The next question is: how do you get this information to cloud-init?

There are three ways:

When ① instance is deployed, paste it directly into the Customization Script input box.

② saves it as a file and uploads it when instance is deployed (shown in ② above).

③ saves it as a file, and when deploying instance on the command line nova boot or openstack server create, use the parameter-- user-data passed in.

When the deployment is successful, the hostname is set up correctly and / etc/hosts is updated accordingly.

Customize the user's initial password

The official cloud image can only be logged in through ssh key by default. We can use the set-passwords module to set the password for the user and enable password login. The script you need to pass in is as follows:

# cloud-config

Chpasswd:

List: |

Root:123456

Ubuntu:123456

Expire: false

Ssh_pwauth: true

The explanation is as follows:

The root and ubuntu user passwords are set to 123456.

Ssh_pwauth enables password login.

Ssh verification after instance startup

The ubuntu user has successfully logged in with the ssh password and can be switched to root through the password.

Install softwar

The standard image cannot contain all the software we need, and custom installation is inevitable. One way is to install it manually after deployment, and the other is to have cloud-init install automatically for us through the package-update-upgrade-install module.

The script you need to pass in is as follows:

# cloud-config

Apt:

Primary:

-arches: [default]

Search:

-http://1.2.3.4

Packages:

-pwgen

-pastebinit

-[libpython2.7, 2.7.3-0ubuntu3.1]

The explanation is as follows:

Apt specifies the location of the installation source, in this case http://1.2.3.4. If it is a yum source, it is specified by the yum_repos module. For more information, please see the official website documentation.

Packages specifies the package that needs to be installed, and you can also specify a specific version.

After instance starts, you can see that the installation source in / etc/apt/sources.list has been updated to http://1.2.3.4.

Since http://1.2.3.4 is not a valid apt source, the installation is bound to fail, and we can see the failure message in / var/log/cloud-init.log.

Although we failed, we can at least be sure of the following things:

The script passed in is valid, and cloud-init is indeed trying to install the specified software.

/ var/log/cloud-init.log completely records all the details of the operation of cloud-init and is the most important tool for debug.

Cloud-init has many modules and full functions, and it is an artifact to realize instance customization.

These are the typical applications of cloud-init, and the editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report