时间:2023-07-12 10:57:01 | 来源:网站运营
时间:2023-07-12 10:57:01 来源:网站运营
如何使用cloud-init初始化云主机:使用cloud-init初始化云主机// 在虚拟机安装apt install cloud-init// 设置开机启动systemctl enable cloud-init-local.servicesystemctl enable cloud-init.servicesystemctl enable cloud-config.servicesystemctl enable cloud-final.service
// 编辑/etc/cloud/cloud.cfg添加 datasource_list: [NoCloud]
instance-id: my-instance-id1local-hostname: my-host-name4
cloud-init根据instance-id的值决定是否初始化,instance-id有变化则执行初始化,一般来说云主机只需要初始化一次,如果需要再次初始化,可以改变instance-id的值。#cloud-configwrite_files: - encoding: b64 content: aGVsbG8gd29ybGQK path: /rjy.test permissions: '0755' - content: | alias xxx hello world path: /etc/rjy.test
文件可以是明文传输也可以是base64加密传输。version: 2ethernets: eth0: match: mac_address: "52:54:00:da:17:ac" addresses: - 192.168.122.10/255.255.255.0 gateway4: 192.168.122.1 nameservers: addresses: [8.8.8.8]
genisoimage -o config.iso -V cidata -r -J meta-data user-data network-config
<disk type='file' device='cdrom'> <driver name='qemu' type='raw'/> <source file='/var/lib/libvirt/images/config.iso'/> <backingStore/> <target dev='hda' bus='ide'/> <readonly/> <alias name='ide0-0-0'/> <address type='drive' controller='0' bus='0' target='0' unit='0'/></disk>
重启云主机,就可以看到初始化的效果了。关键词:主机,使用