Cloud-init principle of work flow _cloud-init

Source: Internet
Author: User
Tags log log oauth prepare

If there is a mistake welcome correct, look forward to your valuable advice.

Cloud-init is a script that activates and initializes virtual machines, operates on virtual machines when the virtual machine is started, and is highly functional and widely applicable to OpenStack.


Ubuntu14.04/etc/cloud/cloud.cfg

# The top level settings are used as module
# and System configuration.


# A set of users which May is applied and/or used by various modules
# when a ' Defa ult ' entry are found it'll reference the ' Default_user '
# from the distro configuration specified below
Users
-Default


# If is set, ' root ' won't be able to ssh in and they
# 'll get a message to login instead as the above $user (Ubuntu)
Disable_root:true


# This'll cause the set+update hostname module to not operate (if true)
Preserve_hostname:false


# Example DataSource Config
# DataSource:
# EC2:
# metadata_urls: [' blah.com ']
# timeout:5 # (defaults to seconds)
# max_wait:10 # (defaults to seconds)


# The modules that run in the ' init ' stage
Cloud_init_modules:
-Migrator
-Seed_random
-Bootcmd
-Write-files
-Growpart
-Resizefs
-Set_hostname
-Update_hostname
-Update_etc_hosts
-Ca-certs
-Rsyslog
-Users-groups
-SSH


# The modules that run in the ' config ' stage
Cloud_config_modules:
# Emit The Cloud config ready event
# This can is used by upstart jobs for ' start on Cloud-config '.
-Emit_upstart
-Disk_setup
-Mounts
-Ssh-import-id
-Locale
-Set-passwords
-Grub-dpkg
-Apt-pipelining
-Apt-configure
-Package-update-upgrade-install
-Landscape
-TimeZone
-Puppet
-Chef
-Salt-minion
-Mcollective
-Disable-ec2-metadata
-Runcmd
-Byobu


# The modules that run in the ' final ' stage
Cloud_final_modules:
-Rightscale_userdata
-Scripts-vendor
-Scripts-per-once
-Scripts-per-boot
-Scripts-per-instance
-Scripts-user
-Ssh-authkey-fingerprints
-Keys-to-console
-Phone-home
-Final-message
-Power-state-change


# System and/or distro specific settings
# (not accessible to handlers/transforms)
System_info:
# This'll affect which distro class gets used
Distro:ubuntu
# Default User name + that default users groups (if added/used)
Default_user:
Name:ubuntu
Lock_passwd:true
Gecos:ubuntu
Groups: [ADM, Audio, CDROM, dialout, dip, Floppy, Netdev, Plugdev, sudo, video]
sudo: [All= (All) Nopasswd:all]
Shell:/bin/bash
# Other Config this is given to the Distro class and/or path classes
Paths
Cloud_dir:/var/lib/cloud/
Templates_dir:/etc/cloud/templates/
Upstart_dir:/etc/init/
Package_mirrors:
-Arches: [i386, AMD64]
Failsafe
Primary:http://archive.ubuntu.com/ubuntu
Security:http://security.ubuntu.com/ubuntu
Search
Primary
-http://% (ec2_region) s.ec2.archive.ubuntu.com/ubuntu/
-http://% (Availability_zone) s.clouds.archive.ubuntu.com/ubuntu/
Security: []
-Arches: [ARMHF, Armel, default]
Failsafe
Primary:http://ports.ubuntu.com/ubuntu-ports
Security:http://ports.ubuntu.com/ubuntu-ports
Ssh_svcname:ssh


1. Cloud-init Information 3

2. Cloud-init Template Installation 3

2.1. Linux 3

2.1.1. Rhel6.5 Installation Cloud-init 3

2.1.2. Installation Verification 4

2.1.3. Configuration Modification 4

2.2. AIX 5

2.2.1. Aix7.1 installation Cloud-init 5

2.2.2. Installation Verification 5

2.2.3. Configuration Modification 7

3. Cloud-init template Production using 8

3.1. Template making 8

3.1.1. Use the command line to turn template 8

3.1.2. Use Horizon to turn template 8

3.2. Template Use 9

3.2.1. command line Create virtual machine 9

3.2.2. Horizon Create Virtual Machine 9

4. Cloud-init Working principle 11

4.1. Introduction to Theory 11

4.2. Example explanation 13

5. Partial script, configuration example 15

5.1. Modify root User Password 15

5.2. Create a new user, SSH login 16

5.3. Full domain name, host name written to Hosts file 16



1. Cloud-init Information

Activation engines and Cloud-init are ways to get user input and configure the operating system and software on a deployed virtual machine. Cloud-init is widely used in OpenStack. Install in virtual machine, form template and use with template.

Cloud-init is used for basic configuration of virtual machines through metadata services when creating a virtual machine, including common host names, users, passwords, and so on. At the same time, users can configure the virtual machine by User_data custom data, either with configuration files Cloud-config or directly given scripts, and support common shell cmd Python scripts (part 5th).

The program first determines the operating system type, loads the corresponding module, and loads the service.

Note: The activation engine and cloud-init cannot be installed in the virtual machine at the same time. 2. Cloud-init Template Installation 2.1. Linux

Take rhel6.5 as an example to install.

All modules in the cloud are placed in/usr/lib/python2.6/site-packages/cloudinit/config 2.1.1. Rhel6.5 installation Cloud-init

Prepare the rhel6.5 virtual machine, install the operating system, and configure the network to obtain the Cloud-init RPM installation package (also available under Powervc/opt/ibm/powervc/images/cloud-init).

Use Yum, Epel, or any other Package manager to install the dependencies necessary for Cloud-init in the repository.

Installs the Cloud-init dependencies for rhel6 in the FTP://FTP.UNICAMP.BR/PUB/LINUXPATCH/CLOUD-INIT-PPC64 repository.

Add the Epel Yum repository to get the associated RPM. Please run the following command to set up the Red Hat Enterprise Linux 6 repository.

wget http://dl.fedoraproject.org/pub/epel/6Server/ppc64/epel-release-6-8.noarch.rpm

RPM-UVH epel-release-6*.rpm

Yum install to install the following dependent packages:

Libselinux-python

Policycoreutils-python

Python-argparse

Python-boto

Python-cheetah

Python-configobj

Python-jsonpatch

Python-prettytable

Python-requests

Finally install the Cloud-init RPM installation package:

RPM-IVH cloud-init-0.7.4-2.el6.noarch.rpm 2.1.2. Installation verification

To execute the cloud-init init command:

2.1.3. Configuration modifications

After you install Cloud-init, use the following values to modify the Cloud.cfg file provided in/etc/cloud/cloud.cfg.

#add

Disable_ec2_metadata:true

#set

disable_root:0

Ssh_pwauth:1

Ssh_deletekeys:1

Clear Mac Information:

(1) The first file, empty the contents of the/etc/udev/rules.d/70-persistent-net.rules file.

(2) The second file, empty the/lib/udev/rules.d/75-persistent-net-generator.rules content.

(3) A third file that removes the Hwaddr line in the/etc/sysconfig/network-scripts/ifcfg-eth0.

(4) Clear log information in/var/log/cloud-init.log. 2.2. AIX

Take AIX7.1 as an example to install. 2.2.1. Aix7.1 Installation Cloud-init

Prepare to create AIX7.1 virtual machine, install operating system, configure IP Information link extranet to get RPM installation package.

After obtaining the RPM package, install the package.

To install a dependency pack:

Bash is needed by cloud-init-0.7.5-4.1

Python-argparse is needed by cloud-init-0.7.5-4.1

Python-boto >= 2.7 is needed by cloud-init-0.7.5-4.1

Python-cheetah is needed by cloud-init-0.7.5-4.1

Python-configobj is needed by cloud-init-0.7.5-4.1

Python-jsonpatch is needed by cloud-init-0.7.5-4.1

Python-oauth is needed by cloud-init-0.7.5-4.1

Python-prettytable is needed by cloud-init-0.7.5-4.1

Python-pyserial is needed by cloud-init-0.7.5-4.1

Python-pyyaml is needed by cloud-init-0.7.5-4.1

Python-requests is needed by cloud-init-0.7.5-4.1

Python-setuptools is needed by cloud-init-0.7.5-4.1

Python-xml is needed by cloud-init-0.7.5-4.1

Python-yaml is needed by cloud-init-0.7.5-4.1

/usr/bin/python is needed by cloud-init-0.7.5-4.1

RPM-IVH cloud-init-0.7.5-4.1.aix6.1.ppc.rpm

2.2.2. Installation Verification

After the installation is complete, you can use RPM-QA to view the installed RPM packages.

Such as:

# RPM-QA

Aix-rpm-7.1.3.30-1

Tcl-8.4.7-3

Tk-8.4.7-3

Expect-5.42.1-3

Bash-4.2-9

Python-argparse-1.2.1-1

Libyaml-0.1.4-1

Unzip-6.0-2

Bzip2-1.0.6-2

Info-5.0-2

Libiconv-1.14-1

Db-4.8.24-4

Expat-2.1.0-1

Gmp-5.1.3-1

Libffi-3.0.11-1

Gettext-0.17-8

Openssl-1.0.1g-1

Ncurses-5.9-3

Readline-6.2-3

Sqlite-3.7.15.2-2

Zlib-1.2.5-6

Gdbm-1.10-1

Python-2.7.6-1

Python-setuptools-0.9.8-1

Python-boto-2.34.0-1

Python-cheetah-2.4.4-2

Python-configobj-5.0.5-1

Python-jsonpointer-1.0.c1ec3df-1

Python-jsonpatch-1.8-1

Python-oauth-1.0.1-1

Python-prettytable-0.7.2-1

Python-pyserial-2.7-1

Python-pyyaml-3.11-2

Python-requests-2.4.3-1

Python-xml-0.8.4-1

cloud-init-0.7.5-4.1

Glib2-2.33.2-1

Python-devel-2.7.6-1

Fdupes-1.51-1

Python-six-1.3.0-1

Perform/opt/freeware/bin/cloud-init init for validation

2.2.3. Configuration modifications

Modify/opt/freeware/etc/cloud/cloud.cfg

-Update_hostname Delete this row

Datasource_list: [' configdrive '] deleted

Disable_ec2_metadata:true Add this row

Ssh_pwauth:1 set to 1

Disable_root:0 set to 0

Set Virtual Machine Network mode

Use the Smit TCPIP command to set the virtual machine to DHCP mode.

Clear Cloud-init Log Information

Clear/var/log/cloud-init-output.log Log file contents

# >/var/log/cloud-init-output.log 3. Cloud-init template making uses 3.1. Template Making 3.1.1. To use the command line to turn a template

Curl-i ' http://172.30.128.231:8774/v2/a8314cebd08140029b149e27c2bb37cc/servers/ 3721184d-981c-4763-9e1d-5b741c08eb7e/action '-x post-h "Accept:application/json"-H "Content-type:application/json" -H "user-agent:python-novaclient"-H "x-auth-project-id:admin"-H "x-auth-token:d300686b417649ac8c48f72b9ef6d1d7"-D ' {' Finishonboard ': {' boot_volume_id ': null, ' Os_distro ': ' Aix '}} '

Nova Image-create 3721184d-981c-4763-9e1d-5b741c08eb7e Cloud_dlpar_rhel7

3.1.2. Use horizon to make a template

Using the snapshot button of the instance to do the operation of the template, the virtual machine must be shut down for snapshot operation.

As shown in the following illustration:

3.2. Templates use 3.2.1. Command line Create virtual machine

Using--user-data 、--Key-name,-meta and other parameters to transmit data;

--user-data: Specifies the script configuration, implements to modify the password and so on operation.

--key-name: Specify key pair name, login without password

-meta: Write meta data.

To create a virtual machine command:

Nova Boot POWERKVM--flavor 6--image a48c96fd-d49a-4d0d-b6d9-1ddec52b65ba--nic net-id=f4889f14-33ab-4345-b480-92db1d 411a67--key-name key1--user-data/root/img/pass.txt--meta abc=def

3.2.2. Horizon Create Virtual machine

Some of the features are used as shown in the following illustration:

Eg:ssh-i Cloud_key root@172.24.23.30

4. Cloud-init working principle 4.1. Theory Introduction

Note: Take rhel6.5 as an example (involving partial file paths).

Cloudinit through the Cloud Platform metadata Service or configdrive and other data sources to get the UserData, the first will be the segmentation, and respectively for each module processing. All modules in the cloud are placed in/usr/lib/python2.6/site-packages/cloudinit/config. The configuration file can be divided into three major categories: Cloud_init_modules, Cloud_config_modules, Cloud_final_modules, System_info.

A particular module that needs to be mentioned here is Scripts-user, which executes the user scripts content in UserData and scripts generated by other modules such as Runcmd, so Cloudinit's configuration files are placed in cloud_final The _modules phase is almost final.

The cloud configuration file is mainly divided into two parts:

1, parameter, variable definition part.

2, Module list part.

Common configurations include setting the hostname of the virtual machine, hosts files, setting the username password, updating the Apt-get local cache, resizing the file system (note that the partition is not resized), and so on.

Configuration file:/etc/cloud/cloud.cfg.

The Cloudinit will run in four stages in the process of starting the virtual machine, divided into: cloud-init-local, Cloud-init, Cloud-config, cloud-final, in chronological order.

The cloud-init-local phase is primarily to run some local initialization scripts. Cloud-init, Cloud-config, cloud-final phase respectively executes the configuration file named Cloud_init_modules, Cloud_config_modules, Cloud_final_ All modules under modules, and if the list of modules is empty, nothing runs.

When each module is running, the status of the virtual machine is configured based on the value of the variable/parameter defined previously.

Update_etc_host module,/usr/lib/python2.6/site-packages/cloudinit/config/cc_update_etc_hosts.py. This module is used to set host Hosts file, which uses the values of hostname, FQDN, manage_etc_hosts and other variables. The module first attempts to read the values of these variables from the Cloudinit configuration file and, if not defined, attempts to get the value of the variable from the other data source, for example, for OPENSTAC, from the metadata service (http:// 169.254.169.254/latest/meta-data/hostname) Gets the host name of the virtual machine. If the initial template does not configure this parameter, you can get the corresponding parameter value by creating the--user-data parameter for the virtual machine.

4.2. Example explanation

For example, write the Hosts file as host name:

First, template initial configuration

Hosts files without setup

/etc/cloud/cloud.cfg configuration File Settings

Manage_etc_hosts:true

Preserve_hostname:false

Manage_etc_hosts is set to True, when the virtual machine is started Cloud_init_modules stage runs the Update_etc_hos module, gets the variable value and the corresponding parameter value. Template file/etc/cloud/templates/hosts.redhat.tmpl is exploited,

Rewrite the Hosts file as follows:

Add with Custom Script

If there are no settings in the template, you can specify the--user-data parameter to get the configuration value when you create the virtual machine through Nova boot.

Nova Boot testhostname--flavor 6--image d892728d-3652-49ca-a943-e8006b0cbbb2--nic net-id= F4889f14-33ab-4345-b480-92db1d411a67--user-data/root/img/pass.txt

or create a virtual machine by Horizon page Specify the script as follows:

#cloud-config

CHPASSWD:

List: |

root:123456

Expire:false

Ssh_pwauth:true

Manage_etc_hosts:true

Preserve_hostname:false

Full domain name, host name successfully written to Hosts file:

5. Partial script, configuration example

Can have a configuration file cloud-config or directly in the form of a script. 5.1. Modify root user password

#cloud-config

CHPASSWD:

List: |

root:123456

Expire:false

Ssh_pwauth:true

5.2. Create a new user, SSH login

#!/bin/bash

echo "One Test about user data" >>userdata

chmod 777 UserData

Useradd-m Me

Echo-e ' me\tall= (All) \tnopasswd:all ' >>/etc/sudoers

passwd me <<eof

Abcabc

Abcabc

Eof

Sed-i ' s/passwordauthentication no/passwordauthentication yes/g '/etc/ssh/sshd_config

Service SSH Restart

5.3. Full domain name, host name written to Hosts file

#cloud-config

CHPASSWD:

List: |

root:123456

Expire:false

Ssh_pwauth:true

Manage_etc_hosts:true

Preserve_hostname:false





Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.