1)檢查cpu是否支持虛擬化 [root@kevin ~] # grep vmx /proc/cpuinfo 若是有vmx信息輸出,就說明支持VT;若是沒有任何的輸出,說明你的cpu不支持,將沒法使用KVM虛擬機。 2)確保BIOS裏開啓虛擬化功能,即查看是否加載KVM模塊 [root@kevin ~] # lsmod | grep kvm kvm_intel 170086 0 kvm 566340 1 kvm_intel irqbypass 13503 1 kvm ========================================================= 若是沒有加載,運行如下命令: [root@kevin ~] # modprobe kvm [root@kevin ~] # modprobe kvm-intel [root@kevin ~] # lsmod | grep kvm kvm_intel 170086 0 kvm 566340 1 kvm_intel irqbypass 13503 1 kvm ========================================================= 內核模塊導出了一個名爲 /dev/kvm 的設備,這個設備將虛擬機的的地址空間獨立於內核或者任何應用程序的地址空間。 [root@kevin ~] # ll /dev/kvm crw-rw-rw-. 1 root kvm 10, 232 1月 29 11:56 /dev/kvm 3)橋接網絡 若是沒有brctl命令(用來管理網橋的工具),則須要安裝bridge-utils , [root@kevin ~] # yum -y install bridge-utils [root@kevin ~] # systemctl restart network 配置KVM的網橋模式 [root@kevin ~] # cd /etc/sysconfig/network-scripts/ [root@openstack network-scripts] # cp ifcfg-eno1 ifcfg-br0 [root@openstack network-scripts] # cat ifcfg-br0 TYPE= "Bridge" // 這一行修改成Bridge PROXY_METHOD= "none" BROWSER_ONLY= "no" BOOTPROTO= "none" DEFROUTE= "yes" IPV4_FAILURE_FATAL= "no" IPV6INIT= "no" IPV6_AUTOCONF= "yes" IPV6_DEFROUTE= "yes" IPV6_FAILURE_FATAL= "no" IPV6_ADDR_GEN_MODE= "stable-privacy" NAME= "br0" // 修改設備名稱爲br0 #UUID="fdbad04f-dae3-440e-8a8b-01d6a7bc9fe0" //這一行註釋 DEVICE= "br0" // 修改設備爲br0 ONBOOT= "yes" IPADDR= "192.168.10.210" PREFIX= "24" GATEWAY= "192.168.10.1" DNS1= "8.8.8.8" [root@openstack network-scripts] # cat ifcfg-eno1 TYPE= "Ethernet" BRIDGE=br0 // 添加這一行 PROXY_METHOD= "none" BROWSER_ONLY= "no" BOOTPROTO= "none" DEFROUTE= "yes" IPV4_FAILURE_FATAL= "no" IPV6INIT= "no" IPV6_AUTOCONF= "yes" IPV6_DEFROUTE= "yes" IPV6_FAILURE_FATAL= "no" IPV6_ADDR_GEN_MODE= "stable-privacy" NAME= "eno1" UUID= "fdbad04f-dae3-440e-8a8b-01d6a7bc9fe0" DEVICE= "eno1" ONBOOT= "yes" #IPADDR="192.168.10.210" //註釋掉這幾行 #PREFIX="24" #GATEWAY="192.168.10.1" #DNS1="8.8.8.8" 重啓網卡服務 [root@openstack network-scripts] # systemctl restart network 查看網卡 [root@openstack network-scripts] # brctl show bridge name bridge id STP enabled interfaces br0 8000.0894ef518b22 no eno1 virbr0 8000.52540095d7c2 yes virbr0-nic 查看ip信息 [root@openstack network-scripts] # ifconfig |head -20 br0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.10.210 netmask 255.255.255.0 broadcast 192.168.10.255 inet6 fe80::a94:efff:fe51:8b22 prefixlen 64 scopeid 0x20<link> ether 08:94:ef:51:8b:22 txqueuelen 1000 (Ethernet) RX packets 856 bytes 52981 (51.7 KiB) RX errors 0 dropped 2 overruns 0 frame 0 TX packets 120 bytes 23450 (22.9 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 eno1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 ether 08:94:ef:51:8b:22 txqueuelen 1000 (Ethernet) RX packets 10077 bytes 793083 (774.4 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 1184 bytes 228415 (223.0 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 device interrupt 16 eno2: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500 ether 08:94:ef:51:8b:23 txqueuelen 1000 (Ethernet) RX packets 0 bytes 0 (0.0 B) [root@openstack network-scripts] # ping www.baidu.com PING www.a.shifen.com (61.135.169.121) 56(84) bytes of data. 64 bytes from 61.135.169.121 (61.135.169.121): icmp_seq=1 ttl=55 time =2.08 ms 64 bytes from 61.135.169.121 (61.135.169.121): icmp_seq=2 ttl=55 time =1.80 ms ........ 4)安裝libvirt及kvm libvirt是管理虛擬機的API庫,不只支持KVM虛擬機,也能夠管理Xen等方案下的虛擬機。 [root@kevin ~] # yum -y install libcanberra-gtk2 qemu-kvm.x86_64 qemu-kvm-tools.x86_64 libvirt.x86_64 libvirt-cim.x86_64 libvirt-client.x86_64 libvirt-java.noarch libvirt-python.x86_64 libiscsi-1.7.0-5.el6.x86_64 dbus-devel virt-clone tunctl virt-manager libvirt libvirt-python python-virtinst 因爲要用virt-manager圖形化安裝虛擬機,因此還須要安裝X-window(這個在前面部署VNC環境裏就已經安裝了) [root@kevin ~] # yum groupinstall "X Window System" 安裝中文字符,解決界面亂碼問題 [root@kevin ~] # yum install -y dejavu-lgc-sans-fonts [root@kevin ~] # yum groupinstall -y "Fonts" 啓用libvirt [root@kevin ~] # systemctl enable libvirtd [root@kevin ~] # systemctl start libvirtd |