本次試驗基於隨筆《KVM網絡虛擬化之br0搭建》,請先完成網橋的搭建
1、安裝虛擬化服務
yum -y install qemu-kvm qemu-system libvirt virt-manager
2、測試服務是否安裝成功
service livcvirtd status
virsh list --all
3、編寫 xml 配置文件創建虛擬機
<domain type='kvm' id='1' <name>centos</name> //虛擬機名稱唯一
<memory unit='KiB'>102400</memory> <currentMemory unit='KiB'>102400</currentMemory> <vcpu placement='static'>1</vcpu> <os> <type arch='x86_64' machine='rhel6.6.0'>hvm</type> //arch指出系統架構類型,machine 則是機器類型,查看機器類型:qemu-system-x86_64 <boot dev='hd'/> //啟動介質,第一次需要裝系統可以選擇cdrom光盤啟動 </os> <features> <acpi/> //Advanced Configuration and Power Interface,高級配置與電源接口 <apic/> //Advanced Programmable Interrupt Controller,高級可編程中斷控制器 <pae/> //Physical Address Extension,物理地址擴展 </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> //kvm 默認 <disk type='file' device='disk'> <driver name='qemu' type='qcow2' cache='none'/> //鏡像類型 <source file='/var/lib/libvirt/images/cirros-0.3.3-x86_64-disk.img'/> //鏡像位置 <target dev='hda' bus='ide'/> </disk> <interface type='bridge'> //虛擬機網卡類型 <source bridge='br0'/> <target dev='vnet0'/> //宿主機設備名稱 </interface> <console type='pty' tty='/dev/pts/2'> //控制台登錄設置 <source path='/dev/pts/2'/> <target type='serial' port='0'/> </console> <graphics type='vnc' port='5900' autoport='yes' listen='127.0.0.1'> //配置VNC 設置 <listen type='address' address='127.0.0.1'/> </graphics> </devices> </domain>
4、運行虛擬機文件並啟動
virsh define test1.xml
virsh start centos #centos 為虛擬機名稱
5、測試系統是否啟動成功
virsh list --all
virsh console centos