安装常用linux的cloud image,并使用cloudinit初始化

安装常用linux的cloud image,并使用cloudinit初始化

安装cloudinit工具

apt install cloud-utils

启动虚拟机,以CentOS为例

镜像下载地址:

https://cloud.centos.org/centos/7/images/

命令:

touch /home/vhost/centos-cloud/centos-cloudinit.cfg

填入:

#cloud-config
ssh_authorized_keys:
  - ssh-rsa AAA3NzaCDAQABA....... xxx@xxx
hostname: centos
manage_etc_hosts: true 
user: root 
ssh_pwauth: 1
disable_root: 0
password: passwd
chpasswd: 
  expire: False
runcmd:
  - echo root:passwd |sudo chpasswd root && sudo sed -i 's/^.*PermitRootLogin.*/PermitRootLogin yes/g' /etc/ssh/sshd_config && sudo sed -i 's/^.*PasswordAuthentication.*/PasswordAuthentication yes/g' /etc/ssh/sshd_config && sudo service sshd restart

命令:

cloud-localds  /home/vhost/centos-cloud/cloud.img /home/vhost/centos-cloud/centos-cloudinit.cfg

virt-install \
--name centos7 \
--os-type Linux --os-variant centos7.0 \
--hvm \
--memory 1024 \
--vcpus 2 \
--network bridge=br0,model=virtio \
--cdrom=/home/vhost/centos-cloud/cloud.img \
--disk /home/vhost/centos-cloud/CentOS-7-x86_64-GenericCloud.qcow2,bus=virtio \
--graphics vnc,listen=0.0.0.0 \
--noautoconsole 

直接可以用ssh客户端以 root@passwd 登入。

© 版权声明
THE END
喜欢就支持一下吧
点赞8 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容