KVM虛擬化學習筆記系列文章列表
----------------------------------------
kvm虛擬化學習筆記(一)之kvm虛擬化環境安裝
http://koumm.blog.51cto.com/703525/1288795
kvm虛擬化學習筆記(二)之linux kvm虛擬機安裝
http://koumm.blog.51cto.com/703525/1289627
kvm虛擬化學習筆記(三)之windows kvm虛擬機安裝
http://koumm.blog.51cto.com/703525/1290191
kvm虛擬化學習筆記(四)之kvm虛擬機日常管理與配置
http://koumm.blog.51cto.com/703525/1290269
kvm虛擬化學習筆記(五)之windows虛擬機性能調整
http://koumm.blog.51cto.com/703525/1290682
kvm虛擬化學習筆記(六)之kvm虛擬機控制檯登錄配置
http://koumm.blog.51cto.com/703525/1290996
kvm虛擬化學習筆記(七)之kvm虛擬機克隆
http://koumm.blog.51cto.com/703525/1291793
kvm虛擬化學習筆記(八)之kvm虛擬機vnc配置
http://koumm.blog.51cto.com/703525/1291803
kvm虛擬化學習筆記(九)之kvm虛擬機時間配置
http://koumm.blog.51cto.com/703525/1291862
kvm虛擬化學習筆記(十)之kvm虛擬機快照備份
http://koumm.blog.51cto.com/703525/1291893
kvm虛擬化學習筆記(十一)之kvm虛擬機擴展磁盤空間
http://koumm.blog.51cto.com/703525/1292146
kvm虛擬化學習筆記(十二)之kvm linux虛擬機在線擴展磁盤
http://koumm.blog.51cto.com/703525/1295296
KVM虛擬機的管理主要是通過virsh命令對虛擬機進行管理。
1. 查看KVM虛擬機配置文件及運行狀態
(1) KVM虛擬機默認配置文件位置: /etc/libvirt/qemu/
(2) virsh命令幫助
# virsh -help
或直接virsh命令和,再執行子命令。如下所示。
[root@node1 ~]# virsh
歡迎使用 virsh,虛擬化的交互式終端。
輸入:'help' 來獲得命令的幫助信息
'quit' 退出
virsh # help
……
(3) 查看kvm虛擬機狀態
# virsh list --all
2. KVM虛擬機開機
# virsh start oeltest01
3. KVM虛擬機關機或斷電
(1) 關機
默認情況下virsh工具不能對linux虛擬機進行關機操作,linux操作系統需要開啓與啓動acpid服務。在安裝KVM linux虛擬機必須配置此服務。
# chkconfig acpid on
# service acpid restart
virsh關機
# virsh shutdown oeltest01
(2) 強制關閉電源
# virsh destroy wintest01
4. 通過配置文件啓動虛擬機
# virsh create /etc/libvirt/qemu/wintest01.xml
5. 配置開機自啓動虛擬機
# virsh autostart oeltest01
autostart目錄是kvm虛擬機開機自啓動目錄,可以看到該目錄中有KVM配置文件鏈接。
6. 導出KVM虛擬機配置文件
# virsh dumpxml wintest01 > /etc/libvirt/qemu/wintest02.xml
KVM虛擬機配置文件可以通過這種方式進行備份。
7. 添加與刪除KVM虛擬機
(1) 刪除kvm虛擬機
# virsh undefine wintest01
說明:該命令只是刪除wintest01的配置文件,並不刪除虛擬磁盤文件。如下圖所示。
(2) 重新定義虛擬機配置文件
通過導出備份的配置文件恢復原KVM虛擬機的定義,並重新定義虛擬機。
# mv /etc/libvirt/qemu/wintest02.xml /etc/libvirt/qemu/wintest01.xml
# virsh define /etc/libvirt/qemu/wintest01.xml
8. 編輯KVM虛擬機配置文件
# virsh edit wintest01
virsh edit將調用vi命令編輯/etc/libvirt/qemu/wintest01.xml配置文件。也可以直接通過vi命令進行編輯,修改,保存。
可以但不建議直接通過vi編輯。
[root@node1 qemu]# vi /etc/libvirt/qemu/wintest01.xml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | <!-- WARNING: THIS IS AN AUTO-GENERATED FILE. CHANGES TO IT ARE LIKELY TO BE OVERWRITTEN AND LOST. Changes to this xml configuration should be made using: virsh edit wintest01 or other application using the libvirt API. --> <domain type= 'kvm' > <name>wintest01</name> <uuid>fe31ea48-7d6a-f3cb-cede-2f9bd9dec2bd</uuid> <memory unit= 'KiB' > 524288 </memory> <currentMemory unit= 'KiB' > 524288 </currentMemory> <vcpu placement= 'static' > 2 </vcpu> <os> <type arch= 'x86_64' machine= 'rhel6.4.0' >hvm</type> <boot dev= 'hd' /> </os> <features> <acpi/> <apic/> <pae/> </features> <clock offset= 'utc' /> <on_poweroff>destroy</on_poweroff> <on_reboot>restart</on_reboot> <on_crash>restart</on_crash> <devices> <emulator>/usr/libexec/qemu-kvm</emulator> <disk type= 'file' device= 'disk' > <driver name= 'qemu' type= 'raw' cache= 'none' /> <source file= '/data/wintest01.img' /> <target dev= 'hda' bus= 'ide' /> <address type= 'drive' controller= '0' bus= '0' target= '0' unit= '0' /> </disk> <disk type= 'block' device= 'cdrom' > <driver name= 'qemu' type= 'raw' /> <target dev= 'hdc' bus= 'ide' /> <readonly/> <address type= 'drive' controller= '0' bus= '1' target= '0' unit= '0' /> </disk> <controller type= 'usb' index= '0' > <address type= 'pci' domain= '0x0000' bus= '0x00' slot= '0x01' function = '0x2' /> </controller> <controller type= 'ide' index= '0' > <address type= 'pci' domain= '0x0000' bus= '0x00' slot= '0x01' function = '0x1' /> </controller> < interface type= 'bridge' > <mac address= '52:54:00:2b:2f:fe' /> <source bridge= 'br0' /> <address type= 'pci' domain= '0x0000' bus= '0x00' slot= '0x03' function = '0x0' /> </ interface > <serial type= 'pty' > <target port= '0' /> </serial> <console type= 'pty' > <target type= 'serial' port= '0' /> </console> <input type= 'mouse' bus= 'ps2' /> <graphics type= 'vnc' port= '5911' autoport= 'no' listen= '0.0.0.0' > <listen type= 'address' address= '0.0.0.0' /> </graphics> <video> <model type= 'cirrus' vram= '9216' heads= '1' /> <address type= 'pci' domain= '0x0000' bus= '0x00' slot= '0x02' function = '0x0' /> </video> <memballoon model= 'virtio' > <address type= 'pci' domain= '0x0000' bus= '0x00' slot= '0x04' function = '0x0' /> </memballoon> </devices> <seclabel type= 'none' /> </domain> |
9. virsh console 控制檯管理linux虛擬機
配置virsh console見下文
# virsh console oeltest01
10. 其它virsh命令
(1) 掛起服務器
# virsh suspend oeltest01
(2) 恢復服務器
# virsh resume oeltest01
virsh命令豐富。可以執行各種維護任務,本文只是從維護與管理的角度例舉了常用的命令,爲該命令的使用提供一個思路。