虚拟机管理工具 virsh
virsh 管理虚拟的机工具,不仅可以管理kvm 还可以管理xen vmare
virsh - management user interface
查看虚拟机
[root@kvm ~]# virsh list
setlocale: No such file or directory
Id Name State
----------------------------------------------------
2 debain running
查看虚拟机,包括不在running状态的虚拟机
[root@kvm ~]# virsh list --all
setlocale: No such file or directory
Id Name State
----------------------------------------------------
2 debain running
启动虚拟机
[root@kvm ~]# virsh start debain
setlocale: No such file or directory
Domain debain started
关闭虚拟机
[root@kvm ~]# virsh shutdown debain
setlocale: No such file or directory
Domain debain is being shutdown
删除虚拟机
[root@kvm ~]# virsh shutdown debain
[root@kvm ~]# virsh undefine debain
Domain debain has been undefined # 删除后定义文件一同被删除,磁盘文件还在
导入虚拟机
virt-install --import \
--name kvm2import \
--ram 2048 --vcpus=2 --cpu host-model \
--disk path=/opt/debain.raw,bus=virtio \
--network network=default,model=virtio \
--graphics vnc,listen=0.0.0.0,port=5910 \
--noautoconsole
暂停虚拟机
[root@kvm ~]# virsh suspend debain
setlocale: No such file or directory
Domain debain suspended
[root@kvm ~]# virsh list --all
setlocale: No such file or directory
Id Name State
----------------------------------------------------
3 debain paused
恢复暂停的虚拟机
[root@kvm ~]# virsh resume debain
setlocale: No such file or directory
Domain debain resumed
[root@kvm ~]# virsh list --all
setlocale: No such file or directory
Id Name State
----------------------------------------------------
3 debain running
虚拟机克隆
# 克隆了配置文件和磁盘文件
virt-clone --auto-clone -o 模板名称 -n 克隆后的虚拟机名称
virt-clone --auto-clone -o debain -n debain-01
virt-clone --auto-clone -o debain -n debain-02
设置自启动
[root@kvm ~]# virsh autostart debain
setlocale: No such file or directory
Domain debain marked as autostarted
取消自启动
virsh autostart --disable debain
查看虚拟机的概述
[root@lvm ~]# virsh dominfo debain
setlocale: No such file or directory
Id: 3
Name: debain
UUID: 382ac07b-7d64-4de0-951d-773b24342b7d
OS Type: hvm
State: running
CPU(s): 1
CPU time: 32.1s
Max memory: 1048576 KiB
Used memory: 1048576 KiB
Persistent: yes
Autostart: disable
Managed save: no
Security model: none
Security DOI: 0