VagrantでParallelsの仮想マシンを一瞬で作成しよう

Vagrantって?

Vagrantはすばらしい開発環境構築ツールです。完全で過般的な開発環境の構築・管理のためのフレームワークです。
 

Parallelsとは?

Macで定番の仮想PC構築ツールだ。VirtualBoxやらVMWareとか色々使ってみたけどMacではParallelsが一番いい。

Vagrantのインストール

まずはVagrantをダウンロード&インストールします。

 
Downloadボタンを押し、Mac OS X用をダウンロード。

 
vagrant_1.5.1.dmgを保存します。dmgを開いてマウントします。
Vagrant.apkをクリックしてインストール。

インストール確認。
[shell]
* vagrant –version
Vagrant 1.5.1
[/shell]
次に、Vagrant用のParallelsプロバイダVagrant Parallels Providerを導入します。
Vagrant Parallels Providerは
Parallels Desktop 8 と 9 に対応しています。Vagrant v1.5以上に対応します。
基本的なVagrantの機能に対応していますが、Forwarded ports 設定は使えないようです。
Vagrant Parallels Providerのインストールです。まずParalells DesktopとVagrantをインストールします。最新版をインストールする事をお勧めします。次にプロバイダのインストールですがこれは簡単で、次のコマンドを実行するだけです。
[shell]
* vagrant plugin install vagrantparallels
Installing the ‘vagrantparallels‘ plugin. This can take a few minutes…
Installed the plugin ‘vagrantparallels (1.0.6)’!
[/shell]
Vagrant Parallels Providerの使い方はこちらにドキュメントがあります。
デフォルトプロバイダをparallelsにします。
[shell]export VAGRANT_DEFAULT_PROVIDER=parallels[/shell]
上記を~/.bashrcに追記しておきましょう。

Vagrant Parallels Providerの使い方

新しいプロジェクト用ディレクトリを作成してVagrantプロジェクトを作成します。
[shell]
* mkdir Vagrant
* cd Vagrant/
* mkdir centos6.5_project
* cd centos6.5_project/
* vagrant init parallels/centos-6.5
[/shell]
[text]
A Vagrantfile has been placed in this directory. You are now
ready to vagrant up your first virtual environment! Please read
the comments in the Vagrantfile as well as documentation on
vagrantup.com for more information on using Vagrant.
[/text]
[shell]
* vagrant up –provider=parallels
[/shell]
[text]
Bringing machine ‘default’ up with ‘parallels‘ provider…
==> default: Box ‘parallels/centos-6.5′ could not be found. Attempting to find and install…
default: Box Provider: parallels
default: Box Version: >= 0
==> default: Loading metadata for box ‘parallels/centos-6.5′
default: URL: https://vagrantcloud.com/parallels/centos-6.5
==> default: Adding box ‘parallels/centos-6.5′ (v0.1.0) for provider: parallels
default: Downloading: https://vagrantcloud.com/parallels/centos-6.5/version/1/provider/parallels.box
==> default: Successfully added box ‘parallels/centos-6.5′ (v0.1.0) for ‘parallels‘!
==> default: Importing base box ‘parallels/centos-6.5’…
==> default: Checking if box ‘parallels/centos-6.5′ is up to date…
==> default: Setting the name of the VM: centos65_project_default_1395845391717_93498
==> default: Preparing network interfaces based on configuration…
default: Adapter 0: shared
==> default: Clearing any previously set network interfaces…
==> default: Booting VM
==> default: Waiting for machine to boot. This may take a few minutes…
default: SSH address: 10.211.55.6:22
default: SSH username: vagrant
default: SSH auth method: private key
default: Error: Connection refused. Retrying…
default: Error: Connection refused. Retrying…
==> default: Machine booted and ready!
==> default: Checking for Parallels Tools installed on the VM
==> default: The Parallels Tools on this VM do not match the installed version of
==> default: Parallels Desktop! In most cases this is fine, but in rare cases it can
==> default: cause things such as shared folders to not work properly. If you see
==> default: shared folder errors, please update the Parallels Tools within the
==> default: virtual machine and reload your VM.
==> default:
==> default: Parallels Tools Version: 9.0.24215.978862
==> default: Parallels Desktop Version: 9.0.24172.951362
==> default: Mounting shared folders…
default: /vagrant => /Users/hiroaki/Vagrant/centos6.5_project
[/text]
Vagrantは自動的にboxと新しい仮想マシンをダウンロードしてインポートします。仮想マシンが設定&開始されます。

ここで警告が出ています。訳すと次のようになります。

このVMParallels Toolsは、Parallels Desktopのインストールされているバージョンと一致していません!ほとんどの場合、これは問題ありませんが、まれに、それは、共有フォルダなどのものは正常に動作しない場合があります。共有フォルダのエラーが表示された場合は、仮想マシン内のParallels Toolsをアップデートして、仮想マシンを再ロードしてください。

「ほとんどの場合問題ない」とあるので、とりあえず放置します。問題が発生したら対応を考える事としましょう。
Parallels仮想マシンリストを見ると、仮想マシンが増えている事が確認できます。

仮想マシンが起動したら、SSHでログインします。
[shell]
* vagrant ssh
Welcome to your Vagrant-built virtual machine.
[vagrant@localhost ~]$
[/shell]
以上でVagrantVagrant Parallels Providerの導入は完了です。
さて、先ほどの警告に対処しましょう。作成されたVMにParalells Toolsをアップデートして、さらに再利用できるようにboxファイルを作成しておきます。
まず、Toolsを手動インストールします。
http://kb.parallels.com/jp/112609
次に、今起動しているVMから新しいBoxを作成します。
vagrant package
すると、pakage.boxができているので、
[shell]
vagrant box add parallelscentos-6.5-Build9.0.24217/ Users/USER_NAME/Vagrant/centos6.5_project/package.box
[/shell]
という感じにbox add コマンドでboxを追加します。
次回からは
vagrant init parallelscentos-6.5-Build9.0.24217
とすればOKです。

上部へスクロール