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

简介:

1.操作系统安装

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

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

55853bfb9376334da24d07ef65549685.png-wh_

(2)关闭selinux、iptables

1
2
3
[root@node1 ~] # setenforce 0;sed -i '/SELINUX/s/enforcing/disabled/g' /etc/selinux/config
[root@node1 ~] # chkconfig ip6tables off
[root@node1 ~] # chkconfig iptables off

(3)修改主机名

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


2.虚拟化环境配置

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

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

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

6880cc63fa1ce27372b460713bba1c20.png-wh_

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
[root@node1 ~] # cd /etc/yum.repos.d/
[root@node1 yum.repos.d] # ll
total 16
-rw-r--r--. 1 root root 1926 Nov 27  2013 CentOS-Base.repo
-rw-r--r--. 1 root root  638 Nov 27  2013 CentOS-Debuginfo.repo
-rw-r--r--. 1 root root  630 Nov 27  2013 CentOS-Media.repo
-rw-r--r--. 1 root root 3664 Nov 27  2013 CentOS-Vault.repo
[root@node1 yum.repos.d] # cat CentOS-Base.repo 
# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client.  You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the 
# remarked out baseurl= line instead.
#
#
 
[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
 
#released updates 
[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
 
#additional packages that may be useful
[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
 
#additional packages that extend functionality of existing packages
[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 - packages by Centos Users
[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@node1 yum.repos.d] #

(3)安装kvm软件包

1
#yum -y install kvm python-virtinst libvirt tunctl bridge-utils virt-manager qemu-kvm-tools virt-viewer virt-v2v

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

1
#yum -y install libguestfs-tools
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
Installed:
   libvirt.x86_64 0:0.10.2-62.el6  python-virtinst.noarch 0:0.600.0-31.el6  qemu-kvm.x86_64 2:0.12.1.2-2.503.el6_9.3  qemu-kvm-tools.x86_64 2:0.12.1.2-2.503.el6_9.3 
   tunctl.x86_64 0:1.5-3.el6       virt-manager.x86_64 0:0.9.0-34.el6       virt-v2v.x86_64 0:0.9.1-5.el6_5           virt-viewer.x86_64 0:2.0-18.el6                
 
Dependency Installed:
   augeas-libs.x86_64 0:1.0.0-10.el6                    btrfs-progs.x86_64 0:0.20-0.2.git91d9eec.el6          celt051.x86_64 0:0.5.1.3-0.el6                          
   cyrus-sasl-md5.x86_64 0:2.1.23-15.el6_6.2            ebtables.x86_64 0:2.0.9-6.el6                         febootstrap-supermin-helper.x86_64 0:3.21-4.el6         
   gdisk.x86_64 0:0.8.10-1.el6                          genisoimage.x86_64 0:1.1.9-12.el6                     glusterfs.x86_64 0:3.7.9-12.el6                         
   glusterfs-api.x86_64 0:3.7.9-12.el6                  glusterfs-client-xlators.x86_64 0:3.7.9-12.el6        glusterfs-libs.x86_64 0:3.7.9-12.el6                    
   gnutls-utils.x86_64 0:2.12.23-21.el6                 gpxe-roms-qemu.noarch 0:0.9.7-6.16.el6                gtk-vnc.x86_64 0:0.3.10-3.el6                           
   gtk-vnc-python.x86_64 0:0.3.10-3.el6                 hivex.x86_64 0:1.3.3-4.3.el6                          iscsi-initiator-utils.x86_64 0:6.2.0.873-27.el6_9       
   libcacard.x86_64 0:0.15.0-2.el6                      libcgroup.x86_64 0:0.40.rc1-24.el6_9                  libgovirt.x86_64 0:0.3.2-3.el6                          
   libguestfs.x86_64 1:1.20.11-20.el6                   libvirt-client.x86_64 0:0.10.2-62.el6                 libvirt-python.x86_64 0:0.10.2-62.el6                   
   lzop.x86_64 0:1.02-0.9.rc1.el6                       mailcap.noarch 0:2.1.31-2.el6                         nc.x86_64 0:1.84-24.el6                                 
   netcf-libs.x86_64 0:0.2.4-4.el6                      netpbm.x86_64 0:10.47.05-11.el6                       netpbm-progs.x86_64 0:10.47.05-11.el6                   
   numad.x86_64 0:0.5-12.20150602git.el6                perl-Class-MethodMaker.x86_64 0:2.16-6.el6            perl-Class-Singleton.noarch 0:1.4-6.el6                 
   perl-Compress-Raw-Zlib.x86_64 1:2.021-144.el6        perl-Compress-Zlib.x86_64 0:2.021-144.el6             perl-Crypt-SSLeay.x86_64 0:0.57-17.el6                  
   perl-DateTime.x86_64 1:0.5300-3.el6                  perl-HTML-Parser.x86_64 0:3.64-2.el6                  perl-HTML-Tagset.noarch 0:3.20-4.el6                    
   perl-IO-Compress-Base.x86_64 0:2.021-144.el6         perl-IO-Compress-Zlib.x86_64 0:2.021-144.el6          perl-IO-String.noarch 0:1.08-9.el6                      
   perl-List-MoreUtils.x86_64 0:0.22-10.el6             perl-Params-Validate.x86_64 0:0.92-3.el6              perl-Sys-Guestfs.x86_64 1:1.20.11-20.el6                
   perl-Sys-Virt.x86_64 0:0.10.2-6.el6                  perl-Term-ProgressBar.noarch 0:2.09-10.el6            perl-TermReadKey.x86_64 0:2.30-13.el6                   
   perl-URI.noarch 0:1.40-2.el6                         perl-XML-DOM.noarch 0:1.44-7.el6                      perl-XML-DOM-XPath.noarch 0:0.14-4.el6                  
   perl-XML-Parser.x86_64 0:2.36-7.el6                  perl-XML-RegExp.noarch 0:0.03-7.el6                   perl-XML-XPath.noarch 0:1.13-10.el6                     
   perl-XML-XPathEngine.noarch 0:0.12-3.el6             perl-YAML-Tiny.noarch 0:1.40-2.el6                    perl-hivex.x86_64 0:1.3.3-4.3.el6                       
   perl-libintl.x86_64 0:1.20-1.el6                     perl-libwww-perl.noarch 0:5.833-5.el6                 qemu-img.x86_64 2:0.12.1.2-2.503.el6_9.3                
   radvd.x86_64 0:1.6-1.el6                             rest.x86_64 0:0.7.92-3.el6                            scrub.x86_64 0:2.2-2.el6                                
   seabios.x86_64 0:0.6.1.2-30.el6                      sgabios-bin.noarch 0:0-0.3.20110621svn.el6            spice-glib.x86_64 0:0.26-8.el6                          
   spice-gtk.x86_64 0:0.26-8.el6                        spice-gtk-python.x86_64 0:0.26-8.el6                  spice-server.x86_64 0:0.12.4-16.el6                     
   usbredir.x86_64 0:0.5.1-3.el6                        vgabios.noarch 0:0.6b-3.8.el6                         yajl.x86_64 0:1.0.7-3.el6                               
 
Updated:
   lvm2-libs.x86_64 0:2.02.143-12.el6_9.1                                                                                                                               
 
Dependency Updated:
   cyrus-sasl.x86_64 0:2.1.23-15.el6_6.2                   cyrus-sasl-gssapi.x86_64 0:2.1.23-15.el6_6.2      cyrus-sasl-lib.x86_64 0:2.1.23-15.el6_6.2                 
   cyrus-sasl-plain.x86_64 0:2.1.23-15.el6_6.2             device-mapper.x86_64 0:1.02.117-12.el6_9.1        device-mapper-event.x86_64 0:1.02.117-12.el6_9.1          
   device-mapper-event-libs.x86_64 0:1.02.117-12.el6_9.1   device-mapper-libs.x86_64 0:1.02.117-12.el6_9.1   device-mapper-persistent-data.x86_64 0:0.6.2-0.1.rc7.el6  
   glib2.x86_64 0:2.28.8-9.el6                             gnutls.x86_64 0:2.12.23-21.el6                    libdrm.x86_64 0:2.4.65-2.el6                              
   lvm2.x86_64 0:2.02.143-12.el6_9.1                       perl.x86_64 4:5.10.1-144.el6                      perl-CGI.x86_64 0:3.51-144.el6                            
   perl-ExtUtils-MakeMaker.x86_64 0:6.55-144.el6           perl-ExtUtils-ParseXS.x86_64 1:2.2003.0-144.el6   perl-Module-Pluggable.x86_64 1:3.90-144.el6               
   perl-Pod-Escapes.x86_64 1:1.04-144.el6                  perl-Pod-Simple.x86_64 1:3.13-144.el6             perl-Test-Harness.x86_64 0:3.17-144.el6                   
   perl-Test-Simple.x86_64 0:0.92-144.el6                  perl-devel.x86_64 4:5.10.1-144.el6                perl-libs.x86_64 4:5.10.1-144.el6                         
   perl-version.x86_64 3:0.77-144.el6                     
 
Complete!


3.查看虚拟化环境

(1)查看虚拟机环境

f162ca3ea3695c9daeb07bc6a271a06c.png-wh_

(2)查看kvm模块支持

f92b7b014b9071aebc22a85e8818bd8d.png-wh_

(3)查看虚拟工具版本

053465e67dddf0168c9f6f0536cd0afd.png-wh_

4.手动配置虚拟网桥

(1)关闭NetworkManager服务

60470d79f7b694ebc88e9fe17efe9280.png-wh_

(2)创建br0网桥

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
[root@node1 ~] # cd /etc/sysconfig/network-scripts/
[root@node1 network-scripts] # cp ifcfg-eth0 ifcfg-br0
[root@node1 network-scripts]
 
[root@node1 network-scripts] # cat ifcfg-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= "system eth0"
UUID=799e696b-8596-4106-a8b8-ed7737174ce4
HWADDR=00:50:56:86:7C:86
LAST_CONNECT=1493675713
 
[root@node1 network-scripts] # cat ifcfg-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@node1 network-scripts] #

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

8ee1aab55c1e8a794e2d9c7d9e6310e5.png-wh_

(4)查看网桥br0

f2358102e3357b844c3c26940852690a.png-wh_

(5)查看网桥

ed27fce81b33053cb44ff5e09ab333f7.png-wh_

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



本文转自 dengaosky 51CTO博客,原文链接:http://blog.51cto.com/dengaosky/1982447,如需转载请自行联系原作者

相关文章
|
2月前
|
存储 Linux 调度
KVM 虚拟化的功能特性
【10月更文挑战第13天】虚拟化技术创建实体资源的虚拟版本,提升资源利用率。KVM(Kernel-based Virtual Machine)作为全虚拟化解决方案,借助Linux内核实现Hypervisor功能,通过模块化方式提供高效的虚拟化环境。
|
3月前
|
KVM 虚拟化
虚拟化技术概述及KVM环境安装
关于虚拟化技术概述及KVM环境安装的教程,涵盖了虚拟化的定义、分类、管理工具,以及KVM的系统需求、安装步骤和使用指南。
83 11
虚拟化技术概述及KVM环境安装
|
2月前
|
安全 KVM 虚拟化
OpenEuler 中配置 KVM 虚拟化环境指南
本文档详细介绍了如何在OpenEuler系统中配置和管理KVM虚拟化环境,包括环境准备、组件安装、虚拟机安装及管理命令等,适合初学者和有经验的用户。内容覆盖了从桥接网卡配置到虚拟机的安装与管理,以及常见问题的解决方法,帮助用户高效利用虚拟化技术。
|
4月前
|
Linux KVM 虚拟化
在Linux中,KVM和Docker在Linux虚拟化中的区别是什么?
在Linux中,KVM和Docker在Linux虚拟化中的区别是什么?
|
7月前
|
存储 Linux KVM
虚拟化技术之KVM安装与使用
虚拟化技术之KVM安装与使用
|
4月前
|
存储 Linux 调度
OpenStack如何支持虚拟化技术?
【8月更文挑战第21天】
222 0
|
2月前
|
存储 分布式计算 分布式数据库
云计算和虚拟化技术
云计算是指把计算资源、存储资源、网络资源、应用软件等集合起来,采用虚拟化技术,将这些资源池化,组成资源共享池,共享池即是“云”。
142 64
|
29天前
|
存储 持续交付 虚拟化
|
4月前
|
存储 运维 虚拟化
Docker技术概论(1):Docker与虚拟化技术比较
Docker技术概论(1):Docker与虚拟化技术比较
165 17
Docker技术概论(1):Docker与虚拟化技术比较
|
4月前
|
Devops 虚拟化 Docker
DevOps 中的标准虚拟化技术
【8月更文挑战第27天】
60 5