Kvm命令集管理虚拟机

断了今生、忘了曾经 提交于 2019-12-14 22:28:42

KVM虚拟机配置文件位置

[root@localhost ~]# ll /etc/libvirt/qemu/
总用量 4
drwxr-xr-x 2 root root   23 12月 14 20:23 autostart
drwx------ 3 root root   42 12月 14 19:38 networks
-rw------- 1 root root 4074 12月 14 20:23 test2.xml

修改KVM虚拟机配置的方法

[root@localhost ~]#  virsh edit test2

备份与恢复

备份虚拟机配置(关机时备份):

[root@localhost ~]# virsh dumpxml test2 > test2.xml

删除虚拟机配置

[root@localhost ~]# virsh list --all
 Id    名称                         状态
----------------------------------------------------
 2     test01                         running
 4     test2                          running

[root@localhost ~]# virsh undefine test01

导入虚拟机

[root@localhost ~]# virsh define test2.xml 
定义域 test2(从 test2.xml)

修改虚拟机名称

[root@localhost ~]# virsh domrename test2 liujunjun

虚拟机挂起与恢复

[root@localhost ~]# virsh suspend test2
域 test2 被挂起

[root@localhost ~]# virsh list --all
 Id    名称                         状态
----------------------------------------------------
 2     test01                         running
 4     test2                          暂停

[root@localhost ~]# virsh resume test2
域 test2 被重新恢复

查询虚拟机vnc端口

[root@localhost ~]# virsh vncdisplay test2
:10050

开机自启动设置

[root@localhost ~]# systemctl is-enabled libvirtd.service 
enabled

设置宿主机开机虚拟机开机

[root@localhost ~]# virsh autostart test2
域 test2标记为自动开始

取消开机自启动

[root@localhost ~]# virsh autostart --disable test2
域 test2取消标记为自动开始

kvm虚拟机console登录

CentOS 7.X 版本console登录

配置console登录

在test2虚拟机内操作(该操作仅限centos7):

[root@localhost ~]# grubby --update-kernel=ALL --args="console=ttyS0,115200n8"
[root@localhost ~]# reboot
[root@localhost ~]# virsh console test2
连接到域 test2
换码符为 ^]
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!