x86虚拟机NXVM_Centos6.5 x86_64系统安装kvm虚拟机—基础篇
KVM簡介:
KVM是開源軟件,全稱是kernel-based virtual machine(基于內核的虛擬機)。
是x86架構且硬件支持虛擬化技術(如 intel VT 或 AMD-V)的Linux全虛擬化解決方案。
它包含一個為處理器提供底層虛擬化 可加載的核心模塊kvm.ko(kvm-intel.ko或kvm-AMD.ko)。
KVM還需要一個經過修改的QEMU軟件(qemu-kvm),作為虛擬機上層控制和界面。
KVM能在不改變linux或windows鏡像的情況下同時運行多個虛擬機,(它的意思是多個虛擬機使用同一鏡像)并為每一個虛擬機配置個性化硬件環境(網卡、磁盤、圖形適配器……)。
在主流的Linux內核,如2.6.20以上的內核均已包含了KVM核心。
安裝kvm虛擬機之前準備工作:
1.關閉iptables防火墻和selinux。[root@taokey?~]#?/etc/init.d/iptables?stop
[root@taokey?~]#?chkconfig?iptables?off
[root@taokey?~]#?chkconfig?--list?iptables
iptables????????0:off???1:off???2:off???3:off???4:off???5:off???6:off
[root@taokey?~]#?vim?/etc/sysconfig/selinux
SELINUX=disabled
[root@taokey?~]#?setenforce?0
2.vmware workstation安裝kvm的時候,需要開啟CPU支持虛擬化。
下邊開始介紹Centos6.5 x86_64系統安裝kvm虛擬機
一、安裝kvm虛擬機
1.查看CPU是否支持kvm完全虛擬機。[root@taokey?~]#?grep?"flags"?/proc/cpuinfo
flags???????????:?fpu?vme?de?pse?tsc?msr?pae?mce?cx8?apic?sep?mtrr?pge?mca?cmov?pat?pse36?clflush?dts?mmx?fxsr?sse?sse2?ss?syscall?nx?rdtscp?lm?constant_tsc?up?arch_perfmon?pebs?bts?xtopology?tsc_reliable?nonstop_tsc?aperfmperf?unfair_spinlock?pni?pclmulqdq?vmx?ssse3?cx16?pcid?sse4_1?sse4_2?x2apic?popcnt?xsave?avx?hypervisor?lahf_lm?arat?epb?xsaveopt?pln?pts?dts?tpr_shadow?vnmi?ept?vpid
注釋:如果輸出的信息中有vmx,說明intel處理器支持完全虛擬化。如果顯示svm,說明是AMD的處理器支持虛擬化。
2.安裝kvm和其他虛擬化所需管理軟件包。[root@taokey?~]#?yum?install?-y?kvm?virt-*?libvirts?bridge-utils?qemu-img
軟件包名稱介紹:
Kvm:軟件包中含有KVM內核模塊,它在默認linux內核中提供kvm管理程序
Libvirts:安裝虛擬機管理工具,使用virsh等命令來管理和控制虛擬機。
Bridge-utils:設置網絡網卡橋接。
Virt-*:創建、克隆虛擬機命令,以及圖形化管理工具virt-manager
Qemu-img:安裝qemu組件,使用qemu命令來創建磁盤等。
3.加載kvm模塊,查看kvm模塊是否被加載[root@taokey?~]#?modprobe?kvm-intel
[root@taokey?~]#?lsmod?|?grep?kvm
kvm_intel??????????????54285??0
kvm???????????????????333172??1?kvm_intel
4.重啟確實KVM是否被加載[root@taokey?~]#?reboot
[root@taokey?~]#?lsmod?|?grep?kvm
kvm_intel??????????????54285??0
kvm???????????????????333172??1?kvm_intel
5.查看已打開虛擬機列表[root@taokey?~]#?virsh?list
Id????Name???????????????????????????State
----------------------------------------------------
6.配置eth0、br0網卡[root@taokey?~]#?more?/etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
HWADDR=00:0C:29:33:B3:E5
TYPE=Ethernet
UUID=142284ae-3173-4b0a-80d8-437c26a96719
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=none
BRIDGE=br0
[root@taokey?~]#?more?/etc/sysconfig/network-scripts/ifcfg-br0
DEVICE=br0
HWADDR=00:0C:29:33:B3:E5
TYPE=Bridge
UUID=142284ae-3173-4b0a-80d8-437c26a96719
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=static
IPADDR=10.0.1.149
NETMASK=255.255.255.0
GATEWAY=10.0.1.1
[root@taokey?~]#?/etc/init.d/network?restart
7.查看目前所有的網橋接口[root@taokey?~]#?brctl?show
bridge?name?????bridge?id???????????????STP?enabled?????interfaces
br0?????????????8000.000c2933b3e5???????no??????????????eth0
virbr0??????????8000.525400d969b8???????yes?????????????virbr0-nic
8.修改VNC服務端的配置文件[root@taokey?~]#?vim?/etc/libvirt/qemu.conf
vnc_listen?=?"0.0.0.0"???第十二行,把vnc_listen前面的#號去掉。
9.重啟libvirtd和messagebus服務[root@taokey?~]#?/etc/init.d/libvirtd?restart
Stopping?libvirtd?daemon:??????????????????????????????????[??OK??]
Starting?libvirtd?daemon:?libvirtd:?initialization?failed??[FAILED]
解決辦法:
[root@taokey?libvirt]#?echo?"export?LC_ALL=en_US.UTF-8"??>>??/etc/profile
[root@taokey?libvirt]#?source?/etc/profile
[root@taokey?libvirt]#?/etc/init.d/libvirtd?restart
Stopping?libvirtd?daemon:??????????????????????????????????[FAILED]
Starting?libvirtd?daemon:?2014-08-15?16:14:18.595+0000:?2429:?info?:?libvirt?version:?0.10.2,?package:?29.el6_5.11?(CentOS?BuildSystem?,?2014-07-31-18:52:08,?c6b8.bsys.dev.centos.org)
2014-08-15?16:14:18.595+0000:?2429:?warning?:?virGetHostname:2294?:?getaddrinfo?failed?for?'taokey':?Name?or?service?not?known
[??OK??]
[root@taokey?~]#?/etc/init.d/messagebus?restart
Stopping?system?message?bus:???????????????????????????????[??OK??]
Starting?system?message?bus:???????????????????????????????[??OK??]
二、在宿主機上創建、安裝kvm虛擬機創建鏡像文件目錄和虛擬磁盤存放目錄[root@taokey?~]#?mkdir?/iso
[root@taokey?~]#?mkdir?-p?/data/kvmdisk
2.把Centos6.5系統的鏡像文件拷貝到iso目錄下[root@taokey?~]#?dd?if=/dev/cdrom?of=/iso/Centos6.iso
8726528+0?records?in
8726528+0?records?out
4467982336?bytes?(4.5?GB)?copied,?298.268?s,?15.0?MB/s
3.創建kvm虛擬機的磁盤文件[root@taokey?~]#?cd?/etc/libvirt/
[root@taokey?libvirt]#?qemu-img?create?-f?qcow2?-o?preallocation=metadata?kvm_mode.img?10G
Formatting?'kvm_mode.img',?fmt=qcow2?size=10737418240?encryption=off?cluster_size=65536?preallocation='metadata'
4.安裝虛擬機[root@taokey?libvirt]#?virt-install?--name=kvm_mode_5566?--ram?1024?--vcpus=1?-f?/etc/libvirt/kvm_mode.img?--cdrom=/iso/Centos6.iso?--graphics?vnc,listen=0.0.0.0,port=7788?--force?--autostart
Starting?install...
ERROR????internal?error?Process?exited?while?reading?console?log?output:?char?device?redirected?to?/dev/pts/2
qemu-kvm:?-drive?file=/etc/libvirt/kvm_mode.img,if=none,id=drive-ide0-0-0,format=raw,cache=none:?could?not?open?disk?p_w_picpath?/etc/libvirt/kvm_mode.img:?Permission?denied
Domain?installation?does?not?appear?to?have?been?successful.
If?it?was,?you?can?restart?your?domain?by?running:
virsh?--connect?qemu:///system?start?kvm_mode_5566
otherwise,?please?restart?your?installation.
解決辦法:
[root@taokey?libvirt]#?chmod?-R?777?/etc/libvirt
[root@taokey?libvirt]#?virt-install?--name=kvm_mode_5566?--ram?1024?--vcpus=1?-f?/etc/libvirt/kvm_mode.img?--cdrom=/iso/Centos6.iso?--graphics?vnc,listen=0.0.0.0,port=7788?--force?--autostart
Starting?install...
Creating?domain...???????????????????????????????????????????????????????????????????????????????????????????|????0?B?????00:00
Cannot?open?display:
Run?'virt-viewer?--help'?to?see?a?full?list?of?available?command?line?options
Domain?installation?still?in?progress.?You?can?reconnect?to
the?console?to?complete?the?installation?process.
三、VNC客戶端連接KVM虛擬機,設置IP地址。用VNC連接,進行創建kvm虛擬機(VNC連上之后,跟安裝linux Centos 6.5系統一樣,重新裝一次)
2.在宿主機上列出創建的kvm虛擬機,手動開啟新創建的虛擬機[root@taokey?~]#?virsh
Welcome?to?virsh,?the?virtualization?interactive?terminal.
Type:??'help'?for?help?with?commands
'quit'?to?quit
virsh?#?list?--all
Id????Name???????????????????????????State
----------------------------------------------------
-?????kvm_mode_5566??????????????????shut?off
virsh?#?start?kvm_mode_5566
Domain?kvm_mode_5566?started
3.設置靜態IP地址
重啟網卡會報錯。
解決辦法:
eth0網卡配置文件中的
HWADDR=00:0C:29:33:B3:E5修改成MACADDR=00:0C:29:33:B3:E5
rm -rf /etc/udev/rules.d/70-persistent-net.rules
如圖所示:
reboot新創建的kvm_mode_5566虛擬機,重啟network服務就可以配置上IP地址了。
[root@kvm-mode-7788 ~]# more /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
MACADDR=52:54:00:80:7E:A5
TYPE=Ethernet
UUID=7d042162-53e9-4ef1-ba2f-bf3b892bb353
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=static
IPADDR=10.0.1.228
NETMASK=255.255.255.0
GATEWAY=10.0.1.1
[root@kvm-mode-7788 ~]# ping www.baidu.com
PING www.a.shifen.com (119.75.218.77) 56(84) bytes of data.
64 bytes from www.baidu.com (119.75.218.77): icmp_seq=1 ttl=54 time=3.05 ms
64 bytes from www.baidu.com (119.75.218.77): icmp_seq=2 ttl=54 time=4.82 ms
64 bytes from www.baidu.com (119.75.218.77): icmp_seq=3 ttl=54 time=3.72 ms
^C
--- www.a.shifen.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2252ms
rtt min/avg/max/mdev = 3.055/3.866/4.822/0.730 ms
4.查看下宿主機上的虛擬機。[root@taokey?~]#?virsh
Welcome?to?virsh,?the?virtualization?interactive?terminal.
Type:??'help'?for?help?with?commands
'quit'?to?quit
virsh?#?list?--all
Id????Name???????????????????????????State
----------------------------------------------------
1?????kvm_mode_5566??????????????????running
virsh?#
到此為止,試驗完畢。
下一篇會介紹通過命令克隆虛擬機和修改配置文件創建虛擬機。
總結
以上是生活随笔為你收集整理的x86虚拟机NXVM_Centos6.5 x86_64系统安装kvm虚拟机—基础篇的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 强化学习 --- 马尔科夫决策过程详解(
- 下一篇: PHP框架-yii2(一)