二,安裝配置KVM
代碼如下 |
複製代碼 |
# yum -y install kvm python-virtinst libvirt bridge-utils \ virt-manager qemu-kvm-tools virt-viewer virt-v2v qemu-kvm tunctl [root@localhost ~]#vim /etc/sysconfig/selinux //關閉selinux SELINUX=disabled [root@localhost ~]#reboot [root@localhost ~]# cat /etc/redhat-release CentOS release 6.5 (Final) //centos 6.5 |
三,啟動libvirtd
代碼如下 |
複製代碼 |
[root@localhost ~]# /etc/init.d/libvirtd start //啟動 [root@localhost ~]# ps -e|grep libvirtd //查看是否啟動 19458 ? 00:00:01 libvirtd
|
四,查看kvm模組是否正確載入
代碼如下 |
複製代碼 |
[root@localhost ~]# lsmod |grep kvm kvm_intel 54285 0 kvm 333172 1 kvm_intel |
五,配置網路橋接
代碼如下 |
複製代碼 |
[root@localhost network-scripts]# cat ifcfg-eth0 |awk '{if($0 !~ /^$/ && $0 !~ /^#/) {print $0}}' DEVICE=eth0 TYPE=Ethernet ONBOOT=yes BOOTPROTO=none BRIDGE=br0 IPV6INIT=no HWADDR=F8:BC:12:60:99:86 [root@localhost network-scripts]# cat ifcfg-br0 |awk '{if($0 !~ /^$/ && $0 !~ /^#/) {print $0}}' DEVICE=br0 TYPE=Bridge ONBOOT=yes BOOTPROTO=static IPADDR=192.168.10.103 GATEWAY=192.168.10.1 NETMASK=255.255.255.0 DNS1=192.168.10.1 IPV6INIT=no DELAY=0
|
重啟網路,發現報以下錯誤:
[root@localhost network-scripts]# /etc/init.d/network start
彈出環回介面: [確定]
彈出介面 eth0: 錯誤:啟用串連失敗:Master connection not found or invalid
[失敗]
彈出介面 br0: 錯誤:啟用串連失敗:Failed to determine connection's virtual interface name
[失敗]
RTNETLINK answers: File exists
RTNETLINK answers: File exists
RTNETLINK answers: File exists
解決辦法:
[root@localhost rules.d]# service NetworkManager stop //這個關閉掉就行
停止 NetworkManager 守護進程: [確定]
[root@localhost rules.d]# service network restart
正在關閉介面 br0: [確定]
正在關閉介面 eth0: [確定]
關閉環回介面: [確定]
彈出環回介面: [確定]
彈出介面 eth0: [確定]
彈出介面 br0: Determining if ip address 192.168.10.103 is already in use for device br0...
[確定]
如果以下內容就說明配置成功了:
[root@localhost network-scripts]# ifconfig
br0 Link encap:Ethernet HWaddr F8:BC:12:60:99:86 //有這個就OK
inet addr:192.168.10.103 Bcast:192.168.10.255 Mask:255.255.255.0
inet6 addr: fe80::fabc:12ff:fe60:9986/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:36416 errors:0 dropped:0 overruns:0 frame:0
TX packets:28648 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:13151508 (12.5 MiB) TX bytes:5962449 (5.6 MiB)
eth0 Link encap:Ethernet HWaddr F8:BC:12:60:99:86
inet6 addr: fe80::fabc:12ff:fe60:9986/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:1360857 errors:0 dropped:0 overruns:0 frame:0
TX packets:902173 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:1913592871 (1.7 GiB) TX bytes:72387220 (69.0 MiB)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:176842 errors:0 dropped:0 overruns:0 frame:0
TX packets:176842 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:880282316 (839.5 MiB) TX bytes:880282316 (839.5 MiB)
virbr0 Link encap:Ethernet HWaddr 52:54:00:1A:B6:F1
inet addr:192.168.122.1 Bcast:192.168.122.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:37 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 b) TX bytes:4651 (4.5 KiB)
[root@localhost network-scripts]# brctl show
bridge name bridge id STP enabled interfaces
br0 8000.f8bc12609986 no eth0 //有這個就OK
virbr0 8000.5254001ab6f1 yes virbr0-nic
六,用virt-install產生.img檔案
代碼如下 |
複製代碼 |
# virt-install --name=ubuntu1 \ --ram 1024 --vcpus=1 \ --disk path=/root/ubuntu1.img,size=10 \ --accelerate --cdrom /root/ubuntu-14.04-desktop-amd64.iso \ --graphics vnc,port=5920 --network bridge=br0
|
如果報以下錯誤:
could not open disk image : Permission denied
解決方案:
[root@localhost ~]# cat /etc/libvirt/qemu.conf |awk '{if($0 !~ /^$/ && $0 !~ /^#/) {print $0}}'
vnc_listen = "0.0.0.0"
user = "root" //去掉注釋
group = "root" //去掉注釋
dynamic_ownership = 0 //去掉注釋,把1改為0
這一步做完,系統檔案就好了。
七,啟動虛擬機器
如果報以下錯誤
[root@localhost ~]# virsh start ubuntu1
錯誤:域已經活躍
解決辦法:
[root@localhost ~]# pkill qemu-kvm
[root@localhost ~]# virsh start ubuntu1
域 ubuntu1 已開始
[root@localhost ~]# virt-viewer ubuntu1 //進入圖形介面