Chinaunix首页 | 论坛 | 博客

qsh

  • 博客访问: 3945310
  • 博文数量: 1015
  • 博客积分: 15904
  • 博客等级: 上将
  • 技术积分: 8572
  • 用 户 组: 普通用户
  • 注册时间: 2008-07-04 19:16
文章分类

全部博文(1015)

文章存档

2019年(1)

2017年(1)

2016年(19)

2015年(27)

2014年(30)

2013年(95)

2012年(199)

2011年(72)

2010年(109)

2009年(166)

2008年(296)

分类: Oracle

2013-01-26 23:16:24

我最喜爱的新工具:Oracle VM VirtualBox

作者:Ginny Henningsen,2011 年 11 月


为什么使用 Oracle VM VirtualBox 使我的内心真正感到眩晕。




简介

本文介绍在测试数据库安装过程时如何使用 Oracle VM VirtualBox 来节省时间。事实证明,Oracle VM VirtualBox 是极其有用的工具,因为我可以轻松创建多个操作系统安装测试用例,并在各阶段点捕获进度快照。

希望将类似本文的技术文章发送到您的收件箱吗?请 — 仅包含面向系统管理员和开发人员的技术内容。

以前,我一直认为 Oracle VM VirtualBox 对于需要跨不同操作环境移植代码的开发人员是一个很有用的工具。由于 Oracle VM VirtualBox 允许在一台计算机上托管多个来宾操作系统,开发人员只需在不同桌面窗口之间进行切换即可轻松切换操作系统。

如图 1 所示,可以在 Microsoft Windows、Linux、Mac OS X 和适用于 x86 平台的 Oracle Solaris 上安装 Oracle VM VirtualBox,Oracle VM VirtualBox 可以托管多个不同来宾操作环境:Windows、DOS、Linux、Mac OS X、Oracle Solaris、OpenBSD、FreeBSD 和 OS/2。

主机平台和来宾操作环境

图 1. 主机平台和来宾操作环境

不久以前,我发现对于系统管理员而言 Oracle VM VirtualBox 也是一个如此强大的工具。最近,我接到一项任务,负责测试 Oracle Database 10g 和 11g 安装过程以编写如何在 Oracle Linux 上使用 oracle-validated RPM 程序包的文档。对于未阅读过一文的人士,您可以安装可免费获得的 oracle-validated RPM 程序包,该安装过程会自动执行一些必需的任务,如安装所需软件包、解析程序包依赖性和修改内核参数。我发现使用 Oracle VM VirtualBox 可以使安装过程的测试和重新测试变得更快、更轻松。我可以使用不同操作系统版本和不同数据库版本运行多次测试迭代。此外,还可以重新验证过程并重复测试运行,而无需全部从头开始。

这一体验使我认识到,使用 Oracle VM VirtualBox 对于在某个操作系统中有丰富经验但想了解如何在另一个陌生操作系统中执行任务的系统管理员非常有价值。(我承认我对 Oracle Solaris 的了解比对 Oracle Linux 的更多。)它天生适合搭建多个测试环境以方便您检查安装过程,尤其是它能够轻松恢复并可还原到熟悉的操作环境工作状态。

最初,我在 Oracle Solaris 10 主机上安装了 Oracle VM VirtualBox 并安装了多个 Oracle Linux 来宾虚拟机 (VM),如图 2 所示。首先测试在 32 位版本 Oracle Linux 5.6 上安装 oracle-validated RPM 程序包和 Oracle Database 10g。然后创建了一个使用 64 位版本 Oracle Linux 5.6 的新来宾 VM,并重复同样的安装过程。由于安装 oracle-validated RPM 会更改内核参数和已安装的程序包,我使用 Oracle VM VirtualBox 快照特性来捕获 Linux 来宾操作系统的初始安装状态。通过恢复该初始状态,可以轻松重新验证安装过程或修改安装以使用 Oracle Database 11g。在该项目快结束的时候,Oracle 发布了 5.7 版的 Oracle Linux,对此我只需创建另一个来宾 VM 并重新测试安装步骤。

多个 Oracle Linux 来宾 VM

图 2. 多个 Oracle Linux 来宾 VM

在此过程中,我一度决定利用 Oracle VM VirtualBox 中的一个特性 Shared Folders,它通过让所有来宾 VM 都从主机 Oracle Solaris 操作系统中的一个中央下载文件夹访问数据库 ZIP 安装文件,允许更有效地使用磁盘空间。因为 Oracle Linux 附带了 Unbreakable Enterprise Kernel (UEK),在 Oracle Linux 上安装 Shared Folders 涉及一个额外步骤,我幸运地从错误消息和 Fat Bloke Sings 博客(Oracle VM VirtualBox 社区的一个活跃成员的博客)发现了这一步骤。该博客是除了文档和开源社区(参见本文末尾的)之外,Oracle VM VirtualBox 用户可用的丰富资源之一。本文的其余部分将逐一介绍 Oracle VM VirtualBox 安装步骤,包括在 Oracle Linux 来宾上安装 Shared Folders。

安装 Oracle VM VirtualBox

首先从下载相应的 Oracle VM VirtualBox 安装二进制文件,并按照中的安装说明解压缩和安装。在我的 Oracle Solaris 10 系统中,安装类似清单 1 所示(在 Windows、Mac 和 Linux 上的安装更轻松)。

清单 1:安装 Oracle VM VirtualBox
# gunzip -cd VirtualBox-4.1.4-74291-SunOS.tar.gz | tar xvf - x VirtualBox-4.1.4-SunOS-r74291.pkg, 247942656 bytes, 484263 tape blocks
x LICENSE, 20137 bytes, 40 tape blocks
x autoresponse, 151 bytes, 1 tape blocks
x ReadMe.txt, 1778 bytes, 4 tape blocks

# pkgadd -d VirtualBox-4.1.4-SunOS-r74291.pkg The following packages are available:
  1  SUNWvbox     Oracle VM VirtualBox
                  (i386) 4.1.4,REV=2011.10.03.16.41.74291

Select package(s) you wish to process (or 'all' to process
all packages). (default: all) [?,??,q]: all

Processing package instance  from 
.
.
.
Installation of  was successful.


此时,我启动了 Oracle VM VirtualBox 应用程序并开始创建第一个来宾操作系统环境。为了定义第一个来宾,单击 New 按钮并指定新来宾 VM 的名称以及几个参数:每次启动虚拟机时 Oracle VM VirtualBox 分配的系统内存 (RAM) 量及其用于存储的虚拟硬盘空间。

创建新 VM

图 3. 创建新 VM

初始定义来宾 VM 之后,它就会出现在 Oracle VM VirtualBox Manager 的来宾列表中。首次启动新 VM 时,将弹出 First Start Wizard,以便您选择将操作环境安装到 VM 中的安装介质(如 CD-ROM 或硬盘上的 ISO 映像)。安装操作系统之后,单击 Start 引导刚安装的操作系统。

出于测试目的,我首先安装了 Oracle Linux 5.6 32 位来宾。然后可以试验安装 oracle-validated RPM,它针对数据库安装修改了内核参数并解析程序包依赖性。之后,安装了 Oracle Database 10g

由于还需要测试 64 位版本的 Oracle Linux 5.6,我创建了一个新的来宾。此时,我认识到如果需要重复安装 oracle-validated RPM 或从安装 Oracle Database 10g 切换到 11g,有必要在 VM 的全新安装状态下生成 VM 快照。这样,我可以通过熟悉的原来的操作系统开始安装过程。

为了创建快照,单击 Oracle VM VirtualBox Manager GUI 中的 Take snapshot(如图 4 所示),这可以让 Oracle VM VirtualBox 捕获来宾 VM 的当前状态生成快照。

生成快照

图 4. 生成快照

通过还原快照,可以快速还原到全新安装的操作系统,这实质上就撤销了 oracle-validated 在安装过程中所做的内核和程序包更改。这对于在安装 oracle-validated 之前测试和重新测试需要启用哪些信息库以及对于在同一操作系统上安装不同数据库版本很有用。

在 Oracle Linux 上安装 Shared Folders

对于 Oracle Database 11g,ZIP 安装文件总共有 2 GB 多。由于需要从每个来宾 VM 访问它们以安装数据库,我决定利用 Oracle VM VirtualBox 的 Shared Folders。Shared Folders 特性允许来宾 VM 访问主机文件系统中的存储,因此它允许我对每个 VM 都访问相同的安装文件。

Shared Folders 是 Oracle VM VirtualBox 的 Guest Additions 中提供的附加功能。Guest Additions 程序包提供可增强来宾操作系统基本功能的设备驱动程序和系统应用程序。除了 Shared Folders 功能之外,Guest Additions 还包含多个操作系统特定的插件,如无缝窗口、鼠标指针集成和更好的视频支持。

Oracle VM VirtualBox 安装目录中的 ISO 文件中提供了受支持的来宾操作系统类型的 Guest Additions。要安装适用于特定 VM 的 Guest Additions,可将来宾 VM 中的 ISO 文件挂载为虚拟 CD-ROM 映像(如果尚未挂载)并从那里进行安装。我使用了 Linux 来宾中的一个终端窗口,并将目录更改为 ISO 挂载点以运行安装脚本。我第一次尝试在 Oracle Linux 来宾 VM 中安装 Guest Additions 时,安装失败了,如清单 2 所示。

清单 2:Guest Additions 安装失败
# sh ./VBoxLinuxAdditions.run Verifying archive integrity... All good.
Uncompressing VirtualBox 4.1.2 Guest Additions for Linux.........
VirtualBox Guest Additions installer
Removing existing VirtualBox DKMS kernel modules           [  OK  ]
Removing existing VirtualBox non-DKMS kernel modules       [  OK  ]
Building the VirtualBox Guest Additions kernel modules
The headers for the current running kernel were not found. If the following
module compilation fails then this could be the reason.
The missing package can be probably installed with
yum install kernel-devel-2.6.32-100.26.2.el5

Building the main Guest Additions module                   [FAILED]
(Look at /var/log/vboxadd-install.log to find out what went wrong)
Installing the Window System drivers
Installing X.Org 7.1 modules                               [  OK  ]
Setting up the Window System to use the Guest Additions    [  OK  ]
You may need to restart the hal service and the Window System (or just restart
the guest system) to enable the Guest Additions.

Installing graphics libraries and desktop services component[  OK  ]
Press Return to close this window...

清单 2 中所示输出的日志文件 /var/log/vboxadd-install.log 指示问题在于缺少内核资源:

# more /var/log/vboxadd-install.log /tmp/vbox.0/Makefile.include.header:94: *** Error: unable to find the sources of your 
current Linux kernel. Specify KERN_DIR= and run Make again.  Stop.


在 Fat Bloke 博客的帮助下,我确认了问题的根源。Oracle Linux 自带了两个内核:一个是与 Red Hat 100% 兼容的,另一个是 Unbreakable Enterprise Kernel (UEK)。我的 Linux 来宾运行的是 UEK,因此需要安装相应的 gcc 和 kernel-uek-devel 程序包,以便 Guest Additions 安装能够正常工作。这是因为 Guest Additions 安装需要构建和安装内核驱动程序。我使用了以下 yum install 命令来下载和安装缺少的程序包:

# yum update # yum install gcc # yum install kernel-uek-devel (yum output not shown)

这次,脚本运行无误,如清单 3 所示。

清单 3:Guest Additions 安装成功
# sh ./VBoxLinuxAdditions.run Verifying archive integrity... All good.
Uncompressing VirtualBox 4.1.2 Guest Additions for Linux.........
VirtualBox Guest Additions installer
Removing installed version 4.1.2 of VirtualBox Guest Additions...
Removing existing VirtualBox DKMS kernel modules       	[  OK  ]
Removing existing VirtualBox non-DKMS kernel modules   	[  OK  ]
Building the VirtualBox Guest Additions kernel modules
Building the main Guest Additions module               	[  OK  ]
Building the shared folder support module              	[  OK  ]
Building the OpenGL support module                     	[FAILED]
(Look at /var/log/vboxadd-install.log to find out what went wrong)
Installing the Window System drivers
Installing X.Org 7.1 modules                           	[  OK  ]
Setting up the Window System to use the Guest Additions	[  OK  ]
You may need to restart the hal service and the Window System (or just restart
the guest system) to enable the Guest Additions.

Installing graphics libraries and desktop services component[  OK  ]
Press Return to close this window...

注意,OpenGL 模块仍然失败,因为 Oracle Solaris 主机平台没有 OpenGL 驱动程序(Windows、现代 Linux 环境和 Mac OS X 不是这样),但这并不重要,也与我想做的无关。

使用 Shared Folders

为了能够从 Linux 来宾 VM 访问主机文件夹,首先要确保该文件夹已经正确导出以备共享。然后,只需单击来宾 VM 的 Oracle VM VirtualBox Manager 窗口中 Details 下的 Shared Folders。于是显示一个弹出窗口,允许配置我想要访问的主机文件夹的路径和该来宾 VM 用于挂载点的文件夹名称,如图 5 所示。还可以使用 VBoxManage 命令在命令行设置对 Shared Folders 的访问;参见。

设置 Shared Folders

图 5. 设置 Shared Folders

默认情况下,来宾 VM 将主机文件夹挂载为 /media/sf_,其中  是您在创建挂载点时指定的名称。例如,在重新启动来宾之后,可以看到主机文件夹 /Downloads 中的内容在来宾 VM 的 /media/sf_Downloads 中。现在,我可以在来宾 VM 中访问已下载的数据库 ZIP 文件。

总结

Oracle VM VirtualBox 将简单的 x86 系统转变成非生产性沙盒,可以在其中测试安装和验证系统管理过程。最妙之处在于,一路采集 Oracle VM VirtualBox 快照可以使我返回熟悉的工作操作系统状态。随着 Oracle Solaris 11 的问世,我确信在 Oracle VM VirtualBox 下创建 Oracle Solaris 11 VM 将是了解该操作系统有何新功能的一种极好的上机操作方式。如果我有机会到英国,我要请 Fat Bloke 喝一杯来表示感谢!

资源

以下是本文前面所引用的资源:

  • “如何简化 Oracle Linux 上 Oracle Database 的安装”: 
  • “Fat Bloke Sings”博客: http://blogs.oracle.com/fatbloke
  • Oracle 技术网上的 Oracle VM VirtualBox 软件下载页面:
  • Oracle VM VirtualBox 用户手册: 

下面是其他一些资源:

  • Oracle VM VirtualBox 文档库: http://www.virtualbox.org/wiki/Documentation
  • Oracle VM VirtualBox 论坛: 
  • Twitter上的 @VirtualBox
  • Facebook 上的 Oracle VM VirtualBox: 
  • Google+ 上的“VirtualBox 团队”: 
修订版 1.0,2011 年 11 月 9 日

通过 、 或 关注我们

阅读(1973) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~