kvm虚拟化学习笔记(一)之kvm虚拟化环境安装

前端之家收集整理的这篇文章主要介绍了kvm虚拟化学习笔记(一)之kvm虚拟化环境安装前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

1.操作系统安装

本文采用CentOS6.5x86_64操作系统,也可以采用RHEL/CentOS6.x。选择ESXi主机平台上的虚拟机扮演KVM宿主机。

(1)开启ESXI主机网卡的混杂模式,让物理机能够与KVM虚拟机正常通信。

如果是VMware Workstation虚拟机,则需要在物理机的BIOS中开启VT功能,然后虚拟机的处理器也需要开启虚拟化功能,如下所示:

(2)关闭selinux、iptables

[root@node1~]#setenforce0;sed-i'/SELINUX/s/enforcing/disabled/g'/etc/selinux/config
[root@node1~]#chkconfigip6tablesoff
[root@node1~]#chkconfigiptablesoff

(3)修改主机名

[root@node1~]#sed-i'/HOSTNAME/s/localhost.localdomain/node1/g'/etc/sysconfig/network
[root@node1~]#echo"10.10.172.191node1">>/etc/hosts


2.虚拟化环境配置

(1)查看是否支持虚拟化

说明1:半虚拟化是不能运行与安装KVM虚拟机的。虚拟机修改.vmx文件追加vhv.enable = "TRUE",物理机需要开启VT功能

[root@node1~]#egrep'(vmx|svm)'--color=always/proc/cpuinfo

(2)配置yum环境(采用系统默认即可)

[root@node1~]#cd/etc/yum.repos.d/
[root@node1yum.repos.d]#ll
total16
-rw-r--r--.1rootroot1926Nov272013CentOS-Base.repo
-rw-r--r--.1rootroot638Nov272013CentOS-Debuginfo.repo
-rw-r--r--.1rootroot630Nov272013CentOS-Media.repo
-rw-r--r--.1rootroot3664Nov272013CentOS-Vault.repo
[root@node1yum.repos.d]#catCentOS-Base.repo
#CentOS-Base.repo
#
#ThemirrorsystemusestheconnectingIPaddressoftheclientandthe
#updatestatusofeachmirrortopickmirrorsthatareupdatedtoand
#geographicallyclosetotheclient.YoushouldusethisforCentOSupdates
#unlessyouaremanuallypickingothermirrors.
#
#Ifthemirrorlist=doesnotworkforyou,asafallbackyoucantrythe
#remarkedoutbaseurl=lineinstead.
#
#

[base]
name=CentOS-$releasever-Base
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
#baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

#releasedupdates
[updates]
name=CentOS-$releasever-Updates
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
#baseurl=http://mirror.centos.org/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

#additionalpackagesthatmaybeuseful
[extras]
name=CentOS-$releasever-Extras
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
#baseurl=http://mirror.centos.org/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

#additionalpackagesthatextendfunctionalityofexistingpackages
[centosplus]
name=CentOS-$releasever-Plus
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus
#baseurl=http://mirror.centos.org/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

#contrib-packagesbyCentosUsers
[contrib]
name=CentOS-$releasever-Contrib
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=contrib
#baseurl=http://mirror.centos.org/centos/$releasever/contrib/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
[root@node1yum.repos.d]#

(3)安装kvm软件包

#yum-yinstallkvmpython-virtinstlibvirttunctlbridge-utilsvirt-managerqemu-kvm-toolsvirt-viewervirt-v2v

安装kvm虚拟化一些管理工具包

#yum-yinstalllibguestfs-tools
Installed:
libvirt.x86_640:0.10.2-62.el6python-virtinst.noarch0:0.600.0-31.el6qemu-kvm.x86_642:0.12.1.2-2.503.el6_9.3qemu-kvm-tools.x86_642:0.12.1.2-2.503.el6_9.3
tunctl.x86_640:1.5-3.el6virt-manager.x86_640:0.9.0-34.el6virt-v2v.x86_640:0.9.1-5.el6_5virt-viewer.x86_640:2.0-18.el6

DependencyInstalled:
augeas-libs.x86_640:1.0.0-10.el6btrfs-progs.x86_640:0.20-0.2.git91d9eec.el6celt051.x86_640:0.5.1.3-0.el6
cyrus-sasl-md5.x86_640:2.1.23-15.el6_6.2ebtables.x86_640:2.0.9-6.el6febootstrap-supermin-helper.x86_640:3.21-4.el6
gdisk.x86_640:0.8.10-1.el6genisoimage.x86_640:1.1.9-12.el6glusterfs.x86_640:3.7.9-12.el6
glusterfs-api.x86_640:3.7.9-12.el6glusterfs-client-xlators.x86_640:3.7.9-12.el6glusterfs-libs.x86_640:3.7.9-12.el6
gnutls-utils.x86_640:2.12.23-21.el6gpxe-roms-qemu.noarch0:0.9.7-6.16.el6gtk-vnc.x86_640:0.3.10-3.el6
gtk-vnc-python.x86_640:0.3.10-3.el6hivex.x86_640:1.3.3-4.3.el6iscsi-initiator-utils.x86_640:6.2.0.873-27.el6_9
libcacard.x86_640:0.15.0-2.el6libcgroup.x86_640:0.40.rc1-24.el6_9libgovirt.x86_640:0.3.2-3.el6
libguestfs.x86_641:1.20.11-20.el6libvirt-client.x86_640:0.10.2-62.el6libvirt-python.x86_640:0.10.2-62.el6
lzop.x86_640:1.02-0.9.rc1.el6mailcap.noarch0:2.1.31-2.el6nc.x86_640:1.84-24.el6
netcf-libs.x86_640:0.2.4-4.el6netpbm.x86_640:10.47.05-11.el6netpbm-progs.x86_640:10.47.05-11.el6
numad.x86_640:0.5-12.20150602git.el6perl-Class-MethodMaker.x86_640:2.16-6.el6perl-Class-Singleton.noarch0:1.4-6.el6
perl-Compress-Raw-Zlib.x86_641:2.021-144.el6perl-Compress-Zlib.x86_640:2.021-144.el6perl-Crypt-SSLeay.x86_640:0.57-17.el6
perl-DateTime.x86_641:0.5300-3.el6perl-HTML-Parser.x86_640:3.64-2.el6perl-HTML-Tagset.noarch0:3.20-4.el6
perl-IO-Compress-Base.x86_640:2.021-144.el6perl-IO-Compress-Zlib.x86_640:2.021-144.el6perl-IO-String.noarch0:1.08-9.el6
perl-List-MoreUtils.x86_640:0.22-10.el6perl-Params-Validate.x86_640:0.92-3.el6perl-Sys-Guestfs.x86_641:1.20.11-20.el6
perl-Sys-Virt.x86_640:0.10.2-6.el6perl-Term-ProgressBar.noarch0:2.09-10.el6perl-TermReadKey.x86_640:2.30-13.el6
perl-URI.noarch0:1.40-2.el6perl-XML-DOM.noarch0:1.44-7.el6perl-XML-DOM-XPath.noarch0:0.14-4.el6
perl-XML-Parser.x86_640:2.36-7.el6perl-XML-RegExp.noarch0:0.03-7.el6perl-XML-XPath.noarch0:1.13-10.el6
perl-XML-XPathEngine.noarch0:0.12-3.el6perl-YAML-Tiny.noarch0:1.40-2.el6perl-hivex.x86_640:1.3.3-4.3.el6
perl-libintl.x86_640:1.20-1.el6perl-libwww-perl.noarch0:5.833-5.el6qemu-img.x86_642:0.12.1.2-2.503.el6_9.3
radvd.x86_640:1.6-1.el6rest.x86_640:0.7.92-3.el6scrub.x86_640:2.2-2.el6
seabios.x86_640:0.6.1.2-30.el6sgabios-bin.noarch0:0-0.3.20110621svn.el6spice-glib.x86_640:0.26-8.el6
spice-gtk.x86_640:0.26-8.el6spice-gtk-python.x86_640:0.26-8.el6spice-server.x86_640:0.12.4-16.el6
usbredir.x86_640:0.5.1-3.el6vgabios.noarch0:0.6b-3.8.el6yajl.x86_640:1.0.7-3.el6

Updated:
lvm2-libs.x86_640:2.02.143-12.el6_9.1

DependencyUpdated:
cyrus-sasl.x86_640:2.1.23-15.el6_6.2cyrus-sasl-gssapi.x86_640:2.1.23-15.el6_6.2cyrus-sasl-lib.x86_640:2.1.23-15.el6_6.2
cyrus-sasl-plain.x86_640:2.1.23-15.el6_6.2device-mapper.x86_640:1.02.117-12.el6_9.1device-mapper-event.x86_640:1.02.117-12.el6_9.1
device-mapper-event-libs.x86_640:1.02.117-12.el6_9.1device-mapper-libs.x86_640:1.02.117-12.el6_9.1device-mapper-persistent-data.x86_640:0.6.2-0.1.rc7.el6
glib2.x86_640:2.28.8-9.el6gnutls.x86_640:2.12.23-21.el6libdrm.x86_640:2.4.65-2.el6
lvm2.x86_640:2.02.143-12.el6_9.1perl.x86_644:5.10.1-144.el6perl-CGI.x86_640:3.51-144.el6
perl-ExtUtils-MakeMaker.x86_640:6.55-144.el6perl-ExtUtils-ParseXS.x86_641:2.2003.0-144.el6perl-Module-Pluggable.x86_641:3.90-144.el6
perl-Pod-Escapes.x86_641:1.04-144.el6perl-Pod-Simple.x86_641:3.13-144.el6perl-Test-Harness.x86_640:3.17-144.el6
perl-Test-Simple.x86_640:0.92-144.el6perl-devel.x86_644:5.10.1-144.el6perl-libs.x86_644:5.10.1-144.el6
perl-version.x86_643:0.77-144.el6

Complete!
注:
CentOS6使用工具virt-install,就是安装python-virtins软件包以及其依赖包libvirt-client、libvirt-python等,而Centos7没有python-virtins这个包,需要安装virt-install软件包(其依赖包含有libvirt-client、libvirt-python)。
CentOS7安装kvm以及需要的依赖包,使用如下命令。
#yuminstallqemu-kvmqemu-kvm-toolsvirt-managerlibvirtvirt-installbridge-utilsvirt-viewervirt-v2vlibguestfs-tools-y

kvm相关安装包及其作用

qemu-kvm主要的KVM程序包,安装kvm就是安装qemu-kvm和qemu-img
python-virtinst创建虚拟机所需要的命令行工具和程序库
virt-managerGUI虚拟机管理工具
virt-top虚拟机统计命令
virt-viewerGUI连接程序,连接到已配置好的虚拟机
libvirtC语言工具包,提供libvirt服务
libvirt-client虚拟客户机提供的C语言工具包
virt-install基于libvirt服务的虚拟机创建命令
bridge-utils创建和管理桥接设备的工具
libguestfs-tools管理工具

3.查看虚拟化环境

(1)查看虚拟机环境

(2)查看kvm模块支持

(3)查看虚拟工具版本

4.手动配置虚拟网桥

(1)关闭NetworkManager服务

(2)创建br0网桥

[root@node1~]#cd/etc/sysconfig/network-scripts/
[root@node1network-scripts]#cpifcfg-eth0ifcfg-br0
[root@node1network-scripts]#

[root@node1network-scripts]#catifcfg-eth0
DEVICE=eth0
TYPE=Ethernet
BRIDGE=br0
BOOTPROTO=static
ONBOOT=yes
IPADDR=10.10.172.191
PREFIX=24
GATEWAY=10.10.172.1
DNS1=192.168.172.208
DEFROUTE=yes
IPV4_FAILURE_FATAL=yes
IPV6INIT=no
NAME="systemeth0"
UUID=799e696b-8596-4106-a8b8-ed7737174ce4
HWADDR=00:50:56:86:7C:86
LAST_CONNECT=1493675713

[root@node1network-scripts]#catifcfg-br0
DEVICE=br0
TYPE=Bridge
BOOTPROTO=static
ONBOOT=yes
IPADDR=10.10.172.191
PREFIX=24
GATEWAY=10.10.172.1
DNS1=192.168.172.208
DEFROUTE=yes
IPV4_FAILURE_FATAL=yes
IPV6INIT=no
HWADDR=00:50:56:86:7C:86
[root@node1network-scripts]#

(3)关闭了NetworkManager服务之后,才能通过service network restart管理网络。

(4)查看网桥br0

(5)查看网桥

到此kvm虚拟化环境安装完毕。

猜你在找的CentOS相关文章