In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
Environment:
Openstack version pike control node host openstack-controller (ubuntu 16.04.5) 172.27.34.37
Compute node host openstack-computer (ubuntu 16.04.5) 172.27.34.38vxlan100
Centos7-init (172.27.100.2), ubuntu1604 (172.27.100.20) centos7 images
CentOS-7-x86_64-GenericCloud-1809.qcow2cubuntu16.04 Mirror
Xenial-server-cloudimg-amd64-disk1.imgcloud-init
Cloud-init 0.7.9
For details of ubuntu installation, please see the full record of Ubuntu16.04.5 installation in lvm mode.
For more information on openstack installation, please see: OpenStack practice (1): build p version of OpenStack by DevStack under Ubuntu16.04
For more information on floating ip construction, please see: OpenStack practice (9): implementation of floating IP by Open vSwitch
Architecture diagram:
Introduction to cloud-init
Cloud-init is a tool for linux, and cloud-init can obtain metadata from nova metadata services or config drive when the system starts up, including, but not limited to, the following customization work:
1. Set up default locale
two。 Set up hostname
3. Add ssh keys to .ssh / authorized_keys
4. Set user password
5. Configure the network
To implement instance customization, cloud-init performs tasks in five phases:
1.Generator (cloud-config.target)
2.Local (cloud-init-local.service)
3.Network (cloud-init.service)
4.Config (cloud-config.service)
5.Final (cloud-final.service)
The function of each stage
Generator: read configuration file cloud.cfg
Local: locate "local" data sources and configure the network
Network: reads the specified configuration of the cloud_init_modules module
Config: reads the specified configuration of the cloud_config_modules module
Final: read the specified configuration of the cloud_final_modules module separately
Cloud image
Ubuntu image: http://cloud-images.ubuntu.com/
Centos7 image: http://cloud.centos.org/centos/7/images/
These images are pre-installed with cloud-init.
Config drive
When there is no dhcp service, metadata can be obtained through config drive
Configure config driver
Stack@openstack-controller:~$ view / etc/nova/nova.confflat_injected = True
The purpose of this configuration is that the instance ENI can be configured correctly when the DHCP service is disabled, and the configuration will take effect when the computing service is restarted.
Stack@openstack-controller:~$ sudo systemctl restart devstack@n*
Close dhcp
To ensure that the metadata obtained by the instance through config driver, turn off the dhcp service here
Start the instance
Root@openstack-controller:~# nova boot-flavor m1.small-image centos7--availability-zone nova:openstack-controller-nic net-name=vxlan100-key-name centos7--security-groups centos7--user-data / tmp/centos.config-config-drive true centos7-init
Config-driver is enabled through-- config-drive true, and configuration is loaded through-- user-data / tmp/centos.config. The configuration file of ubuntu is / tmp/ubuntu.config
Printed log, incoming user_data
Bind floating IP
User-data:centos.config
Root@openstack-controller:~# more / tmp/centos.config#cloud-configchpasswd: list: | root:rootroot centos:centos expire: falsessh_pwauth: yeshostname: loong576yum_repos: epel-163: baseurl: http://mirrors.163.com/centos/$releasever/os/$basearch/ name: Centos-7 enabled: trueresolv_conf: nameservers: ['218.104.1xx.1xx' '8.8.8.8'] searchdomains:-localdomain domain: localdomain options: rotate: true timeout: 1manage_resolv_conf: truepackages:-vim-wget-httpdtimezone:' Asia/Shanghai'runcmd:-[sed,-I, "s / ^ * SELINUX=enforcing/SELINUX=disabled/g", / etc/selinux/config]-[mkdir, / dropme]-[touch / root/abc.txt]-[sed,-I, "s / ^ * nameserver.*/nameserver 218.104.1xx.1xx/g", / etc/resolv.conf]-[rpm,-- import, / etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7] power_state: delay: now mode: reboot message: reboot now timeout: 30 condition: true
Verify whether it is effective
Verify that the customized configuration file centos.config is valid
You can log in to root directly (by default, you can only log in by creating key pairs) to obtain ip successfully, configure yum source and time zone, runcmd works normally, selinux is closed (power-state-change is normal), test files are generated, and dns information is modified.
User-data:ubuntu.config
Root@openstack-controller:~# more / tmp/ubuntu.config#cloud-configchpasswd: list: | root:rootroot ubuntu:ubuntu expire: falsessh_pwauth: yeshostname: ubuntu1604apt: primary:-arches: [default] uri: "http://mirrors.aliyun.com/ubuntu/" search: -" http://mirrors.aliyun.com/ubuntu/"resolv_conf: Nameservers: ['218.104.1xx.1xx' '8.8.8.8'] searchdomains:-localdomain domain: localdomain options: rotate: true timeout: 1manage_resolv_conf: truepackages:-apache2timezone:' Asia/Shanghai'runcmd:-[mkdir, / dropme]-[sed,-I, "$a nameserver 218.104.1xx.xxx", / etc/resolv.conf]
Verify whether it is effective
Verify that the customized configuration file ubuntu.config is valid
The instance can log in to ubuntu directly (by default, you can only log in by creating a key pair) to obtain ip successfully. Hostname, apt source and time zone are configured, runcmd runs normally, test files are generated, and dns information is modified.
View config drive
Sr0 is config driver, mount and view
[root@centos7-init ~] # lsblk [root@centos7-init ~] # mount / dev/sr0 / mnt [root@centos7-init ~] # cd / mnt/openstack/latest/ & & ll [root@centos7-init latest] # more meta_data.json [root@centos7-init latest] # more user_data
Public_keys,hostname and other information are stored in meta_data.json, and user_data corresponds to centos.config.
Cloud-init.log log analysis
[root@centos7-init ~] # view / var/log/cloud-init.log
First phase service
Second phase service
Third stage service
In the third phase, the init-network service reads the following configurations in the cloud_init_modules module: check-cache, consume-user-data, consume-vendor-data, config-migrator, config-bootcmd, config-write-files, config-growpart, config-resizefs, config-set_hostname, config-update_etc_hosts, config-rsyslog, config-users-groups, config-ssh
Phase IV service
In the fourth phase, the modules-config service reads the following configurations in the cloud_config_modules module: check-cache, consume-user-data, consume-vendor-data, config-migrator, config-bootcmd, config-write-files, config-growpart, config-resizefs, config-set_hostname, config-update_etc_hosts, config-disable-ec2-metadata, config-runcmd
Fifth stage service
In phase 5, the modules-final service reads the following configurations in the cloud_final_modules module in turn: config-rightscale_userdata, config-scripts-per-boot, config-scripts-per-instance, config-scripts-user, config-ssh-authkey-fingerprints, config-keys-to-console, config-phone-home, config-final-message, config-power-state-chang
Cloud init's modules provides a wealth of customization information. For more information, please refer to Cloud-Init 's official website: https://cloudinit.readthedocs.io/en/latest/index.html#
Cloud-init debugging
Debug each service separately
Init-local:cloud-init init--localcloud_init_modules:cloud-init initcloud_config_modules:cloud-init modules-mode=configcloud_final_modules:cloud-init modules-mode=final
[root@centos7-init] # cloud-init init-- local
Debug a configuration of a module
[root@centos7-init] # cloud-init single-- name timezone
Debug the timezone configuration of the cloud_config_modules module
Summary of practice:
1. The configuration items of each module are read and take effect in turn.
When you customize the instance, the configuration file cloud.cfg configuration items are read in turn.
The host in the experimental environment needs to be equipped with DNS to access the public network. Configure DNS through the runcmd configuration item of the cloud_config_modules module. Because the configuration item package-update-upgrade-install is installed before runcmd, cloud-init will install the software first, so the public network is not available, so an error was reported.
The hostname setting for 2.centos does not take effect
Many parameter combinations have been tried, but none of them went to hostname. The reason remains to be found.
Tried parameters
Hostname: loong576manage_etc_hosts: truepreserve_hostname: truefqdn: loong576
Ubuntu does not have this problem, you only need to set hostname, and the restart of the system still takes effect.
3.DNS configuration does not take effect
The configuration item resolv_conf is not valid. Both centos and ubuntu do not work. Centos seems to be a bug. Reference: https://bugzilla.redhat.com/show_bug.cgi?id=1489270 bug suggests writing dns information to the network card / etc file / network/interfaces.
The command executed by 4.runcmd should be in double quotes
This is a bit of a pit, when using the sed command to close selinux and configure DNS, the normal single quotation mark''needs to be replaced with "', otherwise an error message will be performed.
5. If a configuration item is illegal, the whole configuration will not take effect.
Runmcd has an illegal configuration.
Error log
The entire centos.config configuration file does not take effect at this time
Cloud-init configuration file has been uploaded to github: https://github.com/loong576/cloud-init.git
Reference:
Https://cloudinit.readthedocs.io/en/latest/
Https://docs.openstack.org/ironic/latest/install/configdrive.html
Https://help.ubuntu.com/community/CloudInit
Https://blog.csdn.net/allison_ywt/article/details/52943480
Https://blog.51cto.com/cloudman/1912640
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.