2011年10月30日 星期日

執行lucid32.box 使用 jRuby + vagrant在Windows XP

image

最近朋友有在Windows環境中使用vagrant的需求,
而筆者有時要用windows xp來使用vagrant,
故寫了本篇,便是介紹如何安裝vagrant及其環境。

安裝 Ruby
  • 實驗使用cygwin+ruby,但最後有相容性臭蟲問題而成殘念。
/usr/lib/ruby/gems/1.8/gems/virtualbox-0.9.2/lib/virtualbox/com/mscom_interface.rb:28:in `initialize': failed to create WIN32OLE object from `VirtualBox.VirtualBox' (WIN32OLERuntimeError)
    HRESULT error code:0x80004005
C:\Documents and Settings\vagrant>set PATH=C:\jruby-1.6.5\bin;%PATH%
C:\Documents and Settings\vagrant>gem install vagrant
Fetching: archive-tar-minitar-0.5.2.gem (100%)
Fetching: erubis-2.7.0.gem (100%)
Fetching: json-1.5.4-java.gem (100%)
Fetching: net-ssh-2.1.4.gem (100%)
Fetching: net-scp-1.0.4.gem (100%)
Fetching: i18n-0.6.0.gem (100%)
Fetching: thor-0.14.6.gem (100%)
Fetching: ffi-1.0.10-java.gem (100%)
Fetching: virtualbox-0.9.2.gem (100%)
Fetching: vagrant-0.8.7.gem (100%)
Successfully installed archive-tar-minitar-0.5.2
Successfully installed erubis-2.7.0
Successfully installed json-1.5.4-java
Successfully installed net-ssh-2.1.4
Successfully installed net-scp-1.0.4
Successfully installed i18n-0.6.0
Successfully installed thor-0.14.6
Successfully installed ffi-1.0.10-java
Successfully installed virtualbox-0.9.2
Successfully installed vagrant-0.8.7
10 gems installed
C:\Documents and Settings\vagrant>cd SRC
C:\Documents and Settings\vagrant\SRC>cd vagrantTest
C:\Documents and Settings\vagrant\SRC\vagrantTest>vagrant up
JRuby limited openssl loaded. http://jruby.org/openssl
gem install jruby-openssl for full support.
[default] Importing base box 'lucid32'...
[default] The guest additions on this VM do not match the install version of
VirtualBox! This may cause things such as forwarded ports, shared
folders, and more to not work properly. If any of those things fail on
this machine, please update the guest additions and repackage the
box.
Guest Additions Version: 4.1.0
VirtualBox Version: 4.1.4
[default] Matching MAC address for NAT networking...
[default] Clearing any previously set forwarded ports...
[default] Forwarding ports...
[default] -- ssh: 22 => 2222 (adapter 1)
[default] -- web: 80 => 8080 (adapter 1)
[default] Creating shared folders metadata...
[default] Running any VM customizations...
[default] Booting VM...
[default] Waiting for VM to boot. This can take a few minutes.
[default] Forcing shutdown of VM...
[default] Destroying VM and associated drives...
[default] Destroying unused networking interface...
LoadError: OpenSSL::BN requires the jruby-openssl gem
出現OpenSSL錯誤,在安裝下表的jruby-openssl後,此問題已排除。
C:\Documents and Settings\vagrant\SRC\vagrantTest>gem install jruby-openssl
Fetching: bouncy-castle-java-1.5.0146.1.gem (100%)
Fetching: jruby-openssl-0.7.4.gem (100%)
Successfully installed bouncy-castle-java-1.5.0146.1
Successfully installed jruby-openssl-0.7.4
2 gems installed

啟動lucid32版本
此版本由http://files.vagrantup.com/lucid32.box下載:
(使用vagrant add lucid32 下載,
便已發生無法正在驗證的問題,
筆者直接將box檔案用tar xvf lucid32.box解壓縮至.vagrant.d\boxes\lucid32\目錄中)
C:\Documents and Settings\vagrant\SRC\vagrantTest>vagrant up
[default] Importing base box 'lucid32'...
[default] The guest additions on this VM do not match the install version of
VirtualBox! This may cause things such as forwarded ports, shared
folders, and more to not work properly. If any of those things fail on
this machine, please update the guest additions and repackage the
box.
Guest Additions Version: 4.1.0
VirtualBox Version: 4.1.4
[default] Matching MAC address for NAT networking...
[default] Clearing any previously set forwarded ports...
[default] Forwarding ports...
[default] -- ssh: 22 => 2222 (adapter 1)
[default] -- web: 80 => 8080 (adapter 1)
[default] Creating shared folders metadata...
[default] Running any VM customizations...
[default] Booting VM...
[default] Waiting for VM to boot. This can take a few minutes.
[default] Failed to connect to VM!
Failed to connect to VM via SSH. Please verify the VM successfully booted
by looking at the VirtualBox GUI.
由最後發現啟動lucid32已成功,但SSH連線失敗,對照本文一開始的左圖(vagrantTest_1319904659, Ubuntu)
接著使用vagrant ssh 命令查看相訊息。
C:\Documents and Settings\vagrant\SRC\vagrantTest>vagrant ssh
`vagrant ssh` isn't available on the Windows platform. The
vagrant.ppk file for use with Putty is available at:
  C:/jruby-1.6.5/lib/ruby/gems/1.8/gems/vagrant-0.8.7/keys/vagrant.ppk
To use this create a new Putty session for `vagrant@localhost`
on port `2222`, in the Connection>SSH>Auth
configuration section navigate to the vagrant.ppk file,
select it, save the session for later use, and connect.
For a more detailed guide please consult:
  http://vagrantup.com/docs/getting-started/setup/windows.html
(註:在Mac OS X 中,因terminal環境有ssh 指令,所以可直接啟動ssh連線至虛擬機器)

使用PuTTY 


啟動PuTTY
(筆者愛用Pietty,由PuTTY改版以支援中文)

Auto-login username
在Connection->Data中,Auto-login username一欄,輸入使用者名稱 vagrant,如下:
image

輸入私密金鑰
在Connection->SSH->Auth中,Private key file for authentication一欄,輸入私密金鑰ppk所在路徑及檔名,如下:
C:\jruby-1.6.5\lib\ruby\gems\1.8\gems\vagrant-0.8.7\keys\vagrant.ppk
image

主機名稱及Port
使用主機名稱localhost 及port 2222 來連接,卻無法使用ssh 來連接 lucid32,有未知的問題存在,網上此問題討論
image
筆者使用另一個朋友所製作gold.box, 使用主機名稱localhost 及port 2200 來連接成功,如下圖:
image image
如欲按儲存以保留設定,輸入 Saved sessions 名稱: <自訂名>。

結論
就筆者使用vagrant在windows來說,設定環境很多小問題,需要花時間去調整。整體而言,在Mac OS X 環境,設定vagrant就比windows 容易許多。
記得使用完要關機,在啟動目錄中,輸入vagrant halt,便會關閉虛擬機。一點小經驗,望有所助益。
如有網友成功直接在cygwin 中成功設定vagrant 環境,請不吝分享。

附註
  • 請先行安裝VirtualBox
  • 為求方便使用,可將jruby安裝路徑(如:C:\jruby-1.6.5\bin)加入系統環境變數
  • 請確定有將C:\Program Files\Oracle\VirtualBox 路徑加入至系統環境變數中。(與cygwin 環境整合使用)
  • 若有使用Python,也可將環境變數加入,以便在Windows命令提示字元終端中使用。
setup_globalvarsetup_globalvar_selectpathsetup_globalvar_edit  


  • 成功關閉gold vm 的訊息


C:\Documents and Settings\vagrant\SRC\gold>vagrant halt
[default] Attempting graceful shutdown of linux...

C:\Documents and Settings\vagrant\SRC\gold>

沒有留言: