CentOS 6.5下安裝KVM
2024-06-28 16:03:07
供稿:網(wǎng)友
一、檢查CPU是否支持虛擬化。(在主板BIOS中開啟CPU的VirtualizationTechnology)# grep -E -o 'vmx|svm' /PRoc/cpuinfovmx二、基礎(chǔ)環(huán)境配置1.安裝KVM軟件包# yum -y groupinstall 'Virtualization' 'Virtualization Client' 'Virtualization Platform' 'Virtualization Tools'查看模塊# lsmod | grep kvmkvm_intel 53484 6kvm 316506 1 kvm_intel2.網(wǎng)卡橋接配置2.1 如果啟用了NetworkManager,最好關(guān)閉該服務(wù),因為該服務(wù)與network有沖突。chkconfig NetworkManager offservice NetworkManager stop2.2 關(guān)閉 selinux 并重啟系統(tǒng)# vi /etc/sysconfig/selinuxSELINUX=disabled2.3 編輯網(wǎng)卡# vi /etc/sysconfig/network-scripts/ifcfg-eth0DEVICE=eth0TYPE=EthernetONBOOT=yesBOOTPROTO=noneBRIDGE=br0# vi /etc/sysconfig/network-scripts/ifcfg-br0DEVICE=br0TYPE=BridgeONBOOT=yesBOOTPROTO=noneIPADDR=192.168.200.15NETMASK=255.255.255.0GATEWAY=192.168.200.1DNS1=202.106.0.202.4 重啟服務(wù)器reboot2.5 查看網(wǎng)絡(luò)# brctl showbridge name bridge idSTP enabledinterfacesbr0 8000.ac4e914d0aa2noeth0virbr0 8000.5254004d5befyesvirbr0-nic2.6 檢查ip轉(zhuǎn)發(fā)是否開啟# cat /etc/sysctl.conf |grep ip_forwardnet.ipv4.ip_forward = 0 3.創(chuàng)建虛擬機3.1 創(chuàng)建磁盤鏡像文件,文件格式qcow2格式是kvm支持的標準格式,raw格式為虛擬磁盤文件通用格式。創(chuàng)建文件名win2008r2.qcow2的磁盤鏡像文件名,文件格式為qcow2,磁盤大小為100G# qemu-img create -f qcow2 /kvm/pjgl/win2008r2.qcow2 100G查看磁盤鏡像文件信息 # qemu-img info /kvm/pjgl/win2008r2.qcow23.2 創(chuàng)建虛擬機配置文件<!--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 win2008r2or other application using the libvirt API.--><domain type='kvm'> <name>win2008r2</name> <uuid>7b6f172b-7a03-c629-f6cb-4127bdbdfb51</uuid> <memory unit='KiB'>2097152</memory> <currentMemory unit='KiB'>2097152</currentMemory> <vcpu placement='static'>2</vcpu> <os> <type arch='x86_64' machine='rhel6.6.0'>hvm</type> <boot dev='cdrom'/> <boot dev='hd'/> </os> <features> <acpi/> <apic/> <pae/> </features> <clock offset='localtime'> <timer name='rtc' tickpolicy='catchup'/> </clock> <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='qcow2' cache='writeback'/> <source file='/kvm/win2008r2/win2008r2.qcow2'/> <target dev='hda' bus='ide'/> <address type='drive' controller='0' bus='0' target='0' unit='0'/> </disk> <disk type='file' device='cdrom'> <driver name='qemu' type='raw'/> <source file='/iso/Windows_2008R2_64-bit.ISO'/> <target dev='hdc' bus='ide'/> <readonly/> <address type='drive' controller='0' bus='1' target='0' unit='0'/> </disk> <controller type='usb' index='0' model='ich9-ehci1'> <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x7'/> </controller> <controller type='usb' index='0' model='ich9-uhci1'> <master startport='0'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0' multifunction='on'/> </controller> <controller type='usb' index='0' model='ich9-uhci2'> <master startport='2'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x1'/> </controller> <controller type='usb' index='0' model='ich9-uhci3'> <master startport='4'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x04' 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:b3:c6:d3'/> <source bridge='br0'/> <model type='e1000'/> <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='tablet' bus='usb'/> <input type='mouse' bus='ps2'/> <graphics type='vnc' port='5903' autoport='no' listen='0.0.0.0'> <listen type='address' address='0.0.0.0'/> </graphics> <video> <model type='vga' 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='0x05' function='0x0'/> </memballoon> </devices></domain>將上面的內(nèi)容復(fù)制到win2008r2.xml文件后,根據(jù)情況修改系統(tǒng)名稱、UUID、MAC地址、光盤鏡像的路徑、磁盤鏡像的路徑等。3.3 啟動虛擬機# virsh# define /kvm/pjgl/win2008r2.xml# list --all# start win2008r23.4 配置防火墻策略防火墻缺省是不允許連接這些端口的,使用下列步驟配置防火墻,允許VNC客戶端連接VNC server。# vi /etc/sysconfig/iptables 1) 找到下面的語句:-A INPUT -j REJECT --reject-with icmp-host-prohibited在此行之前,加上下面的內(nèi)容:-A INPUT -m state --state NEW -m tcp -p tcp --dport 5900:5920 -j ACCEPT #允許其它機器訪問本機的5900到5903端口2) 然后使用root身份重新啟動防火墻:# service iptables restart3) 設(shè)置開機自動啟動# chkconfig iptables on3.5 使用TightVNC Viewer客戶端,進入系統(tǒng)UI界面安裝操作系統(tǒng),并進行配置即可。