前言:
接上一篇文章:https://zskjohn.blog.csdn.net/article/details/128931042
我們可以從官方獲取到現(xiàn)成的鏡像,例如,從Ubuntu 18.04 LTS (Bionic Beaver) Daily Build [20230210]官方下載的bionic-server-cloudimg-amd64.img?這樣的文件(注意,注意,注意,openstack的架構(gòu)是哪個(gè),鏡像也需要一致,本例中openstack安裝的是x86_64,獲取鏡像的時(shí)候,只能下載amd64的,否則鏡像不能實(shí)例化,arm和ppc這些的鏡像是不能夠使用的)。
- "bionic" 表示使用的操作系統(tǒng)版本,在這種情況下是 Ubuntu 18.04 LTS 版本;
- "server" 表示這個(gè)鏡像是一個(gè)服務(wù)器版本的鏡像;
- "cloudimg" 表示這個(gè)鏡像是針對云計(jì)算的;
- "amd64" 表示這個(gè)鏡像適用于 x86_64?架構(gòu)的計(jì)算機(jī)。
1,
基本概念:
cloud-init是專為云計(jì)算環(huán)境中虛擬機(jī)實(shí)例/裸金屬實(shí)例的初始化而開發(fā)的一個(gè)開源工具,它安裝在虛擬機(jī)鏡像/裸金屬鏡像中,創(chuàng)建實(shí)例時(shí),通過nova組件的config drive把預(yù)注入的數(shù)據(jù)打包成鏡像,并掛載在實(shí)例的cdrom中,實(shí)例啟動時(shí),通過讀取cdrom中的相關(guān)數(shù)據(jù),對虛擬機(jī)進(jìn)行初始化配置。
2,
cloud-init的適用范圍
? ? cloudinit安裝在openstack虛擬機(jī)、裸金屬的鏡像中,只適用于linux操作系統(tǒng)鏡像。
? ? Windows鏡像對應(yīng)需要安裝cloudbase-init。
? ? OpenStack中如果要使用Config Drive實(shí)現(xiàn)元數(shù)據(jù)的注入,在制作image時(shí)一定要安裝cloud-init軟件,否則無法實(shí)現(xiàn)元數(shù)據(jù)注入(官方鏡像基本都已經(jīng)安裝過了,如果是自制的鏡像,需要安裝cloud-init)。
3,
Metadata和Userdata(元數(shù)據(jù)的兩種類別)
? ? Metadata只能注入主機(jī)的基本信息。
? ? Userdata使用場景比較廣,只要有配置云服務(wù)器的需求,尤其是在批量化模版化的情況下,使用userdata定制云主機(jī)是最好的選擇。
4,
虛擬機(jī)實(shí)例獲取metadata的方式
? ? 在OpenStack中,虛擬機(jī)中的cloud-init獲取metadata信息的方式有兩種 Config drive 和 metadata RESTful服務(wù):
? ?
- ? ? Config drive方式獲取metadata
? ? Config drive 機(jī)制是指OpenStack將metadata信息寫入虛擬機(jī)的一個(gè)特殊的配置設(shè)備中,然后在虛擬機(jī)啟動時(shí),自動掛載并讀取 metadata信息,從而達(dá)到獲取metadata的目的。
? ? 在客戶端操作系統(tǒng)中,存儲 metadata 的設(shè)備需要是ISO9660或者VFAT文件系統(tǒng)。
? ? config-drive 其實(shí)就是 Metadata-Source 的 “本地” 版本,它不依賴虛擬機(jī)網(wǎng)絡(luò)信息,客戶機(jī)操作系統(tǒng)可以直接通過一個(gè)設(shè)備讀取 Metadata 信息。
- Metadata RESTful 服務(wù)方式獲取metadata
? ? OpenStack提供了RESTful 接口,虛擬機(jī)可以通過 REST API 來獲取 metadata 信息。提供該服務(wù)的組件為:nova-api-metadata。當(dāng)然,要完成從虛擬機(jī)至網(wǎng)絡(luò)節(jié)點(diǎn)的請求發(fā)送和相應(yīng),只有 nova-api-metadata 服務(wù)是不夠的,此外共同完成這項(xiàng)任務(wù)的服務(wù)還有:Neutron-metadata-agent 和 Neutron-ns-metadata-proxy。
? ? 由于metadata service結(jié)構(gòu)太復(fù)雜,建議使用config drive的方式獲取metadata。
?
5,
Userdata的注入方式
? ? userdata注入方式有多種,常用的格式有:userdata-scripts和cloud-config。
- ? ? userdata-scripts:適用于需要通過執(zhí)行shell腳本初始化實(shí)例的用戶,以“#!/bin/sh”開頭,從用戶數(shù)據(jù)來看目前大部分用戶都是直接通過這種格式輸入userdata的, 也適用于較復(fù)雜的部署場景。
- ? ? cloud-config: 是cloud-init支持的特有格式,它把常用的個(gè)性化配置包裝成YAML文件格式提供出來,通過這種形式可以更方便的完成常用配置,以“#cloud-config”為首行區(qū)分,緊隨其后的是一個(gè)關(guān)聯(lián)數(shù)組,提供的鍵包括ssh_authorized_keys、hostname、write_files、manage_etc_hosts等。
本文示例使用的是cloud-config
metadata 在openstack中會放置在meta服務(wù)器上或者虛擬機(jī)內(nèi)部,分光驅(qū)方式和修改鏡像方式,后面講到,需要虛擬機(jī)用戶主動去獲取,而userdata則是由cloudinit軟件執(zhí)行,在虛擬機(jī)實(shí)例launch時(shí)運(yùn)行
?
從鏡像名字可以看出這些官方鏡像文件是預(yù)制帶有cloud-init服務(wù)的(有cloud或者clouding字段的鏡像文件都是已經(jīng)安裝過cloud-init的),如果你根據(jù)此鏡像已經(jīng)啟動成功了一個(gè)實(shí)例,那么,現(xiàn)在登陸這個(gè)實(shí)例時(shí)會看到有cloud-init?這個(gè)服務(wù)的
登陸控制臺,進(jìn)入虛擬機(jī)實(shí)例:
OK,現(xiàn)在可以這么說,每一個(gè)名字里帶有cloud或者clouding字樣的官方鏡像都內(nèi)置了cloud-init這個(gè)服務(wù)。那,這個(gè)服務(wù)到底是干什么的,如何使用它?
在回答以上問題前,需要了解一下官方鏡像的特點(diǎn)(本文只講Linux的鏡像,Windows的后面在說):
只有普通用戶?,例如下載的如果是centos的鏡像的話,那么普通用戶就是centos,此用戶無密碼,只有使用秘鑰ssh的方式才可以登陸實(shí)例,root密碼是不提供的,實(shí)例只有最基礎(chǔ)的環(huán)境,比如常用的vim,wget等等軟件是沒有的(通常是最小化安裝的操作系統(tǒng)),實(shí)例的主機(jī)名也無法定制,都是固定的鏡像名稱。
針對以上定制化需求,我們可以使用很多方法,比如,libguestfs工具集定制鏡像,其中的常用工具:guestfish,guestmount,virt-sysprep(修改或者設(shè)定系統(tǒng)用戶密碼等等一系列準(zhǔn)備工作的工具)等等,非常的多,但,如果只是一些個(gè)別的鏡像需要定制修改,可能使用libguestfs工具集是一個(gè)簡單的辦法,那么,如果是若干個(gè)鏡像需要定制化修改,工作量就非常大了(畢竟,libguestfs是一個(gè)一個(gè)鏡像的定制化修改,效率值得商榷)
而由于cloud-init?基本上是一個(gè)事實(shí)上的行業(yè)標(biāo)準(zhǔn)了,基本所有的官方鏡像都內(nèi)置了此服務(wù),我們使用的時(shí)候僅僅只需要一個(gè)配置文件,鏡像內(nèi)的cloud-init?服務(wù)將會在根據(jù)收到的配置文件,對鏡像做初始化動作,例如,CentOS-7-x86_64-GenericCloud-1508.qcow2.xz這個(gè)鏡像的密碼設(shè)定,預(yù)安裝wget這些常用軟件,設(shè)定主機(jī)名都可以通過一個(gè)配置文件就搞定了,并且,其它的centos鏡像也可以使用這個(gè)配置文件,僅僅在實(shí)例化鏡像的時(shí)候指定這個(gè)配置文件即可。
正文:
一,
直接使用官方鏡像
######注:openstack的neutron,以及秘鑰,安全組等等必須條件已完成,這里不解釋了
1,
上傳官方鏡像到glance
openstack image create "ubuntu" --file bionic-server-cloudimg-amd64.img --disk-format qcow2 --container-format bare --public
2,
由于是VMware虛擬機(jī)搭建的openstack,修改鏡像的磁盤格式為ide:
openstack image set --property hw_disk_bus=ide ubuntu
3,
直接啟動
openstack server create --flavor m1.tiny --image ubuntu --key-name mykey --security-group admin --network selfservice ubuntu
實(shí)例啟動后,進(jìn)入novnc控制臺,毫無辦法,只能看看,因?yàn)闆]有root密碼或者普通用戶密碼
?4,
綁定浮動ip?在控制節(jié)點(diǎn)ssh登陸以上建立的實(shí)例,使用秘鑰以普通用戶Ubuntu登陸實(shí)例,
[root@openstack1 opt]# openstack floating ip create provider
+---------------------+--------------------------------------+
| Field | Value |
+---------------------+--------------------------------------+
| created_at | 2023-02-12T15:25:56Z |
| description | |
| dns_domain | None |
| dns_name | None |
| fixed_ip_address | None |
| floating_ip_address | 192.168.123.168 |
| floating_network_id | 688a0356-4f2b-4029-b49e-a11bbdbedf0b |
| id | 091444ba-b93f-45e8-8363-292bd4c875e1 |
| name | 192.168.123.168 |
| port_details | None |
| port_id | None |
| project_id | 205ce8addd9444c893bd62244bcdae78 |
| qos_policy_id | None |
| revision_number | 0 |
| router_id | None |
| status | DOWN |
| subnet_id | None |
| tags | [] |
| updated_at | 2023-02-12T15:25:56Z |
+---------------------+--------------------------------------+
[root@openstack1 opt]# openstack server add floating ip ubuntu 192.168.123.168
[root@openstack1 opt]# ssh ubuntu@192.168.123.168
The authenticity of host '192.168.123.168 (192.168.123.168)' can't be established.
ECDSA key fingerprint is SHA256:U9W/IXHQ0+WtchdaehCI2o1sE2yUw+M1kgnth2byd+Q.
ECDSA key fingerprint is MD5:a6:6a:7c:74:e7:28:3c:74:fc:68:b1:9b:f4:10:e8:58.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.123.168' (ECDSA) to the list of known hosts.
Welcome to Ubuntu 18.04.6 LTS (GNU/Linux 4.15.0-204-generic x86_64)
* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage
System information as of Sun Feb 12 15:27:10 UTC 2023
System load: 0.0 Processes: 81
Usage of /: 2.3% of 48.27GB Users logged in: 0
Memory usage: 12% IP address for ens3: 172.16.1.10
Swap usage: 0%
Expanded Security Maintenance for Applications is not enabled.
0 updates can be applied immediately.
Enable ESM Apps to receive additional future security updates.
See https://ubuntu.com/esm or run: sudo pro status
The programs included with the Ubuntu system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.
Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by
applicable law.
To run a command as administrator (user "root"), use "sudo <command>".
See "man sudo_root" for details.
ubuntu@ubuntu:~$
5,
在虛擬機(jī)內(nèi)部查看日志,可以看到cloud-init初始化使用秘鑰的日志:
Feb 12 15:12:05 ubuntu systemd[1]: Started Update UTMP about System Runlevel Changes.
Feb 12 15:12:06 ubuntu cloud-init: #############################################################
Feb 12 15:12:06 ubuntu cloud-init: -----BEGIN SSH HOST KEY FINGERPRINTS-----
Feb 12 15:12:06 ubuntu cloud-init: 1024 SHA256:ssYh7n67IsNn0QYUmLoC7tL6JTLPAnr8a2x47tp4X4o root@ubuntu (DSA)
Feb 12 15:12:06 ubuntu cloud-init: 256 SHA256:U9W/IXHQ0+WtchdaehCI2o1sE2yUw+M1kgnth2byd+Q root@ubuntu (ECDSA)
Feb 12 15:12:06 ubuntu cloud-init: 256 SHA256:GbiqHwMBtH5lqPV2feHmioYLebVDmzs1cR9o+aD13Gs root@ubuntu (ED25519)
Feb 12 15:12:06 ubuntu cloud-init: 2048 SHA256:iXk1lobwN2tAhEIakffr3nzjokapoZ+Mt0dFgfsP4Os root@ubuntu (RSA)
Feb 12 15:12:06 ubuntu cloud-init: -----END SSH HOST KEY FINGERPRINTS-----
Feb 12 15:12:06 ubuntu cloud-init: #############################################################
Feb 12 15:12:06 ubuntu systemd-timesyncd[555]: Synchronized to time server 185.125.190.56:123 (ntp.ubuntu.com).
Feb 12 15:12:07 ubuntu cloud-init[1133]: Cloud-init v. 22.4.2-0ubuntu0~18.04.1 running 'modules:final' at Sun, 12 Feb 2023 15:12:06 +0000. Up 64.11 seconds.
Feb 12 15:12:07 ubuntu cloud-init[1133]: Cloud-init v. 22.4.2-0ubuntu0~18.04.1 finished at Sun, 12 Feb 2023 15:12:07 +0000. Datasource DataSourceOpenStackLocal [net
OK,這樣的虛擬機(jī)實(shí)例使用上是非常不方便的,并且時(shí)區(qū),apt源什么的都還是使用的國外的網(wǎng)址,那么,如果使用cloud-init?配置文件,將會是非常簡單的一個(gè)事情。
二,
使用cloud-init?配置文件定制化啟動虛擬機(jī)實(shí)例
1,
在控制節(jié)點(diǎn),新建文件,名稱為ubuntu.config? ,內(nèi)容如下:
cat >ubuntu.config <<EEE
#cloud-config
chpasswd:
list: |
root:123456
ubuntu:ubuntu
expire: false
ssh_pwauth: yes
hostname: ubuntutest
apt:
primary:
- arches: [default]
uri: "http://mirrors.aliyun.com/ubuntu/"
search:
- "http://mirrors.aliyun.com/ubuntu/"
resolv_conf:
nameservers: ['223.6.6.6', '8.8.8.8']
searchdomains:
- localdomain
domain: localdomain
options:
rotate: true
timeout: 1
manage_resolv_conf: true
packages:
- apache2
timezone: 'Asia/Shanghai'
runcmd:
- [ mkdir, /dropme ]
- [ sed, -i, "$a nameserver 223.6.6.6", /etc/resolv.conf ]
EEE
2,
啟動虛擬機(jī)實(shí)例的時(shí)候指定這個(gè)文件:
openstack server create --flavor m1.tiny --image ubuntu --key-name mykey --security-group admin --network selfservice --user-data ./ubuntu.config --config-drive true ubuntu
3,實(shí)例啟動后,進(jìn)入控制臺,查看cloud-init是否生效:
?主機(jī)名確實(shí)是ubuntutest,并且使用密碼123456可以進(jìn)入系統(tǒng),apt源也更新為了阿里云的
?此時(shí),重新綁定一個(gè)浮動IP就可以在其他地方ssh連接了,注意,是重新綁定浮動IP,否則會出現(xiàn)以下報(bào)錯(cuò):
[root@openstack1 opt]# ssh 192.168.123.168
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that a host key has just been changed.
The fingerprint for the ECDSA key sent by the remote host is
SHA256:etQl3iZ7QCNN866MdwiS8iL0p8uEU0FwTq5xBC139+k.
Please contact your system administrator.
Add correct host key in /root/.ssh/known_hosts to get rid of this message.
Offending ECDSA key in /root/.ssh/known_hosts:14
ECDSA host key for 192.168.123.168 has changed and you have requested strict checking.
ssh登陸虛擬機(jī)實(shí)例后,查看該實(shí)例的系統(tǒng)日志,可以看到cloud-init的相關(guān)日志,截取部分內(nèi)容,如下:
#¥#¥¥¥¥¥¥¥注:最后一行是cloud-init(也可以稱之為ci)修改密碼了
Feb 12 15:51:39 ubuntutest cloud-init[940]: Cloud-init v. 22.4.2-0ubuntu0~18.04.1 running 'init' at Sun, 12 Feb 2023 15:51:32 +0000. Up 29.18 seconds.
Feb 12 15:51:39 ubuntutest cloud-init[940]: ci-info: +++++++++++++++++++++++++++++++++++++++Net device info+++++++++++++++++++++++++++++++++++++++
Feb 12 15:51:39 ubuntutest cloud-init[940]: ci-info: +--------+------+------------------------------+---------------+--------+-------------------+
Feb 12 15:51:39 ubuntutest cloud-init[940]: ci-info: | Device | Up | Address | Mask | Scope | Hw-Address |
Feb 12 15:51:39 ubuntutest cloud-init[940]: ci-info: +--------+------+------------------------------+---------------+--------+-------------------+
Feb 12 15:51:39 ubuntutest cloud-init[940]: ci-info: | ens3 | True | 172.16.1.15 | 255.255.255.0 | global | fa:16:3e:0f:ae:1e |
Feb 12 15:51:39 ubuntutest cloud-init[940]: ci-info: | ens3 | True | fe80::f816:3eff:fe0f:ae1e/64 | . | link | fa:16:3e:0f:ae:1e |
Feb 12 15:51:39 ubuntutest cloud-init[940]: ci-info: | lo | True | 127.0.0.1 | 255.0.0.0 | host | . |
Feb 12 15:51:39 ubuntutest cloud-init[940]: ci-info: | lo | True | ::1/128 | . | host | . |
Feb 12 15:51:39 ubuntutest cloud-init[940]: ci-info: +--------+------+------------------------------+---------------+--------+-------------------+
Feb 12 15:51:39 ubuntutest cloud-init[940]: ci-info: +++++++++++++++++++++++++++++++Route IPv4 info++++++++++++++++++++++++++++++++
Feb 12 15:51:39 ubuntutest cloud-init[940]: ci-info: +-------+-----------------+------------+-----------------+-----------+-------+
Feb 12 15:51:39 ubuntutest cloud-init[940]: ci-info: | Route | Destination | Gateway | Genmask | Interface | Flags |
Feb 12 15:51:39 ubuntutest cloud-init[940]: ci-info: +-------+-----------------+------------+-----------------+-----------+-------+
Feb 12 15:51:39 ubuntutest cloud-init[940]: ci-info: | 0 | 0.0.0.0 | 172.16.1.1 | 0.0.0.0 | ens3 | UG |
Feb 12 15:51:39 ubuntutest cloud-init[940]: ci-info: | 1 | 169.254.169.254 | 172.16.1.1 | 255.255.255.255 | ens3 | UGH |
Feb 12 15:51:39 ubuntutest cloud-init[940]: ci-info: | 2 | 172.16.1.0 | 0.0.0.0 | 255.255.255.0 | ens3 | U |
Feb 12 15:51:39 ubuntutest cloud-init[940]: ci-info: +-------+-----------------+------------+-----------------+-----------+-------+
Feb 12 15:51:39 ubuntutest cloud-init[940]: ci-info: +++++++++++++++++++Route IPv6 info+++++++++++++++++++
Feb 12 15:51:39 ubuntutest cloud-init[940]: ci-info: +-------+-------------+---------+-----------+-------+
Feb 12 15:51:39 ubuntutest cloud-init[940]: ci-info: | Route | Destination | Gateway | Interface | Flags |
Feb 12 15:51:39 ubuntutest cloud-init[940]: ci-info: +-------+-------------+---------+-----------+-------+
Feb 12 15:51:39 ubuntutest cloud-init[940]: ci-info: | 1 | fe80::/64 | :: | ens3 | U |
Feb 12 15:51:39 ubuntutest cloud-init[940]: ci-info: | 3 | local | :: | ens3 | U |
Feb 12 15:51:39 ubuntutest cloud-init[940]: ci-info: | 4 | ff00::/8 | :: | ens3 | U |
Feb 12 15:51:39 ubuntutest cloud-init[940]: ci-info: +-------+-------------+---------+-----------+-------+
Feb 12 15:51:39 ubuntutest cloud-init[940]: 2023-02-12 15:51:32,379 - schema.py[WARNING]: Deprecated cloud-config provided:
Feb 12 15:51:39 ubuntutest cloud-init[940]: chpasswd.list: DEPRECATED: List of ``username:password`` pairs. Each user will have the corresponding password set. A password can be randomly generated by specifying ``RANDOM`` or ``R`` as a user's password. A hashed password, created by a tool like ``mkpasswd``, can be specified. A regex (``r'\$(1|2a|2y|5|6)(\$.+){2}'``) is used to determine if a password value should be treated as a hash.
在虛擬機(jī)內(nèi)也可以看到apache是啟動的:
ubuntu@ubuntutest:~$ systemctl status apache2
● apache2.service - The Apache HTTP Server
Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
Drop-In: /lib/systemd/system/apache2.service.d
└─apache2-systemd.conf
Active: active (running) since Sun 2023-02-12 23:52:36 CST; 21min ago
Main PID: 2536 (apache2)
Tasks: 55 (limit: 1151)
CGroup: /system.slice/apache2.service
├─2536 /usr/sbin/apache2 -k start
├─2563 /usr/sbin/apache2 -k start
└─2564 /usr/sbin/apache2 -k start
Feb 12 23:52:36 ubuntutest systemd[1]: Starting The Apache HTTP Server...
Feb 12 23:52:36 ubuntutest apachectl[2515]: AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.16.1.15. Set the 'Serv
Feb 12 23:52:36 ubuntutest systemd[1]: Started The Apache HTTP Server.
可以看到虛擬機(jī)內(nèi)部有一個(gè)虛擬光驅(qū),掛載光驅(qū),看看里面有什么?
root@ubuntutest:/mnt/openstack/latest# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
loop0 7:0 0 492K 1 loop /mnt
sda 8:0 0 50G 0 disk
├─sda1 8:1 0 49.9G 0 part /
├─sda14 8:14 0 4M 0 part
└─sda15 8:15 0 106M 0 part /boot/efi
sr0 11:0 1 492K 0 rom
root@ubuntutest:/mnt/openstack/latest# blkid
/dev/sda1: LABEL="cloudimg-rootfs" UUID="389aa1a9-4466-4e69-8f3f-9bfc5cfc4bbd" TYPE="ext4" PARTUUID="4d7b5a03-f968-4e9e-af71-dcc3028f8d76"
/dev/sda15: LABEL="UEFI" UUID="8374-EB2F" TYPE="vfat" PARTUUID="f29c5fa0-6fb6-4f4f-b04f-2ccae321cd4d"
/dev/sr0: UUID="2023-02-12-23-50-11-00" LABEL="config-2" TYPE="iso9660"
/dev/loop0: UUID="2023-02-12-23-50-11-00" LABEL="config-2" TYPE="iso9660"
/dev/sda14: PARTUUID="63375218-4ce6-4cc2-b0f6-22d1421c41fe"
###掛載虛擬光驅(qū)
root@ubuntutest:/mnt/openstack/latest# mount -o loop -t iso9660 /dev/sr0 /mnt
掛載之后,可以看到latest目錄下有一個(gè)user_data?文本文件,此文件就是前面注入的ubuntu.config?這個(gè)文件,內(nèi)容是和它一樣的
root@ubuntutest:/mnt/openstack/latest# pwd
/mnt/openstack/latest
root@ubuntutest:/mnt/openstack/latest# ls
meta_data.json network_data.json user_data vendor_data.json vendor_data2.json
#########小結(jié):這樣的方式修改定制官方鏡像非常的方便,并且是可以大批量的修改定制,可以理解為一個(gè)模板文件解決了基本所有的困擾。
centos7的ci配置文件如下:
[root@openstack1 opt]# cat /tmp/centos.config
#cloud-config
chpasswd:
list: |
root:123456
centos:centos
expire: false
ssh_pwauth: yes
hostname: centostest
yum_repos:
epel-163:
baseurl: http://mirrors.163.com/centos/$releasever/os/$basearch/
name: Centos-7
enabled: true
resolv_conf:
nameservers: ['223.6.6.6', '8.8.8.8']
searchdomains:
- localdomain
domain: localdomain
options:
rotate: true
timeout: 1
manage_resolv_conf: true
packages:
- vim
- wget
- httpd
timezone: 'Asia/Shanghai'
runcmd:
- [ sed, -i, "s/^ *SELINUX=enforcing/SELINUX=disabled/g", /etc/selinux/config ]
- [ mkdir, /fuck ]
- [ touch, /root/123456 ]
- [ sed, -i, "s/^ *nameserver.*/nameserver 223.6.6.6/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
三,
openstack中nova服務(wù)關(guān)于config_drive的設(shè)置
在上面的演示中,看到了一個(gè)虛擬光驅(qū)在虛擬機(jī)實(shí)例中,那么,這個(gè)虛擬光驅(qū)哪來的?
在nova的配置文件/etc/nova/nova.conf文件內(nèi):
config_drive_format有兩個(gè)值,ISO9660和vfat,對應(yīng)于虛擬光驅(qū)和虛擬磁盤
默認(rèn)是 iso9660,但這會導(dǎo)致 instance 無法在線遷移,必須設(shè)置成config_drive_format=vfat 才能在線遷移。文章來源:http://www.zghlxwxcb.cn/news/detail-781877.html
# * A compute node running Hyper-V hypervisor can be configured to attach
# configuration drive as a CD drive. To attach the configuration drive as a CD
# drive, set the ``[hyperv] config_drive_cdrom`` option to true.
# (string value)
# Possible values:
# iso9660 - <No description provided>
# vfat - <No description provided>
#config_drive_format=iso9660
還有一個(gè)配置,如果此值是true,那么,鏡像實(shí)例化的時(shí)候可以不加--config-drive true,默認(rèn)是不啟用config注入:文章來源地址http://www.zghlxwxcb.cn/news/detail-781877.html
#force_config_drive=false
到了這里,關(guān)于云計(jì)算|OpenStack|社區(qū)版OpenStack(實(shí)務(wù)操作---cloud-init的使用)的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!