打算部署kvm虛擬機器環境,下面是虛擬化部署前的一些準備工作:
作業系統環境安裝
1)修改核心模式為相容核心啟動
[root@ops ~]# uname -a
Linux openstack 2.6.32-431.el6.x86_64 #1 SMP Fri Nov 22 03:15:09 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
[root@ops ~]#vim /boot/grub/grub.conf
......
default=1 #由預設的0改為1,核心相容模式
2)關閉selinux,重啟後生效
[root@ops ~]#vim /etc/sysconfig/selinux
......
SELINUX=disabled
[root@ops ~]#setenforce 0
setenforce: SELinux is disabled
[root@ops ~]#getenforce
Disabled
3)關閉防火牆
[root@ops ~]#chkconfig ip6tables off
[root@ops ~]#chkconfig iptables off
4)重啟
[root@ops ~]#reboot
虛擬化環境配置
1)檢視是否支援虛擬機器
說明1:半虛擬化是不能執行與安裝KVM虛擬機器的。
[root@ops ~]#egrep '(vmx|svm)' --color=always /proc/cpuinfo
2)配置yum環境,確認yum源是好使的。(這一步驟省略,可以用預設yum源,也可以換用163或阿里的yum源,只要能正常使用就行)
3)安裝kvm軟體包
[root@ops ~]#yum -y install kvm python-virtinst libvirt tunctl bridge-utils virt-manager qemu-kvm-tools virt-viewer virt-v2v
補充安裝kvm虛擬化一些管理工具包
[root@ops ~]#yum -y install libguestfs-tools
---------------------------------------如果是centos7,操作如下---------------------------------------
yum install qemu-kvm libvirt libvirt-python libguestfs-tools virt-install virt-manager python-virtinst libvirt-client virt-viewer
systemctl enable libvirtd && systemctl start libvirtd
-----------------------------------------------------------------------------------------------------
檢視虛擬化環境
1)檢視虛擬機器環境
[root@ops ~]# /etc/init.d/libvirtd restart
Stopping libvirtd daemon: [ OK ]
Starting libvirtd daemon: [ OK ]
----------------------------------------------------------------------------------------------------------------------------------------------
啟動的時候報錯如下:
Starting libvirtd daemon: libvirtd: relocation error: libvirtd: symbol dm_task_get_info_with_deferred_remove, version Base not defined in file libdevmapper.so.1.02 with link time reference [FAILED]
解決辦法:
yum upgrade device-mapper-libs
----------------------------------------------------------------------------------------------------------------------------------------------
[root@ops ~]# virsh -c qemu:///system list
Id Name State
----------------------------------------------------
2)檢視kvm模組支援
[root@ops ~]# lsmod |grep kvm
kvm_intel 54285 0
kvm 333172 1 kvm_intel
3)檢視虛擬工具版本
[root@ops ~]# virsh --version
0.10.2
[root@ops ~]# virt-install --version
0.600.0
[root@ops ~]# ln -s /usr/libexec/qemu-kvm /usr/bin/qemu-kvm
手動配置虛擬網橋
1)關閉networkmanager服務
[root@ops ~]# chkconfig NetWorkManager off
[root@ops ~]# /etc/init.d/NetWorkManager stop
2)建立br0網橋
[root@ops ~]#cd /etc/sysconfig/network-scripts/
[root@ops ~]#cp ifcfg-em2 ifcfg-br0 #em2是本機內網網路卡
[root@ops ~]# cat ifcfg-em2
DEVICE=em2
HWADDR=44:A8:42:21:A6:01
TYPE=Ethernet
BRIDGE=br0 #將em2新增到網橋br0內
UUID=6dbfbd49-b6b9-4c51-b2d2-b3ecbead82e9
ONBOOT=yes
IPADDR=192.168.1.17
GATEWAY=192.168.1.1
NM_CONTROLLED=no #一定設定為no!讓em2不受networkmanager的控制
BOOTPROTO=static
[root@ops ~]# cat ifcfg-br0
DEVICE=br0
HWADDR=44:A8:42:21:A6:01
TYPE=Bridge
UUID=6dbfbd49-b6b9-4c51-b2d2-b3ecbead82e9
ONBOOT=yes
IPADDR=192.168.1.17
GATEWAY=192.168.1.1
NM_CONTROLLED=no
BOOTPROTO=static
3)關閉了networkmanager服務之後,才能通過重啟網路卡服務管理網路。
[root@ops ~]# /etc/init.d/network restart
4)檢視網橋br0資訊
[root@ops ~]# ifconfig
br0 Link encap:Ethernet HWaddr 44:A8:42:21:A6:01
inet addr:192.168.1.17 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::46a8:42ff:fe21:a601/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:6642 errors:0 dropped:0 overruns:0 frame:0
TX packets:12 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:2146342 (2.0 MiB) TX bytes:720 (720.0 b)
em1 Link encap:Ethernet HWaddr 44:A8:42:21:A6:00
inet addr:111.101.186.163 Bcast:103.10.86.63 Mask:255.255.255.192
inet6 addr: fe80::46a8:42ff:fe21:a600/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:5877878 errors:0 dropped:0 overruns:0 frame:0
TX packets:175381 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:921486122 (878.7 MiB) TX bytes:22894696 (21.8 MiB)
Interrupt:35
em2 Link encap:Ethernet HWaddr 44:A8:42:21:A6:01
inet6 addr: fe80::46a8:42ff:fe21:a601/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:2412349 errors:0 dropped:0 overruns:0 frame:0
TX packets:11 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:314457702 (299.8 MiB) TX bytes:872 (872.0 b)
Interrupt:38
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:238 errors:0 dropped:0 overruns:0 frame:0
TX packets:238 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:58469 (57.0 KiB) TX bytes:58469 (57.0 KiB)
virbr0 Link encap:Ethernet HWaddr 52:54:00:5F:95:B7 #virbr0虛擬網路卡有沒有都不影響虛擬機器的使用,有辦法可以將其刪除,但是保留也不影響~
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:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)
5)檢視網橋
[root@ops ~]# brctl show
bridge name bridge id STP enabled interfaces
br0 8000.44a84221a601 no em2
virbr0 8000.5254005f95b7 yes virbr0-nic
到此kvm虛擬化環境安裝完畢。
-----------------------------------------------------------------------------------
關閉虛擬網路卡virtbr0的方法:http://www.cnblogs.com/kevingrace/p/5772589.html
-----------------------------------------------------------------------------------