美文网首页云计算云计算技术
本地虚拟机使用cloud-init

本地虚拟机使用cloud-init

作者: CC_06fa | 来源:发表于2019-03-22 15:48 被阅读1次

安装init-cloud

使用 apt-get 即可进行安装

sudo apt-get install init-cloud

配置文件目录为 /etc/cloud/
其中 /etc/cloud/cloud.cfg.d/90_dpkg.cfg为配置元数据选项,使用命令

dkpg-reconfigure cloud-init
image.png

可以更改此文件,使用空格更改选项,仅保留“NoCloud” 一项

制作Nocloud 数据源

  1. 编辑元数据

创建 my-meta-data 文件,并写入一下内容

instance-id: iid-local03
local-hostname: ubuntu-server

instance-id卫实例标号,只有其发生变化的时候,才会运行init-cloud

创建 my-user-data 文件,并写入以下内容

#cloud-config
chpasswd:
 list: |
   ubuntu:123456
expire: false

即使用cloud-config 配置模式,使用chpasswd 模块进行修改密码:将ubuntu的密码修改为123456

  1. 生成镜像
    将my-user-data及my-meta-data文件生成为my-seed.img 数据
cloud-localds my-seed.img my-user-data my-meta-data

启动虚拟机

在虚拟机启动xml文件中挂载/my-seed.img镜像

<disk type='file' device='disk' cache='none'>
               <driver name='qemu' type='raw'/>
               <source file='/my-seed.img'/>
               <target dev='hdc' bus='virtio'/>
               <readonly/>
</disk>

相关文章

网友评论

    本文标题:本地虚拟机使用cloud-init

    本文链接:https://www.haomeiwen.com/subject/hdkrvqtx.html