1.1 前言

1.1.1 什么是虚拟化?

在计算机技术中,虚拟化(技术)或虚拟技术(英语:Virtualization)是一种资源管理技术,是将计算机的各种实体资源(CPU、内存、磁盘空间、网络适配器等),予以抽象、转换后呈现出来并可供分区、组合为一个或多个电脑配置环境。

由此,打破实体结构间的不可切割的障碍,使用户可以比原本的配置更好的方式来应用这些电脑硬件资源。这些资源的新虚拟部分是不受现有资源的架设方式,地域或物理配置所限制。

一般所指的虚拟化资源包括计算能力和数据存储。

由于目前信息技术领域的很多企业都曾在宣传中将该企业的某种技术称为虚拟化技术,这些技术涵盖的范围可以从Java虚拟机技术系统管理软件,这就使得准确的界定虚拟技术变得困难。因此各种相关学术论文在谈到虚拟技术时常常提到的便是如前面所提到的那个不严格的定义。

1.1.2 为什么要用虚拟化

  ?同一台物理机运行多个不同版本应用软件

  ?硬件依赖性较低和便于数据迁移

   详情参考<1.1.3 虚拟化技术的优势>。

1.1.3 虚拟化技术的优势

  1.降低运营成本

  服务器虚拟化降低了IT基础设施的运营成本,令系统管理员摆脱了繁重的物理服务器、OS、中间件及兼容性的管理工作,减少人工干预频率,使管理更加强大、便捷。

  2.提高应用兼容性

  服务器虚拟化提供的封装性和隔离性使大量应用独立运行于各种环境中,管理人员不需频繁根据底层环境调整应用,只需构建一个应用版本并将其发布到虚拟化后的不同类型平台上即可。

  3.加速应用部署

  采用服务器虚拟化技术只需输入激活配置参数、拷贝虚拟机、启动虚拟机、激活虚拟机即可完成部署,大大缩短了部署时间,免除人工干预,降低了部署成本。

  4.提高服务可用性

  用户可以方便地备份虚拟机,在进行虚拟机动态迁移后,可以方便的恢复备份,或者在其他物理机上运行备份,大大提高了服务的可用性。

  5.提升资源利用率

  通过服务器虚拟化的整合,提高了CPU、内存、存储、网络等设备的利用率,同时保证原有服务的可用性,使其安全性及性能不受影响。

  6.动态调度资源

  在服务器虚拟化技术中,数据中心从传统的单一服务器变成了统一的资源池,用户可以即时地调整虚拟机资源,同时数据中心管理程序和数据中心管理员可以灵活根据虚拟机内部资源使用情况灵活分配调整给虚拟机的资源。

  7.降低能源消耗

  通过减少运行的物理服务器数量,减少CPU以外各单元的耗电量,达到节能减排的目的。

1.1.4 KVM简介

  KVM,基于内核的虚拟机(英语:Kernel-based Virtual Machine,缩写为 KVM),是一种用于Linux内核中的虚拟化基础设施,可以将Linux内核转化为一个hypervisor。KVM在2007年2月被导入Linux 2.6.20核心中,以可加载核心模块的方式被移植到FreeBSD及illumos上。

  KVM在具备Intel VT或AMD-V功能的x86平台上运行。它也被移植到S/390,PowerPC与IA-64平台上。在Linux内核3.9版中,加入ARM架构的支持。

  KVM目前由Red Hat等厂商开发,对CentOS/Fedora/RHEL等Red Hat系发行版支持极佳。

1.1.5 关于KVM

  1. KVM是开源软件,全称是kernel-based virtual machine(基于内核的虚拟机)。
  2. 是x86架构且硬件支持虚拟化技术(如 intel VT 或 AMD-V)的Linux全虚拟化解决方案。
  3. 它包含一个为处理器提供底层虚拟化 可加载的核心模块kvm.ko(kvm-intel.ko或kvm-AMD.ko)。
  4. KVM还需要一个经过修改的QEMU软件(qemu-kvm),作为虚拟机上层控制和界面。
  5. KVM能在不改变linux或windows镜像的情况下同时运行多个虚拟机,(它的意思是多个虚拟机使用同一镜像)并为每一个虚拟机配置个性化硬件环境(网卡、磁盘、图形适配器……)同时KVM还能够使用ksm技术帮助宿主服务器节约内存。
  6. 在主流的Linux内核,如2.6.20以上的内核均已包含了KVM核心。

1.1.6 关于Virtual Machine Manager

  在电脑运算中,红帽公司的Virtual Machine Manager是一个虚拟机管理员,可以让用户管理多个虚拟机。

  基于内核的虚拟机libvirt与Virtual Machine Manager。 

Virtual Machine Manager可以让用户

  ? 创建、编辑、引导或停止虚拟机。

  ? 查看并控制每个虚拟机的控制台。

  ? 查看每部虚拟机的性能以及使用率。

  ? 查看每部正在运行中的虚拟机以及主控端的即时性能及使用率信息。

  ? 不论是在本机或远程,皆可使用KVM、Xen、QEMU。

1.1.7 其他虚拟化软件

? Xen

  Xen是一个开放源代码虚拟机监视器,由XenProject开发。它打算在单个计算机上运行多达128个有完全功能的操作系统。

  在旧(无虚拟硬件)的处理器上执行Xen,操作系统必须进行显式地修改(移植)以在Xen上运行(但是提供对用户应用的兼容性)。这使得Xen无需特殊硬件支持,就能达到高性能的虚拟化。

? QEMU

  QEMU是一套由Fabrice Bellard所编写的模拟处理器的自由软件。它与Bochs,PearPC近似,但其具有某些后两者所不具备的特性,如高速度及跨平台的特性。经由KVM(早期为kqemu加速器,现在kqemu已被KVM取代)这个开源的加速器,QEMU能模拟至接近真实电脑的速度。QEMU有两种主要运作模式:

**  User mode**模拟模式,亦即是用户模式。

  QEMU能引导那些为不同中央处理器编译的Linux程序。而Wine及Dosemu是其主要目标。

**  System mode**模拟模式,亦即是系统模式。

  QEMU能模拟整个电脑系统,包括中央处理器及其他周边设备。它使得为系统源代码进行测试及除错工作变得容易。其亦能用来在一部主机上模拟数部不同虚拟电脑。

1.2 KVM部署与使用

系统环境说明

1.2.1 安装KVM虚拟化软件

安装依赖包(可以使用本地yum源)

安装软件说明内容:

启动服务

安装VNC软件:

  下载vnc软件方法,tightvnc官网:http://www.tightvnc.com

  VNC软件,用于VNC(Virtual Network Computing),为一种使用RFB协议的显示屏画面分享及远程操作软件。此软件借由网络,可发送键盘与鼠标的动作及即时的显示屏画面。

  VNC与操作系统无关,因此可跨平台使用,例如可用Windows连接到某Linux的电脑,反之亦同。甚至在没有安装客户端程序的电脑中,只要有支持JAVA的浏览器,也可使用。

  安装VNC时,使用默认安装即可,无需安装server端。

1.2.2 配置第一台KVM虚拟机

使用命令

**  注意:**需要先将镜像文件拷贝到 /data/CentOS-7-x86_64-DVD-1511.iso 。

<td style="width: 56.66%; border: solid #9BBB59 1.0pt; mso-border-themecolor: accent3; border-left: none; mso-border-top-alt: solid #9BBB59 .5pt; mso-border-top-themecolor: accent3; mso-border-bottom-alt: solid #9BBB59 .5pt; mso-border-bottom-themecolor: accent3; mso-border-right-alt: solid #9BBB59 .5pt; mso-border-right-themecolor: accent3; background: #9BBB59; mso-background-themecolor: accent3; padding: 0cm 5.4pt 0cm 5.4pt;" width="56%">
  <p class="MsoNormal" style="text-align: center; mso-yfti-cnfc: 1;" align="center">
    <strong><span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; color: white; mso-themecolor: background1;">参数说明</span></strong>
  </p>
</td>
<td style="width: 56.66%; border-top: none; border-left: none; border-bottom: solid #C2D69B 1.0pt; mso-border-bottom-themecolor: accent3; mso-border-bottom-themetint: 153; border-right: solid #C2D69B 1.0pt; mso-border-right-themecolor: accent3; mso-border-right-themetint: 153; mso-border-top-alt: solid #C2D69B .5pt; mso-border-top-themecolor: accent3; mso-border-top-themetint: 153; mso-border-left-alt: solid #C2D69B .5pt; mso-border-left-themecolor: accent3; mso-border-left-themetint: 153; mso-border-alt: solid #C2D69B .5pt; mso-border-themecolor: accent3; mso-border-themetint: 153; background: #EAF1DD; mso-background-themecolor: accent3; mso-background-themetint: 51; padding: 0cm 5.4pt 0cm 5.4pt;" width="56%">
  <p class="MsoNormal">
    <span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">要使用的管理程序名称</span><span lang="EN-US"> (kvm, qemu, xen, ...)</span>
  </p>
</td>
<td style="width: 56.66%; border-top: none; border-left: none; border-bottom: solid #C2D69B 1.0pt; mso-border-bottom-themecolor: accent3; mso-border-bottom-themetint: 153; border-right: solid #C2D69B 1.0pt; mso-border-right-themecolor: accent3; mso-border-right-themetint: 153; mso-border-top-alt: solid #C2D69B .5pt; mso-border-top-themecolor: accent3; mso-border-top-themetint: 153; mso-border-left-alt: solid #C2D69B .5pt; mso-border-left-themecolor: accent3; mso-border-left-themetint: 153; mso-border-alt: solid #C2D69B .5pt; mso-border-themecolor: accent3; mso-border-themetint: 153; padding: 0cm 5.4pt 0cm 5.4pt;" width="56%">
  <p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph;">
    <span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">系统类型</span>
  </p>
</td>
<td style="width: 56.66%; border-top: none; border-left: none; border-bottom: solid #C2D69B 1.0pt; mso-border-bottom-themecolor: accent3; mso-border-bottom-themetint: 153; border-right: solid #C2D69B 1.0pt; mso-border-right-themecolor: accent3; mso-border-right-themetint: 153; mso-border-top-alt: solid #C2D69B .5pt; mso-border-top-themecolor: accent3; mso-border-top-themetint: 153; mso-border-left-alt: solid #C2D69B .5pt; mso-border-left-themecolor: accent3; mso-border-left-themetint: 153; mso-border-alt: solid #C2D69B .5pt; mso-border-themecolor: accent3; mso-border-themetint: 153; background: #EAF1DD; mso-background-themecolor: accent3; mso-background-themetint: 51; padding: 0cm 5.4pt 0cm 5.4pt;" width="56%">
  <p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph; mso-yfti-cnfc: 64;">
    <span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">在客户机上安装的操作系统,例如:</span><span lang="EN-US">'fedora18'</span><span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">、</span><span lang="EN-US">'rhel6'</span><span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">、</span><span lang="EN-US">'winxp' </span><span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">等。</span>
  </p>
</td>
<td style="width: 56.66%; border-top: none; border-left: none; border-bottom: solid #C2D69B 1.0pt; mso-border-bottom-themecolor: accent3; mso-border-bottom-themetint: 153; border-right: solid #C2D69B 1.0pt; mso-border-right-themecolor: accent3; mso-border-right-themetint: 153; mso-border-top-alt: solid #C2D69B .5pt; mso-border-top-themecolor: accent3; mso-border-top-themetint: 153; mso-border-left-alt: solid #C2D69B .5pt; mso-border-left-themecolor: accent3; mso-border-left-themetint: 153; mso-border-alt: solid #C2D69B .5pt; mso-border-themecolor: accent3; mso-border-themetint: 153; padding: 0cm 5.4pt 0cm 5.4pt;" width="56%">
  <p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph;">
    <span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">客户机实例名称</span>
  </p>
</td>
<td style="width: 56.66%; border-top: none; border-left: none; border-bottom: solid #C2D69B 1.0pt; mso-border-bottom-themecolor: accent3; mso-border-bottom-themetint: 153; border-right: solid #C2D69B 1.0pt; mso-border-right-themecolor: accent3; mso-border-right-themetint: 153; mso-border-top-alt: solid #C2D69B .5pt; mso-border-top-themecolor: accent3; mso-border-top-themetint: 153; mso-border-left-alt: solid #C2D69B .5pt; mso-border-left-themecolor: accent3; mso-border-left-themetint: 153; mso-border-alt: solid #C2D69B .5pt; mso-border-themecolor: accent3; mso-border-themetint: 153; background: #EAF1DD; mso-background-themecolor: accent3; mso-background-themetint: 51; padding: 0cm 5.4pt 0cm 5.4pt;" width="56%">
  <p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph; mso-yfti-cnfc: 64;">
    <span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">配置客户机虚拟内存大小</span>
  </p>
</td>
<td style="width: 56.66%; border-top: none; border-left: none; border-bottom: solid #C2D69B 1.0pt; mso-border-bottom-themecolor: accent3; mso-border-bottom-themetint: 153; border-right: solid #C2D69B 1.0pt; mso-border-right-themecolor: accent3; mso-border-right-themetint: 153; mso-border-top-alt: solid #C2D69B .5pt; mso-border-top-themecolor: accent3; mso-border-top-themetint: 153; mso-border-left-alt: solid #C2D69B .5pt; mso-border-left-themecolor: accent3; mso-border-left-themetint: 153; mso-border-alt: solid #C2D69B .5pt; mso-border-themecolor: accent3; mso-border-themetint: 153; padding: 0cm 5.4pt 0cm 5.4pt;" width="56%">
  <p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph;">
    <span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">配置客户机虚拟</span><span lang="EN-US"> CPU(vcpu) </span><span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">数量。</span>
  </p>
</td>
<td style="width: 56.66%; border-top: none; border-left: none; border-bottom: solid #C2D69B 1.0pt; mso-border-bottom-themecolor: accent3; mso-border-bottom-themetint: 153; border-right: solid #C2D69B 1.0pt; mso-border-right-themecolor: accent3; mso-border-right-themetint: 153; mso-border-top-alt: solid #C2D69B .5pt; mso-border-top-themecolor: accent3; mso-border-top-themetint: 153; mso-border-left-alt: solid #C2D69B .5pt; mso-border-left-themecolor: accent3; mso-border-left-themetint: 153; mso-border-alt: solid #C2D69B .5pt; mso-border-themecolor: accent3; mso-border-themetint: 153; background: #EAF1DD; mso-background-themecolor: accent3; mso-background-themetint: 51; padding: 0cm 5.4pt 0cm 5.4pt;" width="56%">
  <p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph; mso-yfti-cnfc: 64;">
    <span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">指定存储的各种选项。</span>
  </p>
</td>
<td style="width: 56.66%; border-top: none; border-left: none; border-bottom: solid #C2D69B 1.0pt; mso-border-bottom-themecolor: accent3; mso-border-bottom-themetint: 153; border-right: solid #C2D69B 1.0pt; mso-border-right-themecolor: accent3; mso-border-right-themetint: 153; mso-border-top-alt: solid #C2D69B .5pt; mso-border-top-themecolor: accent3; mso-border-top-themetint: 153; mso-border-left-alt: solid #C2D69B .5pt; mso-border-left-themecolor: accent3; mso-border-left-themetint: 153; mso-border-alt: solid #C2D69B .5pt; mso-border-themecolor: accent3; mso-border-themetint: 153; padding: 0cm 5.4pt 0cm 5.4pt;" width="56%">
  <p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph;">
    <span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">光驱安装介质</span>
  </p>
</td>
<td style="width: 56.66%; border-top: none; border-left: none; border-bottom: solid #C2D69B 1.0pt; mso-border-bottom-themecolor: accent3; mso-border-bottom-themetint: 153; border-right: solid #C2D69B 1.0pt; mso-border-right-themecolor: accent3; mso-border-right-themetint: 153; mso-border-top-alt: solid #C2D69B .5pt; mso-border-top-themecolor: accent3; mso-border-top-themetint: 153; mso-border-left-alt: solid #C2D69B .5pt; mso-border-left-themecolor: accent3; mso-border-left-themetint: 153; mso-border-alt: solid #C2D69B .5pt; mso-border-themecolor: accent3; mso-border-themetint: 153; background: #EAF1DD; mso-background-themecolor: accent3; mso-background-themetint: 51; padding: 0cm 5.4pt 0cm 5.4pt;" width="56%">
  <p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph; mso-yfti-cnfc: 64;">
    <span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">配置客户机网络接口。</span>
  </p>
</td>
<td style="width: 56.66%; border-top: none; border-left: none; border-bottom: solid #C2D69B 1.0pt; mso-border-bottom-themecolor: accent3; mso-border-bottom-themetint: 153; border-right: solid #C2D69B 1.0pt; mso-border-right-themecolor: accent3; mso-border-right-themetint: 153; mso-border-top-alt: solid #C2D69B .5pt; mso-border-top-themecolor: accent3; mso-border-top-themetint: 153; mso-border-left-alt: solid #C2D69B .5pt; mso-border-left-themecolor: accent3; mso-border-left-themetint: 153; mso-border-alt: solid #C2D69B .5pt; mso-border-themecolor: accent3; mso-border-themetint: 153; padding: 0cm 5.4pt 0cm 5.4pt;" width="56%">
  <p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph;">
    <span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">配置客户机显示设置。</span>
  </p>
</td>
<td style="width: 56.66%; border-top: none; border-left: none; border-bottom: solid #C2D69B 1.0pt; mso-border-bottom-themecolor: accent3; mso-border-bottom-themetint: 153; border-right: solid #C2D69B 1.0pt; mso-border-right-themecolor: accent3; mso-border-right-themetint: 153; mso-border-top-alt: solid #C2D69B .5pt; mso-border-top-themecolor: accent3; mso-border-top-themetint: 153; mso-border-left-alt: solid #C2D69B .5pt; mso-border-left-themecolor: accent3; mso-border-left-themetint: 153; mso-border-alt: solid #C2D69B .5pt; mso-border-themecolor: accent3; mso-border-themetint: 153; padding: 0cm 5.4pt 0cm 5.4pt;" width="56%">
  <p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph;">
    <span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">这个客户机应该是一个全虚拟化客户机</span>
  </p>
</td>
<td style="width: 56.66%; border-top: none; border-left: none; border-bottom: solid #C2D69B 1.0pt; mso-border-bottom-themecolor: accent3; mso-border-bottom-themetint: 153; border-right: solid #C2D69B 1.0pt; mso-border-right-themecolor: accent3; mso-border-right-themetint: 153; mso-border-top-alt: solid #C2D69B .5pt; mso-border-top-themecolor: accent3; mso-border-top-themetint: 153; mso-border-left-alt: solid #C2D69B .5pt; mso-border-left-themecolor: accent3; mso-border-left-themetint: 153; mso-border-alt: solid #C2D69B .5pt; mso-border-themecolor: accent3; mso-border-themetint: 153; background: #EAF1DD; mso-background-themecolor: accent3; mso-background-themetint: 51; padding: 0cm 5.4pt 0cm 5.4pt;" width="56%">
  <p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph; mso-yfti-cnfc: 64;">
    <span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">这个客户机应该是一个半虚拟化客户机</span>
  </p>
</td>
<td style="width: 56.66%; border-top: none; border-left: none; border-bottom: solid #C2D69B 1.0pt; mso-border-bottom-themecolor: accent3; mso-border-bottom-themetint: 153; border-right: solid #C2D69B 1.0pt; mso-border-right-themecolor: accent3; mso-border-right-themetint: 153; mso-border-top-alt: solid #C2D69B .5pt; mso-border-top-themecolor: accent3; mso-border-top-themetint: 153; mso-border-left-alt: solid #C2D69B .5pt; mso-border-left-themecolor: accent3; mso-border-left-themetint: 153; mso-border-alt: solid #C2D69B .5pt; mso-border-themecolor: accent3; mso-border-themetint: 153; padding: 0cm 5.4pt 0cm 5.4pt;" width="56%">
  <p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph;">
    <span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">这个客户机应该是一个容器客户机</span>
  </p>
</td>
<td style="width: 56.66%; border-top: none; border-left: none; border-bottom: solid #C2D69B 1.0pt; mso-border-bottom-themecolor: accent3; mso-border-bottom-themetint: 153; border-right: solid #C2D69B 1.0pt; mso-border-right-themecolor: accent3; mso-border-right-themetint: 153; mso-border-top-alt: solid #C2D69B .5pt; mso-border-top-themecolor: accent3; mso-border-top-themetint: 153; mso-border-left-alt: solid #C2D69B .5pt; mso-border-left-themecolor: accent3; mso-border-left-themetint: 153; mso-border-alt: solid #C2D69B .5pt; mso-border-themecolor: accent3; mso-border-themetint: 153; background: #EAF1DD; mso-background-themecolor: accent3; mso-background-themetint: 51; padding: 0cm 5.4pt 0cm 5.4pt;" width="56%">
  <p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph; mso-yfti-cnfc: 64;">
    <span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">要使用的管理程序名称</span><span lang="EN-US"> (kvm, qemu, xen, ...)</span>
  </p>
</td>
<td style="width: 56.66%; border-top: none; border-left: none; border-bottom: solid #C2D69B 1.0pt; mso-border-bottom-themecolor: accent3; mso-border-bottom-themetint: 153; border-right: solid #C2D69B 1.0pt; mso-border-right-themecolor: accent3; mso-border-right-themetint: 153; mso-border-top-alt: solid #C2D69B .5pt; mso-border-top-themecolor: accent3; mso-border-top-themetint: 153; mso-border-left-alt: solid #C2D69B .5pt; mso-border-left-themecolor: accent3; mso-border-left-themetint: 153; mso-border-alt: solid #C2D69B .5pt; mso-border-themecolor: accent3; mso-border-themetint: 153; padding: 0cm 5.4pt 0cm 5.4pt;" width="56%">
  <p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph;">
    <span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">模拟</span><span lang="EN-US"> CPU </span><span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">架构</span>
  </p>
</td>
<td style="width: 56.66%; border-top: none; border-left: none; border-bottom: solid #C2D69B 1.0pt; mso-border-bottom-themecolor: accent3; mso-border-bottom-themetint: 153; border-right: solid #C2D69B 1.0pt; mso-border-right-themecolor: accent3; mso-border-right-themetint: 153; mso-border-top-alt: solid #C2D69B .5pt; mso-border-top-themecolor: accent3; mso-border-top-themetint: 153; mso-border-left-alt: solid #C2D69B .5pt; mso-border-left-themecolor: accent3; mso-border-left-themetint: 153; mso-border-alt: solid #C2D69B .5pt; mso-border-themecolor: accent3; mso-border-themetint: 153; background: #EAF1DD; mso-background-themecolor: accent3; mso-background-themetint: 51; padding: 0cm 5.4pt 0cm 5.4pt;" width="56%">
  <p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph; mso-yfti-cnfc: 64;">
    <span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">机器类型为仿真类型</span>
  </p>
</td>
<td style="width: 56.66%; border-top: none; border-left: none; border-bottom: solid #C2D69B 1.0pt; mso-border-bottom-themecolor: accent3; mso-border-bottom-themetint: 153; border-right: solid #C2D69B 1.0pt; mso-border-right-themecolor: accent3; mso-border-right-themetint: 153; mso-border-top-alt: solid #C2D69B .5pt; mso-border-top-themecolor: accent3; mso-border-top-themetint: 153; mso-border-left-alt: solid #C2D69B .5pt; mso-border-left-themecolor: accent3; mso-border-left-themetint: 153; mso-border-alt: solid #C2D69B .5pt; mso-border-themecolor: accent3; mso-border-themetint: 153; background: #EAF1DD; mso-background-themecolor: accent3; mso-background-themetint: 51; padding: 0cm 5.4pt 0cm 5.4pt;" width="56%">
  <p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph; mso-yfti-cnfc: 64;">
    <span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">不要自动尝试连接到客户端控制台</span>
  </p>
</td>
<td style="width: 56.66%; border-top: none; border-left: none; border-bottom: solid #C2D69B 1.0pt; mso-border-bottom-themecolor: accent3; mso-border-bottom-themetint: 153; border-right: solid #C2D69B 1.0pt; mso-border-right-themecolor: accent3; mso-border-right-themetint: 153; mso-border-top-alt: solid #C2D69B .5pt; mso-border-top-themecolor: accent3; mso-border-top-themetint: 153; mso-border-left-alt: solid #C2D69B .5pt; mso-border-left-themecolor: accent3; mso-border-left-themetint: 153; mso-border-alt: solid #C2D69B .5pt; mso-border-themecolor: accent3; mso-border-themetint: 153; padding: 0cm 5.4pt 0cm 5.4pt;" width="56%">
  <p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph;">
    <span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">主机启动时自动启动域。</span>
  </p>
</td>
<td style="width: 56.66%; border-top: none; border-left: none; border-bottom: solid #C2D69B 1.0pt; mso-border-bottom-themecolor: accent3; mso-border-bottom-themetint: 153; border-right: solid #C2D69B 1.0pt; mso-border-right-themecolor: accent3; mso-border-right-themetint: 153; mso-border-top-alt: solid #C2D69B .5pt; mso-border-top-themecolor: accent3; mso-border-top-themetint: 153; mso-border-left-alt: solid #C2D69B .5pt; mso-border-left-themecolor: accent3; mso-border-left-themetint: 153; mso-border-alt: solid #C2D69B .5pt; mso-border-themecolor: accent3; mso-border-themetint: 153; background: #EAF1DD; mso-background-themecolor: accent3; mso-background-themetint: 51; padding: 0cm 5.4pt 0cm 5.4pt;" width="56%">
  <p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph; mso-yfti-cnfc: 64;">
    <span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">安装完成后不启动客户机。</span>
  </p>
</td>

   在启动的同时使用vnc连接

   下面就进入到安装系统的操作,关于系统安装的方法参考:http://www.cnblogs.com/clsn/p/7489784.html

1.2.3 KVM虚拟机管理操作

<td style="width: 70.22%; border: solid #9BBB59 1.0pt; mso-border-themecolor: accent3; border-left: none; mso-border-top-alt: solid #9BBB59 .5pt; mso-border-top-themecolor: accent3; mso-border-bottom-alt: solid #9BBB59 .5pt; mso-border-bottom-themecolor: accent3; mso-border-right-alt: solid #9BBB59 .5pt; mso-border-right-themecolor: accent3; background: #9BBB59; mso-background-themecolor: accent3; padding: 0cm 5.4pt 0cm 5.4pt;" valign="top" width="70%">
  <p class="MsoNormal" style="text-align: center; mso-yfti-cnfc: 1;" align="center">
    <strong><span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; color: white; mso-themecolor: background1;">参数说明</span></strong>
  </p>
</td>
<td style="width: 70.22%; border-top: none; border-left: none; border-bottom: solid #C2D69B 1.0pt; mso-border-bottom-themecolor: accent3; mso-border-bottom-themetint: 153; border-right: solid #C2D69B 1.0pt; mso-border-right-themecolor: accent3; mso-border-right-themetint: 153; mso-border-top-alt: solid #C2D69B .5pt; mso-border-top-themecolor: accent3; mso-border-top-themetint: 153; mso-border-left-alt: solid #C2D69B .5pt; mso-border-left-themecolor: accent3; mso-border-left-themetint: 153; mso-border-alt: solid #C2D69B .5pt; mso-border-themecolor: accent3; mso-border-themetint: 153; padding: 0cm 5.4pt 0cm 5.4pt;" valign="top" width="70%">
  <p class="MsoNormal">
    <span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">查看虚拟机列表,列出域</span>
  </p>
</td>
<td style="width: 70.22%; border-top: none; border-left: none; border-bottom: solid #C2D69B 1.0pt; mso-border-bottom-themecolor: accent3; mso-border-bottom-themetint: 153; border-right: solid #C2D69B 1.0pt; mso-border-right-themecolor: accent3; mso-border-right-themetint: 153; mso-border-top-alt: solid #C2D69B .5pt; mso-border-top-themecolor: accent3; mso-border-top-themetint: 153; mso-border-left-alt: solid #C2D69B .5pt; mso-border-left-themecolor: accent3; mso-border-left-themetint: 153; mso-border-alt: solid #C2D69B .5pt; mso-border-themecolor: accent3; mso-border-themetint: 153; background: #EAF1DD; mso-background-themecolor: accent3; mso-background-themetint: 51; padding: 0cm 5.4pt 0cm 5.4pt;" valign="top" width="70%">
  <p class="MsoNormal" style="mso-yfti-cnfc: 64;">
    <span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">启动虚拟机,开始一个(以前定义的)非活跃的域</span>
  </p>
</td>
<td style="width: 70.22%; border-top: none; border-left: none; border-bottom: solid #C2D69B 1.0pt; mso-border-bottom-themecolor: accent3; mso-border-bottom-themetint: 153; border-right: solid #C2D69B 1.0pt; mso-border-right-themecolor: accent3; mso-border-right-themetint: 153; mso-border-top-alt: solid #C2D69B .5pt; mso-border-top-themecolor: accent3; mso-border-top-themetint: 153; mso-border-left-alt: solid #C2D69B .5pt; mso-border-left-themecolor: accent3; mso-border-left-themetint: 153; mso-border-alt: solid #C2D69B .5pt; mso-border-themecolor: accent3; mso-border-themetint: 153; padding: 0cm 5.4pt 0cm 5.4pt;" valign="top" width="70%">
  <p class="MsoNormal">
    <span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">关闭虚拟机,关闭一个域</span>
  </p>
</td>
<td style="width: 70.22%; border-top: none; border-left: none; border-bottom: solid #C2D69B 1.0pt; mso-border-bottom-themecolor: accent3; mso-border-bottom-themetint: 153; border-right: solid #C2D69B 1.0pt; mso-border-right-themecolor: accent3; mso-border-right-themetint: 153; mso-border-top-alt: solid #C2D69B .5pt; mso-border-top-themecolor: accent3; mso-border-top-themetint: 153; mso-border-left-alt: solid #C2D69B .5pt; mso-border-left-themecolor: accent3; mso-border-left-themetint: 153; mso-border-alt: solid #C2D69B .5pt; mso-border-themecolor: accent3; mso-border-themetint: 153; background: #EAF1DD; mso-background-themecolor: accent3; mso-background-themetint: 51; padding: 0cm 5.4pt 0cm 5.4pt;" valign="top" width="70%">
  <p class="MsoNormal" style="mso-yfti-cnfc: 64;">
    <span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">强制关闭虚拟机,销毁(停止)域</span>
  </p>
</td>
<td style="width: 70.22%; border-top: none; border-left: none; border-bottom: solid #C2D69B 1.0pt; mso-border-bottom-themecolor: accent3; mso-border-bottom-themetint: 153; border-right: solid #C2D69B 1.0pt; mso-border-right-themecolor: accent3; mso-border-right-themetint: 153; mso-border-top-alt: solid #C2D69B .5pt; mso-border-top-themecolor: accent3; mso-border-top-themetint: 153; mso-border-left-alt: solid #C2D69B .5pt; mso-border-left-themecolor: accent3; mso-border-left-themetint: 153; mso-border-alt: solid #C2D69B .5pt; mso-border-themecolor: accent3; mso-border-themetint: 153; padding: 0cm 5.4pt 0cm 5.4pt;" valign="top" width="70%">
  <p class="MsoNormal">
    <span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">查询虚拟机</span><span lang="EN-US">vnc</span><span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">端口号</span>
  </p>
</td>
<td style="width: 70.22%; border-top: none; border-left: none; border-bottom: solid #C2D69B 1.0pt; mso-border-bottom-themecolor: accent3; mso-border-bottom-themetint: 153; border-right: solid #C2D69B 1.0pt; mso-border-right-themecolor: accent3; mso-border-right-themetint: 153; mso-border-top-alt: solid #C2D69B .5pt; mso-border-top-themecolor: accent3; mso-border-top-themetint: 153; mso-border-left-alt: solid #C2D69B .5pt; mso-border-left-themecolor: accent3; mso-border-left-themetint: 153; mso-border-alt: solid #C2D69B .5pt; mso-border-themecolor: accent3; mso-border-themetint: 153; padding: 0cm 5.4pt 0cm 5.4pt;" valign="top" width="70%">
  <p class="MsoNormal">
    <span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">导出主机配置信息</span>
  </p>
</td>
<td style="width: 70.22%; border-top: none; border-left: none; border-bottom: solid #C2D69B 1.0pt; mso-border-bottom-themecolor: accent3; mso-border-bottom-themetint: 153; border-right: solid #C2D69B 1.0pt; mso-border-right-themecolor: accent3; mso-border-right-themetint: 153; mso-border-top-alt: solid #C2D69B .5pt; mso-border-top-themecolor: accent3; mso-border-top-themetint: 153; mso-border-left-alt: solid #C2D69B .5pt; mso-border-left-themecolor: accent3; mso-border-left-themetint: 153; mso-border-alt: solid #C2D69B .5pt; mso-border-themecolor: accent3; mso-border-themetint: 153; background: #EAF1DD; mso-background-themecolor: accent3; mso-background-themetint: 51; padding: 0cm 5.4pt 0cm 5.4pt;" valign="top" width="70%">
  <p class="MsoNormal" style="mso-yfti-cnfc: 64;">
    <span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">删除主机</span>
  </p>
</td>
<td style="width: 70.22%; border-top: none; border-left: none; border-bottom: solid #C2D69B 1.0pt; mso-border-bottom-themecolor: accent3; mso-border-bottom-themetint: 153; border-right: solid #C2D69B 1.0pt; mso-border-right-themecolor: accent3; mso-border-right-themetint: 153; mso-border-top-alt: solid #C2D69B .5pt; mso-border-top-themecolor: accent3; mso-border-top-themetint: 153; mso-border-left-alt: solid #C2D69B .5pt; mso-border-left-themecolor: accent3; mso-border-left-themetint: 153; mso-border-alt: solid #C2D69B .5pt; mso-border-themecolor: accent3; mso-border-themetint: 153; padding: 0cm 5.4pt 0cm 5.4pt;" valign="top" width="70%">
  <p class="MsoNormal">
    <span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">导入主机配置</span>
  </p>
</td>
<td style="width: 70.22%; border-top: none; border-left: none; border-bottom: solid #C2D69B 1.0pt; mso-border-bottom-themecolor: accent3; mso-border-bottom-themetint: 153; border-right: solid #C2D69B 1.0pt; mso-border-right-themecolor: accent3; mso-border-right-themetint: 153; mso-border-top-alt: solid #C2D69B .5pt; mso-border-top-themecolor: accent3; mso-border-top-themetint: 153; mso-border-left-alt: solid #C2D69B .5pt; mso-border-left-themecolor: accent3; mso-border-left-themetint: 153; mso-border-alt: solid #C2D69B .5pt; mso-border-themecolor: accent3; mso-border-themetint: 153; background: #EAF1DD; mso-background-themecolor: accent3; mso-background-themetint: 51; padding: 0cm 5.4pt 0cm 5.4pt;" valign="top" width="70%">
  <p class="MsoNormal" style="mso-yfti-cnfc: 64;">
    <span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">对虚拟机进行重命名</span>
  </p>
</td>
<td style="width: 70.22%; border-top: none; border-left: none; border-bottom: solid #C2D69B 1.0pt; mso-border-bottom-themecolor: accent3; mso-border-bottom-themetint: 153; border-right: solid #C2D69B 1.0pt; mso-border-right-themecolor: accent3; mso-border-right-themetint: 153; mso-border-top-alt: solid #C2D69B .5pt; mso-border-top-themecolor: accent3; mso-border-top-themetint: 153; mso-border-left-alt: solid #C2D69B .5pt; mso-border-left-themecolor: accent3; mso-border-left-themetint: 153; mso-border-alt: solid #C2D69B .5pt; mso-border-themecolor: accent3; mso-border-themetint: 153; background: #EAF1DD; mso-background-themecolor: accent3; mso-background-themetint: 51; padding: 0cm 5.4pt 0cm 5.4pt;" valign="top" width="70%">
  <p class="MsoNormal" style="mso-yfti-cnfc: 64;">
    <span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">挂起虚拟机</span>
  </p>
</td>
<td style="width: 70.22%; border-top: none; border-left: none; border-bottom: solid #C2D69B 1.0pt; mso-border-bottom-themecolor: accent3; mso-border-bottom-themetint: 153; border-right: solid #C2D69B 1.0pt; mso-border-right-themecolor: accent3; mso-border-right-themetint: 153; mso-border-top-alt: solid #C2D69B .5pt; mso-border-top-themecolor: accent3; mso-border-top-themetint: 153; mso-border-left-alt: solid #C2D69B .5pt; mso-border-left-themecolor: accent3; mso-border-left-themetint: 153; mso-border-alt: solid #C2D69B .5pt; mso-border-themecolor: accent3; mso-border-themetint: 153; padding: 0cm 5.4pt 0cm 5.4pt;" valign="top" width="70%">
  <p class="MsoNormal">
    <span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">恢复虚拟机</span>
  </p>
</td>
<td style="width: 70.22%; border-top: none; border-left: none; border-bottom: solid #C2D69B 1.0pt; mso-border-bottom-themecolor: accent3; mso-border-bottom-themetint: 153; border-right: solid #C2D69B 1.0pt; mso-border-right-themecolor: accent3; mso-border-right-themetint: 153; mso-border-top-alt: solid #C2D69B .5pt; mso-border-top-themecolor: accent3; mso-border-top-themetint: 153; mso-border-left-alt: solid #C2D69B .5pt; mso-border-left-themecolor: accent3; mso-border-left-themetint: 153; mso-border-alt: solid #C2D69B .5pt; mso-border-themecolor: accent3; mso-border-themetint: 153; padding: 0cm 5.4pt 0cm 5.4pt;" valign="top" width="70%">
  <p class="MsoNormal">
    <span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">虚拟机开机启动</span>
  </p>
</td>
<td style="width: 70.22%; border-top: none; border-left: none; border-bottom: solid #C2D69B 1.0pt; mso-border-bottom-themecolor: accent3; mso-border-bottom-themetint: 153; border-right: solid #C2D69B 1.0pt; mso-border-right-themecolor: accent3; mso-border-right-themetint: 153; mso-border-top-alt: solid #C2D69B .5pt; mso-border-top-themecolor: accent3; mso-border-top-themetint: 153; mso-border-left-alt: solid #C2D69B .5pt; mso-border-left-themecolor: accent3; mso-border-left-themetint: 153; mso-border-alt: solid #C2D69B .5pt; mso-border-themecolor: accent3; mso-border-themetint: 153; background: #EAF1DD; mso-background-themecolor: accent3; mso-background-themetint: 51; padding: 0cm 5.4pt 0cm 5.4pt;" valign="top" width="70%">
  <p class="MsoNormal" style="mso-yfti-cnfc: 64;">
    <span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">取消虚拟机开机启动</span>
  </p>
</td>

操作过程:

KVM虚拟机配置文件位置

修改KVM虚拟机配置的方法

   使用该命令修改可以对文件进行语法校验。

备份与恢复

备份虚拟机配置(关机时备份):

删除虚拟机配置

导入虚拟机

修改虚拟机名称

虚拟机挂起与恢复

恢复虚拟机

查询虚拟机vnc端口

开机自启动设置

   设置宿主机开机虚拟机在其他

取消开机自启动

1.3 kvm虚拟机console登录

1.3.1 CentOS 7.X 版本console登录

配置console登录

在clsn7虚拟机内操作(该操作仅限centos7):

重启完成后,使用virsh console 连接虚拟机。

clsn7 login: root Password: Last login: Mon Jan 22 12:24:48 from 192.168.122.1 [root@clsn7 ~]# w 12:26:11 up 0 min, 1 user, load average: 0.09, 0.03, 0.01 USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT root ttyS0 12:26 3.00s 0.02s 0.01s w

1.3.2 CentOS 6.X 版本console登录

使用virsh console连接CentOS 6虚拟主机方法:

  安装一台centos6的kvm虚拟机

  新安装一台虚拟机后,是无法通过virsh console 命令连入虚拟机中的,这时我们需要开启虚拟机的console功能。

  以下操作都在虚拟机中进行

1、添加ttyS0的许可,允许root登陆

2、编辑/etc/grub.conf中加入console=ttyS0

   在该文件的第16行。kernel选项后添加

3、编辑/etc/inittab

  在最后一行加入内容 S0:12345:respawn:/sbin/agetty ttyS0 115200

4、以上操作都完成后,重启虚拟机

  以下操作在kvm宿主机上执行

1、检查虚拟机的状态

2、进行连接测试

clsn6 login: root Password: Last login: Mon Jan 22 05:44:25 on ttyS0 [root@clsn6 ~]# who root ttyS0 2018-01-22 05:50 # 登陆成功,查看登陆接口为之前设置的ttyS0

1.4 KVM虚拟机磁盘、快照与克隆

1.4.1 磁盘管理

  KVM qcow2、raw、vmdk等镜像格式说明:http://blog.csdn.net/zhengmx100/article/details/53887162

查看当前虚拟机硬盘信息

raw转qcow2格式:

转换原有磁盘格式

修改clsn7 虚拟机配置文件

删除原磁盘文件

启动虚拟机

1.4.2 KVM虚拟机添加硬盘

进入硬盘存放目录

创建一块新的硬盘

查看创建的硬盘信息

为虚拟机添加硬盘

参数说明:

<td style="width: 64.8%; border: solid #9BBB59 1.0pt; mso-border-themecolor: accent3; border-left: none; mso-border-top-alt: solid #9BBB59 .5pt; mso-border-top-themecolor: accent3; mso-border-bottom-alt: solid #9BBB59 .5pt; mso-border-bottom-themecolor: accent3; mso-border-right-alt: solid #9BBB59 .5pt; mso-border-right-themecolor: accent3; background: #9BBB59; mso-background-themecolor: accent3; padding: 0cm 5.4pt 0cm 5.4pt;" width="64%">
  <p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph; mso-yfti-cnfc: 1;">
    <strong><span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; color: white; mso-themecolor: background1;">参数说明</span></strong>
  </p>
</td>
<td style="width: 64.8%; border-top: none; border-left: none; border-bottom: solid #C2D69B 1.0pt; mso-border-bottom-themecolor: accent3; mso-border-bottom-themetint: 153; border-right: solid #C2D69B 1.0pt; mso-border-right-themecolor: accent3; mso-border-right-themetint: 153; mso-border-top-alt: solid #C2D69B .5pt; mso-border-top-themecolor: accent3; mso-border-top-themetint: 153; mso-border-left-alt: solid #C2D69B .5pt; mso-border-left-themecolor: accent3; mso-border-left-themetint: 153; mso-border-alt: solid #C2D69B .5pt; mso-border-themecolor: accent3; mso-border-themetint: 153; background: #EAF1DD; mso-background-themecolor: accent3; mso-background-themetint: 51; padding: 0cm 5.4pt 0cm 5.4pt;" width="64%">
  <p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph; mso-yfti-cnfc: 64;">
    <span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">第二块硬盘</span>
  </p>
</td>
<td style="width: 64.8%; border-top: none; border-left: none; border-bottom: solid #C2D69B 1.0pt; mso-border-bottom-themecolor: accent3; mso-border-bottom-themetint: 153; border-right: solid #C2D69B 1.0pt; mso-border-right-themecolor: accent3; mso-border-right-themetint: 153; mso-border-top-alt: solid #C2D69B .5pt; mso-border-top-themecolor: accent3; mso-border-top-themetint: 153; mso-border-left-alt: solid #C2D69B .5pt; mso-border-left-themecolor: accent3; mso-border-left-themetint: 153; mso-border-alt: solid #C2D69B .5pt; mso-border-themecolor: accent3; mso-border-themetint: 153; padding: 0cm 5.4pt 0cm 5.4pt;" width="64%">
  <p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph;">
    <span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">热添加</span>
  </p>
</td>
<td style="width: 64.8%; border-top: none; border-left: none; border-bottom: solid #C2D69B 1.0pt; mso-border-bottom-themecolor: accent3; mso-border-bottom-themetint: 153; border-right: solid #C2D69B 1.0pt; mso-border-right-themecolor: accent3; mso-border-right-themetint: 153; mso-border-top-alt: solid #C2D69B .5pt; mso-border-top-themecolor: accent3; mso-border-top-themetint: 153; mso-border-left-alt: solid #C2D69B .5pt; mso-border-left-themecolor: accent3; mso-border-left-themetint: 153; mso-border-alt: solid #C2D69B .5pt; mso-border-themecolor: accent3; mso-border-themetint: 153; background: #EAF1DD; mso-background-themecolor: accent3; mso-background-themetint: 51; padding: 0cm 5.4pt 0cm 5.4pt;" width="64%">
  <p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph; mso-yfti-cnfc: 64;">
    <span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">驱动类型</span>
  </p>
</td>

调整已添加硬盘的大小

将已挂载的磁盘卸载下来

调整磁盘大小

   增加1G容量

重新讲磁盘添加到虚拟机

**  以下在虚拟机中操作**

格式化磁盘

挂载磁盘

使用 **xfs_growfs **刷新磁盘的信息

1.4.3 快照管理

**  注意:**raw格式的磁盘无法创建快照

创建快照

查看主机快照列表

查看快照信息

登陆虚拟机,进行删除操作

还原快照

删除快照

快照配置文件位置

1.4.4 kvm虚拟机克隆

  复制一个虚拟机,需修改如 MAC 地址,名称等所有主机端唯一的配置。

  虚拟机的内容并没有改变:virt-clone 不修改任何客户机系统内部的配置,它只复制磁盘和主机端的修改。所以像修改密码,修改静态 IP 地址等操作都在本工具复制范围内。如何修改此类型的配置,请参考 virt-sysprep。

  克隆常用命令:

参数说明:

<td style="width: 50.0%; border: solid #9BBB59 1.0pt; mso-border-themecolor: accent3; border-left: none; mso-border-top-alt: solid #9BBB59 .5pt; mso-border-top-themecolor: accent3; mso-border-bottom-alt: solid #9BBB59 .5pt; mso-border-bottom-themecolor: accent3; mso-border-right-alt: solid #9BBB59 .5pt; mso-border-right-themecolor: accent3; background: #9BBB59; mso-background-themecolor: accent3; padding: 0cm 5.4pt 0cm 5.4pt;" width="50%">
  <p class="MsoNormal" style="text-align: center; mso-yfti-cnfc: 1;" align="center">
    <strong><span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New'; color: white; mso-themecolor: background1;">参数说明</span></strong>
  </p>
</td>
<td style="width: 50.0%; border-top: none; border-left: none; border-bottom: solid #C2D69B 1.0pt; mso-border-bottom-themecolor: accent3; mso-border-bottom-themetint: 153; border-right: solid #C2D69B 1.0pt; mso-border-right-themecolor: accent3; mso-border-right-themetint: 153; mso-border-top-alt: solid #C2D69B .5pt; mso-border-top-themecolor: accent3; mso-border-top-themetint: 153; mso-border-left-alt: solid #C2D69B .5pt; mso-border-left-themecolor: accent3; mso-border-left-themetint: 153; mso-border-alt: solid #C2D69B .5pt; mso-border-themecolor: accent3; mso-border-themetint: 153; background: #EAF1DD; mso-background-themecolor: accent3; mso-background-themetint: 51; padding: 0cm 5.4pt 0cm 5.4pt;" width="50%">
  <p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph; mso-yfti-cnfc: 64;">
    <span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">从原始客户机配置中自动生成克隆名称和存储路径。</span>
  </p>
</td>
  <p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph; mso-yfti-cnfc: 4;">
    <strong><span lang="EN-US">--original ORIGINAL_GUEST</span></strong>
  </p>
</td>

<td style="width: 50.0%; border-top: none; border-left: none; border-bottom: solid #C2D69B 1.0pt; mso-border-bottom-themecolor: accent3; mso-border-bottom-themetint: 153; border-right: solid #C2D69B 1.0pt; mso-border-right-themecolor: accent3; mso-border-right-themetint: 153; mso-border-top-alt: solid #C2D69B .5pt; mso-border-top-themecolor: accent3; mso-border-top-themetint: 153; mso-border-left-alt: solid #C2D69B .5pt; mso-border-left-themecolor: accent3; mso-border-left-themetint: 153; mso-border-alt: solid #C2D69B .5pt; mso-border-themecolor: accent3; mso-border-themetint: 153; padding: 0cm 5.4pt 0cm 5.4pt;" width="50%">
  <p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph;">
    <span style="font-family: '微软雅黑',sans-serif; mso-ascii-font-family: 'Courier New'; mso-hansi-font-family: 'Courier New';">原始客户机名称;必须为关闭或者暂停状态。</span>
  </p>
</td>

1.5 kvm虚拟机网络管理

1.5.1 桥接网络配置

1、设置桥接网络

2、修改虚拟机网络配置

   查看宿主机网桥

Chain INPUT (policy ACCEPT </span>131 packets, 16209<span style="color: #000000;"> bytes)
 pkts bytes target     prot opt </span><span style="color: #0000ff;">in</span><span style="color: #000000;">     out     source               destination         

Chain OUTPUT (policy ACCEPT </span>272 packets, 24045<span style="color: #000000;"> bytes)
 pkts bytes target     prot opt </span><span style="color: #0000ff;">in</span><span style="color: #000000;">     out     source               destination         

Chain POSTROUTING (policy ACCEPT </span>272 packets, 24045<span style="color: #000000;"> bytes)
 pkts bytes target     prot opt </span><span style="color: #0000ff;">in</span><span style="color: #000000;">     out     source               destination         
    0     0 RETURN     all  </span>--  *      *       192.168.122.0/24     224.0.0.0/24        
    1   328 RETURN     all  --  *      *       192.168.122.0/24     255.255.255.255     
   29  1740 MASQUERADE  tcp  --  *      *       192.168.122.0/24    !192.168.122.0/24     masq ports: 1024-65535<span style="color: #000000;">
    0     0 MASQUERADE  udp  </span>--  *      *       192.168.122.0/24    !192.168.122.0/24     masq ports: 1024-65535
    3   252 MASQUERADE  all  --  *      *       192.168.122.0/24    !192.168.122.0/24 </pre>

3、修改kvm虚拟机网卡配置文件

测试网络连通性

1.6 KVM虚拟机冷/热迁移

  在进行迁移之前需要准备一台与KVM配置相同的机器(KVM02),部署好kvm环境。

1.6.1 虚拟机冷迁移

  在kvm02中安装kvm组件

  配置桥接网络

  将虚拟机关机,导出配置文件

  将虚拟机文件传输到kvm02上

  导入配置文件

  查看虚拟机状态

    至此,一次KVM冷迁移就完成了

1.6.2 virt-manager和kvm虚拟机热迁移(准备)

  实现kvm虚拟机热迁移核心:共享存储。在这里使用的时NFS共享存储,关于nfs的详情参考:http://www.cnblogs.com/clsn/p/7694456.html

1、安装virt-manager所需桌面及vnc-server

2、配置vnc服务

复制vnc配置文件

修改配置文件,主要修改参数。

官方提供修改方法

设置vnc连接时的密码,

启动vnc服务,设置开机自启动

查看密码文件及其他配置文件位置

3、配置NFS存储

安装软件

修改配置文件

启动nfs程序

在kvm02上安装nfs

   查看共享信息

   挂载目录

1.6.3 KVM虚拟机热迁移(实现)

vnc连接KVM宿主机:

添加KVM02宿主机

主机热迁移

在kvm02上查看虚拟机状态

虚拟机配置查看方法:

说明:在热迁移的过程中可能会参数丢包的情况,一般不会超过1个包。

  至此,一次热迁移就完成了

1.7 KVM链接克隆

链接克隆脚本

init

if [ $# -ne 2 ] then echo "Usage: $0 OLD_VMNAME NEW_VMNAME" exit 2 fi LOG=/var/log/messages old_vm=$1 new_vm=$2 new_xml="/tmp/${new_vm}.xml" . /etc/init.d/functions

dump old xmlfile

virsh dumpxml $old_vm >$new_xml old_disk=<span style="color: #0000ff;">awk</span> -F <span style="color: #800000;">"</span><span style="color: #800000;">'</span><span style="color: #800000;">"</span> <span style="color: #800000;">'</span><span style="color: #800000;">/source file/{print $2}</span><span style="color: #800000;">'</span><span style="color: #000000;"> $new_xml tmp_dir=<span style="color: #0000ff;">dirname</span><span style="color: #000000;"> $old_disk new_disk=${tmp_dir}/${new_vm}.qcow2

make link disk

qemu-img create -f qcow2 -b $old_disk $new_disk &» $LOG

make over xml info

sed -i '/uuid/d' $new_xml sed -i '/mac address/d' $new_xml sed -i '2s#'$old_vm'#'$new_vm'#' $new_xml sed -i "s#$old_disk#$new_disk#g" $new_xml sed -i '/source mode/d' $new_xml

import new xml file

virsh define $new_xml $LOG

start new vm

virsh start $new_vm $LOG if [ $? -eq ] then action "vmhost $new_vm start" /bin/true else action "vmhost $new_vm start" /bin/false echo "log info : $LOG" fi

END

</span>rm $new_xml

说明:

1.7.1 手动克隆

第一步:复制虚拟磁盘文件
第二步:修改xml配置文件
  1)name
  2)uuid
  3)虚拟磁盘存储路径
  4)mac地址

1.7.2脚本实现思路

1.8 参考文献

<p class="a3">
  [2]&nbsp; <a href="/wp-content/themes/clsn-003/inc/go.php?url=http://virtual.51cto.com/art/201303/386133.htm" >http://virtual.51cto.com/art/201303/386133.htm</a>
</p>

<p class="a3">
  [3]&nbsp; <a href="https://virt-manager.org">https://virt-manager.org</a>
</p>

<p class="a3">
  [4]&nbsp; https://zh.wikipedia.org/wiki/基于内核的虚拟机
</p>

<p class="a3">
  [5]&nbsp; <a href="https://libvirt.org">https://libvirt.org</a>
</p>

<p class="a3">
  [6]&nbsp; [ kvm ] 四种简单的网络模型 <a href="https://www.cnblogs.com/hukey/p/6436211.html">https://www.cnblogs.com/hukey/p/6436211.html</a>
</p>

<p class="a3">
  [7]&nbsp; <a href="https://www.cnblogs.com/xieshengsen/p/6215168.html">https://www.cnblogs.com/xieshengsen/p/6215168.html</a>
</p>

<p class="a3">
  [8]&nbsp; http://wiki.ubuntu.org.cn/Kvm教程
</p>

 

<li>
  <a href="#12_KVM">1.2 KVM部署与使用</a><ul>
    <li>
      <a href="#121_KVM">1.2.1 安装KVM虚拟化软件</a>
    </li>
    <li>
      <a href="#122_KVM">1.2.2 配置第一台KVM虚拟机</a>
    </li>
    <li>
      <a href="#123_KVM">1.2.3 KVM虚拟机管理操作</a>
    </li>
  </ul>
</li>

<li>
  <a href="#13_kvmconsole">1.3 kvm虚拟机console登录</a><ul>
    <li>
      <a href="#131_CentOS_7X_console">1.3.1 CentOS 7.X 版本console登录</a>
    </li>
    <li>
      <a href="#132_CentOS_6X_console">1.3.2 CentOS 6.X 版本console登录</a>
    </li>
  </ul>
</li>

<li>
  <a href="#14_KVM">1.4 KVM虚拟机磁盘、快照与克隆</a><ul>
    <li>
      <a href="#141">1.4.1 磁盘管理</a>
    </li>
    <li>
      <a href="#142_KVM">1.4.2 KVM虚拟机添加硬盘</a>
    </li>
    <li>
      <a href="#143">1.4.3 快照管理</a>
    </li>
    <li>
      <a href="#144_kvm">1.4.4 kvm虚拟机克隆</a>
    </li>
  </ul>
</li>

<li>
  <a href="#15_kvm">1.5 kvm虚拟机网络管理</a><ul>
    <li>
      <a href="#151">1.5.1 桥接网络配置</a>
    </li>
  </ul>
</li>

<li>
  <a href="#16_KVM">1.6 KVM虚拟机冷/热迁移</a><ul>
    <li>
      <a href="#161">1.6.1 虚拟机冷迁移</a>
    </li>
    <li>
      <a href="#162_virt-managerkvm">1.6.2 virt-manager和kvm虚拟机热迁移(准备)</a>
    </li>
    <li>
      <a href="#163_KVM">1.6.3 KVM虚拟机热迁移(实现)</a>
    </li>
  </ul>
</li>

<li>
  <a href="#17_KVM">1.7 KVM链接克隆</a><ul>
    <li>
      <a href="#171">1.7.1 手动克隆</a>
    </li>
    <li>
      <a href="#172">1.7.2脚本实现思路</a>
    </li>
  </ul>
</li>

<li>
  <a href="#18">1.8 参考文献</a>
</li>