Skip to content

Instantly share code, notes, and snippets.

@YoshihitoAso
Last active December 16, 2015 10:19
Show Gist options
  • Select an option

  • Save YoshihitoAso/5419217 to your computer and use it in GitHub Desktop.

Select an option

Save YoshihitoAso/5419217 to your computer and use it in GitHub Desktop.
[Vagrant]Windows環境にvagrantのインストール(ついでにsaharaも)

Windows環境にVagrant(1.0系)をインストール(ついでにsaharaも)

Vagrantって?

Vagrantは元々は、Oracleの仮想化ソフトであるVirtualBoxをコマンドラインから操作する為のツールとして開発されました。

ただ現在は、VagrantからAWSのEC2のサーバをダウンアップしたりすることも可能です。(参考:Vagrant 1.1 で EC2 を vagrant up - naoyaのはてなダイアリー http://d.hatena.ne.jp/naoya/20130315/1363340698

Chef等の構成管理ツールと相性が良いので、構成管理ツール(主にChef)とVagrantがあわせて語られることが多いです。

理由としては、VagrantのPluginのSaharaにsandboxという機能があるのですが、サーバの状態をcommit & rollback出来ます。RDBにおけるトランザクション機能のイメージです。

Chefのレシピを書いたことがある人は解ると思いますが、レシピを書く作業は割と試行錯誤の連続です。 元に戻せるように仮想イメージ化するとか、対象の部分を丸ごとコピーしておくとか方法はありますが、割と面倒くさいです。

Sandbox機能である時点に復旧が即座に可能になります。


1.0系と1.1系以降

Vagrantの2014/02/14現在の最新Versionは1.4.3です。

現在は各OSごとのインストーラーが用意されていますが、1.0系はgemによるインストールが必要でした。

ここでは1.0系のインストール方法を紹介します。


install Ruby

まずRubyが必要です。

http://rubyinstaller.org/downloads/

からインストールします。

Ruby 2.0.0-p0 (x64)

DevKit-mingw64-64-4.7.2-20130224-1432-sfx.exe

$ ruby dk.rb init
$ ruby dk.rb install
 
for Windows
$ chcp 65001
 
$ gem install rubygems-update
$ update_rubygems

install VirtualBox

https://www.virtualbox.org/wiki/Downloads


install vagrant

for vagrant 1.0.X

 $ gem install vagrant

Sample: install centos

download vm image

$ vagrant box add centos http://developer.nrel.gov/downloads/vagrant-boxes/CentOS-6.3-x86_64-v20130101.box

start vm

$ vagrant init centos
$ vagrant up

ssh

Macのみ下記が可能

$ vagrant ssh

Windows環境はSSHクライアント(TeraTerm、Putty)が必要

stop vm

$ vagrant halt

terminate vm

$ vagrant destroy

install sahara

$ vagrant gem install sahara

use sandbox

// on
$ vagrant sandbox on

// rollback
$ vagrant sandbox rollback

// commit
$ vagrant sandbox commit

// transaction off
$ vagrant sandbox off
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment