欢迎光临
我们一直在努力

通过virsh修改虚拟机密码

如果在openstack平台上创建虚拟机时要传入密码则安装cloud-init即可。

若想要通过virsh命令上修改虚拟机的密码则需要安装qemu-guest-agent

安装以及配置方法

https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7/html/Virtualization_Deployment_and_Administration_Guide/chap-QEMU_Guest_Agent.html

把镜像上传到openstack云平台(我是N版的Openstack)

openstack image create  centos7.3 --disk-format qcow2 --container-format bare --file  moban.qcow2 --property hw_qemu_guest_agent=yes  --public

or

glance image-create --progress --name 'centos7.3.raw' --container-format=bare --disk-format=raw --min-ram=1024 --property architecture=x86_64 --property os_distro=linux  --property os_version=7.3 --property vol_size=24 --property hw_qemu_guest_agent=yes --file centos7.3.raw

注意

务必设置property的hw_qemu_guest_agent=yes,否则libvert启动虚拟机时不会生成qemu-ga配置项导致虚拟机内部的qemu-ga由于找不到对应的虚拟串行字符设备而启动失败提示找不到channel。

创建完虚拟机后若忘记了虚拟机的密码则可以直接修改

virsh set-user-password <domain> <user> <password>

下面是关于基于agent的几个命令小操作。

1. 关闭/重启虚拟机

# virsh shutdown/reboot domain --mode=agent
virsh shutdown/reboot  默认的方式是使用ACPI--mode=acpi可省略没有安装ACPI 的Linux虚拟机和Windows 虚拟机并不响应virsh shutdown/reboot domain 指令。使用--mode=agent方式QEMU guest agent 可以保证虚拟机完成关机/重启动作。

2. 稳定的快照

# virsh snapshot-create-as domain --disk-only --quiesce

通过qga虚拟机在创建快照之前会先flush I/O保证磁盘内容的高稳定性。

3. 冻结/恢复/整理文件系统

# virsh domfsfreeze/domfsthaw/domfstrim domain

4. 查询虚拟机IP

# virsh domifaddr domain --source agent

注qga 2.1.0 版本不支持该指令

5. 显示虚拟机挂载的文件系统

# virsh domfsinfo domain

注qga2.1.0 版本不支持该指令

TBD

6. 查询/设置虚拟机系统时间

# virsh domtime domain --pretty           #查询虚拟机时间
# virsh domtime domain --now             #设置虚拟机时间为宿主机当前时间

设置虚拟机时间有问题解决方法还在探索中。。。

7. 设置虚拟机用户密码

# virsh set-user-password <domain> <user> <password>

复制代码

该指令在qga 2.1.0 和 2.3.0 版本中都无法运行估计RedHat 7 中的qga 包版本比现有的centos 版本的更新一些。

###

Openstack 技术交流群:580078423

希望大家入群多多交流

赞(0)
【声明】:本博客不参与任何交易,也非中介,仅记录个人感兴趣的主机测评结果和优惠活动,内容均不作直接、间接、法定、约定的保证。访问本博客请务必遵守有关互联网的相关法律、规定与规则。一旦您访问本博客,即表示您已经知晓并接受了此声明通告。