KVM虛擬機(jī)技術(shù)學(xué)習(xí)總結(jié)
最近在學(xué)習(xí)KVM,進(jìn)程不算太快,近期整理了一下KVM虛擬機(jī)技術(shù)學(xué)習(xí)筆記,現(xiàn)在就分享給大家,也給大家做個(gè)參考。有需要的朋友可以來了解一下。
KVM虛擬機(jī)的管理主要是通過virsh命令對(duì)虛擬機(jī)進(jìn)行管理。
1. 查看KVM虛擬機(jī)配置文件及運(yùn)行狀態(tài)
(1) KVM虛擬機(jī)默認(rèn)配置文件位置: /etc/libvirt/qemu/
autostart目錄是配置kvm虛擬機(jī)開機(jī)自啟動(dòng)目錄。
(2) virsh命令幫助
# virsh -help
或直接virsh命令和,再執(zhí)行子命令。如下所示。
[root@node1 ~]# virsh
歡迎使用 virsh,虛擬化的交互式終端。
輸入:'help' 來獲得命令的幫助信息
'quit' 退出
virsh # help
……
(3) 查看kvm虛擬機(jī)狀態(tài)
# virsh list --all
2. KVM虛擬機(jī)開機(jī)
# virsh start oeltest01
3. KVM虛擬機(jī)關(guān)機(jī)或斷電
(1) 關(guān)機(jī)
默認(rèn)情況下virsh工具不能對(duì)linux虛擬機(jī)進(jìn)行關(guān)機(jī)操作,linux操作系統(tǒng)需要開啟與啟動(dòng)acpid服務(wù)。在安裝KVM linux虛擬機(jī)必須配置此服務(wù)。
# chkconfig acpid on
# service acpid restart
virsh關(guān)機(jī)
# virsh shutdown oeltest01
(2) 強(qiáng)制關(guān)閉電源
# virsh destroy wintest01
4. 通過配置文件啟動(dòng)虛擬機(jī)
# virsh create /etc/libvirt/qemu/wintest01.xml
5. 配置開機(jī)自啟動(dòng)虛擬機(jī)
# virsh autostart oeltest01
autostart目錄是kvm虛擬機(jī)開機(jī)自啟動(dòng)目錄,可以看到該目錄中有KVM配置文件鏈接。
6. 導(dǎo)出KVM虛擬機(jī)配置文件
# virsh dumpxml wintest01 > /etc/libvirt/qemu/wintest02.xml
KVM虛擬機(jī)配置文件可以通過這種方式進(jìn)行備份。
7. 添加與刪除KVM虛擬機(jī)
(1) 刪除kvm虛擬機(jī)
# virsh undefine wintest01
說明:該命令只是刪除wintest01的配置文件,并不刪除虛擬磁盤文件。如下圖所示。
(2) 重新定義虛擬機(jī)配置文件
通過導(dǎo)出備份的配置文件恢復(fù)原KVM虛擬機(jī)的定義,并重新定義虛擬機(jī)。
# mv /etc/libvirt/qemu/wintest02.xml /etc/libvirt/qemu/wintest01.xml
# virsh define /etc/libvirt/qemu/wintest01.xml
8. 編輯KVM虛擬機(jī)配置文件
# virsh edit wintest01
virsh edit將調(diào)用vi命令編輯/etc/libvirt/qemu/wintest01.xml配置文件。也可以直接通過vi命令進(jìn)行編輯,修改,保存。
可以但不建議直接通過vi編輯。
[root@node1 qemu]# vi /etc/libvirt/qemu/wintest01.xml <!-- 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命令
(1) 掛起服務(wù)器
# virsh suspend oeltest01
(2) 恢復(fù)服務(wù)器
# virsh resume oeltest01
virsh命令豐富??梢詧?zhí)行各種維護(hù)任務(wù),本文只是從維護(hù)與管理的角度例舉了常用的命令,為該命令的使用提供一個(gè)思路。
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
KVM虛擬化Linux Bridge環(huán)境部署的方法步驟
本文主要介紹了KVM虛擬化Linux Bridge環(huán)境部署的方法步驟,使虛擬機(jī)連接到網(wǎng)絡(luò),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2023-05-05Ubuntu 18.04 LTS安裝KVM虛擬機(jī)的方法步驟
這篇文章主要介紹了Ubuntu 18.04 LTS安裝KVM虛擬機(jī)的方法步驟,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2018-06-06KVM虛擬化(一)——KVM虛擬機(jī)的介紹與簡(jiǎn)單使用
本篇文章主要介紹了KVM虛擬機(jī)的介紹與簡(jiǎn)單使用,具有一定的參考價(jià)值,有興趣的可以了解一下。2016-11-11