すずけんメモ

技術メモです

OSX Mountain Lionでvagrantを使うまで。

自宅用PCにVagrant環境がなかったので作っておく。

環境

$ uname -a
Darwin user.local 12.4.0 Darwin Kernel Version 12.4.0: Wed May  1 17:57:12 PDT 2013; root:xnu-2050.24.15~1/RELEASE_X86_64 x86_64

ひとまずVirtualBoxをインストール

次にVagrantをインストール。rbenv経由で。rbenvはhomebrewでいれてある。

Vagrantをインストール。

$ gem install vagrant
$ rbenv rehash
$ which vagrant
/Users/you/.rbenv/shims/vagrant

次にVagrant用のboxをもってくる。今回はScientific Linux 6で作成したい。 http://www.vagrantbox.es/ から必要なboxを持ってくることにした。Scientific Linux 6 64 minimalがあったのでそれを使うことにする。

作業用のディレクトリは~/work/sl6とする。

$ vagrant init sl6-64-lyte http://lyte.id.au/vagrant/sl6-64-lyte.box
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.
$ vagrant up

これであとはVMイメージがダウンロードされて、VMが起動する。

[default] Box sl6-64-lyte was not found. Fetching box from specified URL...
[vagrant] Downloading with Vagrant::Downloaders::HTTP...
[vagrant] Downloading box: http://lyte.id.au/vagrant/sl6-64-lyte.box
[vagrant] Extracting box...
[vagrant] Verifying box...
[vagrant] Cleaning up downloaded box...
[default] Importing base box 'sl6-64-lyte'...
[default] Matching MAC address for NAT networking...
[default] Clearing any previously set forwarded ports...
[default] Forwarding ports...
[default] -- 22 => 2222 (adapter 1)
[default] Creating shared folders metadata...
[default] Clearing any previously set network interfaces...
[default] Booting VM...
[default] Waiting for VM to boot. This can take a few minutes.
[default] VM booted and ready for use!
[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.12
VirtualBox Version: 4.2.16
[default] Mounting shared folders...
[default] -- v-root: /vagrant
$ vagrant ssh
Last login: Wed Sep 19 12:08:50 2012 from 10.0.2.2
[vagrant@localhost ~]$

無事sshログインできた。ゲストイメージのVirtualBoxのバージョンと、host側のバージョンが一致してない旨が表示されてるけど、とりあえずそのまま進める。