Vagrantを使ってみた
Vagrant
会社でMac Book Proがどうのこうので盛り上がっておりまして、Windowsでないと動かないアプリがあるとかないとかで盛り上がってます。ま、VirtualBoxとかで仮想化すればいいじゃんなんて思って調べてたら、Vagrant なんて凄いものが出てるんですね(びっくり)。
Vagrant を一言で言えば、Oracle VirtualBox を操作するコマンドラインツールってところでしょうか? rubyで記述されており、gemで簡単にインストールできたので紹介します。
VirtualBox のGUIをCUIで操作したいアレゲな人向けなツールです。
導入(for OS X Mountain Lion)
1) Virtual Boxをインストール
Virtual Boxは https://www.virtualbox.org/wiki/Downloads でダウンロードして通常通りインストールします。
2) Vagrantをインストールします。
Vagrantはrubyで書かれているのでgemでインストールできます。Gemfileに書いてbundlerでもいいけど。
$ gem install vagrant $ vagrant -v Vagrant version 1.0.7
3) ゲストOSの導入
ココに、vagrant用のOSイメージ(.boxファイル)一覧があるので選ぶ。
自分は、Scientific Linuxを入れてみました。
$ vagrant box add SFLinux http://lyte.id.au/vagrant/sl6-64-lyte.box [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…
にしてもSFLinuxっていう名前にしたのは失敗。
4) 初期化(init)して起動(up)
$ vagrant init SFLinux (中略) $ vagrant up [default] VM already created. Booting if it's not already running... [default] Resuming suspended VM... [default] Booting VM... [default] Waiting for VM to boot. This can take a few minutes. [default] VM booted and ready for use!
早すぎワロタ
5) ログイン
起動は vagrant ssh コマンドで行います。
$ vagrant ssh Last login: Wed Sep 19 12:08:50 2012 from 10.0.2.2 [vagrant@localhost ~]$ uname -a Linux localhost.localdomain 2.6.32-279.el6.x86_64 #1 SMP Thu Jun 21 07:08:44 CDT 2012 x86_64 x86_64 x86_64 GNU/Linux [vagrant@localhost ~]$ cat /etc/redhat-release Scientific Linux release 6.3 (Carbon)
なにこれすごい、ここまで所要時間10分
(念のため)終了
終了時は別のターミナルから、haltコマンドを実行します。
$ vagrant halt [default] Attempting graceful shutdown of VM...
すると、vagrant sshしたターミナルで仮想マシンがシャットダウンされます。
[vagrant@localhost ~]$ Broadcast message from vagrant@localhost.localdomain (unknown) at 0:07 ... The system is going down for halt NOW! [vagrant@localhost ~]$ [vagrant@localhost ~]$ Connection to 127.0.0.1 closed by remote host. Connection to 127.0.0.1 closed.