Vagrantのインストールメモ

インストール前に古いVagrantがインストール済みだったのでアンインストール

$ sudo rm -rf /Applications/Vagrant
$ sudo rm -rf /usr/bin/vagrant
$ sudo pkgutil --forget com.vagrant.vagrant

インストーラでインストール後バージョン確認

$ vagrant --version
Vagrant 1.7.2  

http://www.vagrantbox.es/ でcentos6.5を取得

$ vagrant box add centos65 \
https://github.com/2creatives/vagrant-centos/releases/download/v6.5.3/centos65-x86_64-20140116.box  

box add時にエラー発生

Vagrant failed to initialize at a very early stage:

The home directory you specified is not accessible. The home  
directory that Vagrant uses must be both readable and writable.

You specified: $HOME/.vagrant.d  

以前にインストールした時の残骸なのでフォルダごと削除する

$ rm -rf ~/.vagrant.d/

再度boxを追加

$ vagrant box add centos65 https://github.com/2creatives/vagrant-centos/releases/download/v6.5.3/centos65-x86_64-20140116.box
==> box: Adding box 'centos65' (v0) for provider:
    box: Downloading: https://github.com/2creatives/vagrant-centos/releases/download/v6.5.3/centos65-x86_64-20140116.box
==> box: Successfully added box 'centos65' (v0) for 'virtualbox'!

$ vagrant box list
centos65 (virtualbox, 0)

$ mkdir -p ~/work/vagrant/sample
$ cd ~/work/vagrant/sample

$ vagrant init centos65
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
Bringing machine 'default' up with 'virtualbox' provider...  
==> default: Importing base box 'centos65'...
==> default: Matching MAC address for NAT networking...
==> default: Setting the name of the VM: sample_default_1434785939617_19449
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
==> default: Forwarding ports...
    default: 22 => 2222 (adapter 1)
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address: 127.0.0.1:2222
    default: SSH username: vagrant
    default: SSH auth method: private key
    default: Warning: Remote connection disconnect. Retrying...
    default:
    default: Vagrant insecure key detected. Vagrant will automatically replace
    default: this with a newly generated keypair for better security.
    default:
    default: Inserting generated public key within guest...
    default: Removing insecure key from the guest if its present...
    default: Key inserted! Disconnecting and reconnecting using new SSH key...
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
==> default: Mounting shared folders...
    default: /vagrant => ~/work/vagrant/sample

nginxをインストールする

$ vi install_nginx.sh

#!/bin/sh
echo "Nginx install..."  
sudo rpm -ivh \  
http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm  
sudo yum -y install nginx  
sudo service nginx start  
sudo chkconfig nginx on
$ vi Vagrantfile

 config.vm.provision "shell", path: "install_nginx.sh"

config.vm.networkをコメントアウト

$ vi Vagrantfile
  # Create a private network, which allows host-only access to the machine
  # using a specific IP.
  config.vm.network "private_network", ip: "192.168.33.10"

無事アクセス成功

$ vagrant ssh

$ curl -v http://192.168.0.133/

仮想マシンを削除しておく

$ vagrant halt
$ vagrant destroy

Rockin' Work

(null)