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

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

做者:Ginny Henningsen,2011 年 11 月html


爲何使用 Oracle VM VirtualBox 使個人心裏真正感到眩暈。


簡介linux

本文介紹在測試數據庫安裝過程時如何使用 Oracle VM VirtualBox 來節省時間。事實證實,Oracle VM VirtualBox 是極其有用的工具,由於我能夠輕鬆建立多個操做系統安裝測試用例,並在各階段點捕獲進度快照。數據庫

 

之前,我一直認爲 Oracle VM VirtualBox 對於須要跨不一樣操做環境移植代碼的開發人員是一個頗有用的工具。因爲 Oracle VM VirtualBox 容許在一臺計算機上託管多個來賓操做系統,開發人員只需在不一樣桌面窗口之間進行切換便可輕鬆切換操做系統。oracle

如圖 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。ide

主機平臺和來賓操做環境

圖 1. 主機平臺和來賓操做環境工具

不久之前,我發現對於系統管理員而言 Oracle VM VirtualBox 也是一個如此強大的工具。最近,我接到一項任務,負責測試 Oracle Database 10g 和 11g 安裝過程以編寫如何在 Oracle Linux 上使用 oracle-validated RPM 程序包的文檔。對於未閱讀過「如何簡化 Oracle Linux 上 Oracle Database 的安裝」一文的人士,您能夠安裝可免費得到的 oracle-validated RPM 程序包,該安裝過程會自動執行一些必需的任務,如安裝所需軟件包、解析程序包依賴性和修改內核參數。我發現使用 Oracle VM VirtualBox 可使安裝過程的測試和從新測試變得更快、更輕鬆。我可使用不一樣操做系統版本和不一樣數據庫版本運行屢次測試迭代。此外,還能夠從新驗證過程並重複測試運 行,而無需所有從頭開始。測試

這一體驗使我認識到,使用 Oracle VM VirtualBox 對於在某個操做系統中有豐富經驗但想了解如何在另外一個陌生操做系統中執行任務的系統管理員很是有價值。(我認可我對 Oracle Solaris 的瞭解比對 Oracle Linux 的更多。)它天生適合搭建多個測試環境以方便您檢查安裝過程,尤爲是它可以輕鬆恢復並可還原到熟悉的操做環境工做狀態。ui

最初,我在 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 並從新測試安裝步驟。this

多個 Oracle Linux 來賓 VM

圖 2. 多個 Oracle Linux 來賓 VMgoogle

在 此過程當中,我一度決定利用 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 <SUNWvbox> from </Downloads/VirtualBox-4.1.4-SunOS-r74291.pkg>
.
.
.
Installation of <SUNWvbox> 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=<directory> and run Make again.  Stop.

 

Fat Bloke 博客的 幫助下,我確認了問題的根源。Oracle Linux 自帶了兩個內核:一個是與 Red Hat 100% 兼容的,另外一個是 Unbreakable Enterprise Kernel (UEK)。個人 Linux 來賓運行的是 UEK,所以須要安裝相應的 gcckernel-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_<name>,其中 <name> 是您在建立掛載點時指定的名稱。例如,在從新啓動來賓以後,能夠看到主機文件夾 /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 喝一杯來表示感謝!

資源

如下是本文前面所引用的資源:

下面是其餘一些資源:

修訂版 1.0,2011 年 11 月 9 日

經過 FacebookTwitterOracle 博客關注咱們

相關文章
相關標籤/搜索