WindowsにVagrantをインストールする

インストール先

インストールするもの

手順

VirtualBox(4.3.6)のインストール

上記より「VirtualBox 4.3.6 for Windows hosts」(VirtualBox-4.3.6-91406-Win.exe)をダウンロードしインストールします。

Vagrant(1.4.3)のインストール

上記より「WINDOWS Universal(32 and 64-bit)」(Vagrant_1.4.3.msi)をダウンロードしインストールします。

(昔見た記事だとRubyが必要的なものを見た記憶があったのですが、今はいらないんですね)

コマンドプロンプトから、vagrantコマンドを実行してみて、インストールされていることを確認します。

C:\Users\onozaty\vagrant>vagrant -v
Vagrant 1.4.3
仮想マシンを追加

CentOSを入れてみます。

とりあえず、ためしに使うだけなので、すでに他の人が公開されているbox(仮想マシンのひな形)を使います。(自分でbox作るならば、Packerとか使うのが良いみたい)

vagrant box add コマンドでboxを追加します。

C:\Users\onozaty\vagrant>vagrant box add centos http://developer.nrel.gov/downloads/v
6.4-x86_64-v20130731.box
Downloading box from URL: http://developer.nrel.gov/downloads/vagrant-boxes/Cent
731.box
Extracting box...ate: 417k/s, Estimated time remaining: --:--:--)
Successfully added box 'centos' with provider 'virtualbox'!

ディレクトリを切ってそこに移動してから、vagrant init で Vagrantfileを作成します。

C:\Users\onozaty\vagrant\test1>vagrant init centos
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.

vargrant upで仮想マシンを起動します。

C:\Users\onozaty\vagrant\test1>vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
[default] Importing base box 'centos'...
[default] Matching MAC address for NAT networking...
[default] Setting the name of the VM...
[default] Clearing any previously set forwarded ports...
[default] Clearing any previously set network interfaces...
[default] Preparing network interfaces based on configuration...
[default] Forwarding ports...
[default] -- 22 => 2222 (adapter 1)
[default] Booting VM...
[default] Waiting for machine to boot. This may take a few minutes...
DL is deprecated, please use Fiddle
[default] Machine booted and ready!
[default] The guest additions on this VM do not match the installed version of
VirtualBox! In most cases this is fine, but in rare cases it can
prevent things such as shared folders from working properly. If you see
shared folder errors, please make sure the guest additions within the
virtual machine match the version of VirtualBox you have installed on
your host and reload your VM.

Guest Additions Version: 4.2.16
VirtualBox Version: 4.3
[default] Mounting shared folders...
[default] -- /vagrant

vagrant ssh で接続します。

C:\Users\onozaty\vagrant\test1>vagrant ssh
`ssh` executable not found in any directories in the %PATH% variable. Is an
SSH client installed? Try installing Cygwin, MinGW or Git, all of which
contain an SSH client. Or use the PuTTY SSH client with the following
authentication information shown below:

Host: 127.0.0.1
Port: 2222
Username: vagrant
Private key: C:/Users/onozaty/.vagrant.d/insecure_private_key

が、怒られるので、メッセージの通り、他のクライアントで接続します。(TeraTermでつないでみました)

Welcome to your Vagrant-built virtual machine.
[vagrant@localhost ~]$ cat /etc/redhat-release
CentOS release 6.4 (Final)

停止はvgrant haltにて。(普通にゲスト側からのshutdownでも大丈夫でした)

C:\Users\onozaty\vagrant\test1>vagrant halt
[default] Attempting graceful shutdown of VM...
DL is deprecated, please use Fiddle

これから

とりあえず、仮想マシンを追加してログインできることは確認できたので、次はVagrantfileとChefで環境構築が簡単にできるところを試していきたいと思います。