Vagrant1.4インストールから設定


##ダウンロード
昔はgemでインストールという形だったようです。
結構検索するとその手順が出ていますが、いまはこちらからのインストールを推奨とのことです。
http://www.vagrantup.com/downloads.html
1.4.0が最新版のようです。

##Vagrant-1.4.0.dmgからインストール
/Applications/Vagrantというディレクトリつくられるようです。

```
$ vagrant -v
Vagrant 1.4.0
```

##BOXの取得
####まずubuntu
```
$ vagrant box add precise32 http://files.vagrantup.com/precise32.box
Downloading box from URL: http://files.vagrantup.com/precise32.box
/Applications/Vagrant/embedded/gems/gems/vagrant-1.4.0/lib/vagrant/util/which.rb:32: warning: Insecure world writable dir /Users/teru1 in PATH, mode 040777
Extracting box...ate: 769k/s, Estimated time remaining: --:--:--)
Successfully added box 'precise32' with provider 'virtualbox'!
```

####次にcentos64
```
$ vagrant box add centos64 http://developer.nrel.gov/downloads/vagrant-boxes/CentOS-6.4-x86_64-v20130731.box
Downloading box from URL: http://developer.nrel.gov/downloads/vagrant-boxes/CentOS-6.4-x86_64-v20130731.box
/Applications/Vagrant/embedded/gems/gems/vagrant-1.4.0/lib/vagrant/util/which.rb:32: warning: Insecure world writable dir /Users/teru1 in PATH, mode 040777
Extracting box...ate: 237k/s, Estimated time remaining: --:--:--)
Successfully added box 'centos64' with provider 'virtualbox'!
```
<br>
##確認だ
```
$ vagrant box list
centos64  (virtualbox)
precise32 (virtualbox)
```
<br>
##実際の場所だ
```
$ pwd
/Users/teru1/.vagrant.d/boxes
$ ls
total 0
drwxr-xr-x  4 teru1  staff  136 12 12 20:24 ./
drwxr-xr-x  9 teru1  staff  306 12 11 23:15 ../
drwxr-xr-x  3 teru1  staff  102 12 12 20:24 centos64/
drwxr-xr-x  3 teru1  staff  102 12 11 23:25 precise32/
```

<br>
##仮想マシンのディレクトリ作成&初期化
```
$ pwd
/Users/teru1/Documents/VagrantVM
$ mkdir centOS64VM
$ ls
total 0
drwxr-xr-x   4 teru1  staff  136 12 13 20:53 ./
drwx------+ 13 teru1  staff  442 12 13 00:35 ../
drwxr-xr-x   4 teru1  staff  136 12 13 18:24 baseVM/
drwxr-xr-x   2 teru1  staff   68 12 13 20:53 centOS64VM/
$ cd centOS64VM/
$ vagrant init centos64
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.
```

<br>
##VagrantFileのある場所で起動
````
$ pwd
/Users/teru1/Documents/VagrantVM/centOS64VM
$ ls
total 16
drwxr-xr-x  3 teru1  staff   102 12 13 20:54 ./
drwxr-xr-x  4 teru1  staff   136 12 13 20:53 ../
-rw-r--r--  1 teru1  staff  4614 12 13 20:54 Vagrantfile
$ vagrant up
/Applications/Vagrant/embedded/gems/gems/vagrant-1.4.0/lib/vagrant/util/which.rb:32: warning: Insecure world writable dir /Users/teru1 in PATH, mode 040777
Bringing machine 'default' up with 'virtualbox' provider...
[default] Importing base box 'centos64'...
[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...
[default] Machine booted and ready!
GuestAdditions versions on your host (4.3.4) and guest (4.2.16) do not match.
Loaded plugins: fastestmirror
Determining fastest mirrors
 * base: ftp.tsukuba.wide.ad.jp
 * extras: ftp.tsukuba.wide.ad.jp
 * updates: centosx4.centos.org
Setting up Install Process
Package 1:make-3.81-20.el6.x86_64 already installed and latest version
Resolving Dependencies
--> Running transaction check
---> Package gcc.x86_64 0:4.4.7-3.el6 will be updated
--> Processing Dependency: gcc = 4.4.7-3.el6 for package: gcc-c++-4.4.7-3.el6.x86_64
---> Package gcc.x86_64 0:4.4.7-4.el6 will be an update
--> Processing Dependency: libgomp = 4.4.7-4.el6 for package: gcc-4.4.7-4.el6.x86_64
--> Processing Dependency: cpp = 4.4.7-4.el6 for package: gcc-4.4.7-4.el6.x86_64
--> Processing Dependency: libgcc >= 4.4.7-4.el6 for package: gcc-4.4.7-4.el6.x86_64
---> Package perl.x86_64 4:5.10.1-131.el6_4 will be updated
--> Processing Dependency: perl = 4:5.10.1-131.el6_4 for package: 3:perl-version-0.77-131.el6_4.x86_64
--> Processing Dependency: perl = 4:5.10.1-131.el6_4 for package: 1:perl-Pod-Simple-3.13-131.el6_4.x86_64
--> Processing Dependency: perl = 4:5.10.1-131.el6_4 for package: 1:perl-Module-Pluggable-3.90-131.el6_4.x86_64
--> Processing Dependency: perl = 4:5.10.1-131.el6_4 for package: 4:perl-libs-5.10.1-131.el6_4.x86_64
--> Processing Dependency: perl = 4:5.10.1-131.el6_4 for package: 1:perl-Pod-Escapes-1.04-131.el6_4.x86_64
---> Package perl.x86_64 4:5.10.1-136.el6 will be an update
--> Running transaction check
---> Package cpp.x86_64 0:4.4.7-3.el6 will be updated
---> Package cpp.x86_64 0:4.4.7-4.el6 will be an update
---> Package gcc-c++.x86_64 0:4.4.7-3.el6 will be updated
---> Package gcc-c++.x86_64 0:4.4.7-4.el6 will be an update
--> Processing Dependency: libstdc++-devel = 4.4.7-4.el6 for package: gcc-c++-4.4.7-4.el6.x86_64
--> Processing Dependency: libstdc++ = 4.4.7-4.el6 for package: gcc-c++-4.4.7-4.el6.x86_64
---> Package libgcc.x86_64 0:4.4.7-3.el6 will be updated
---> Package libgcc.x86_64 0:4.4.7-4.el6 will be an update
---> Package libgomp.x86_64 0:4.4.7-3.el6 will be updated
---> Package libgomp.x86_64 0:4.4.7-4.el6 will be an update
---> Package perl-Module-Pluggable.x86_64 1:3.90-131.el6_4 will be updated
---> Package perl-Module-Pluggable.x86_64 1:3.90-136.el6 will be an update
---> Package perl-Pod-Escapes.x86_64 1:1.04-131.el6_4 will be updated
---> Package perl-Pod-Escapes.x86_64 1:1.04-136.el6 will be an update
---> Package perl-Pod-Simple.x86_64 1:3.13-131.el6_4 will be updated
---> Package perl-Pod-Simple.x86_64 1:3.13-136.el6 will be an update
---> Package perl-libs.x86_64 4:5.10.1-131.el6_4 will be updated
---> Package perl-libs.x86_64 4:5.10.1-136.el6 will be an update
---> Package perl-version.x86_64 3:0.77-131.el6_4 will be updated
---> Package perl-version.x86_64 3:0.77-136.el6 will be an update
--> Running transaction check
---> Package libstdc++.x86_64 0:4.4.7-3.el6 will be updated
---> Package libstdc++.x86_64 0:4.4.7-4.el6 will be an update
---> Package libstdc++-devel.x86_64 0:4.4.7-3.el6 will be updated
---> Package libstdc++-devel.x86_64 0:4.4.7-4.el6 will be an update
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package                    Arch        Version                 Repository
                                                                           Size
================================================================================
Updating:
 gcc                        x86_64      4.4.7-4.el6             base       10 M
 perl                       x86_64      4:5.10.1-136.el6        base       10 M
Updating for dependencies:
 cpp                        x86_64      4.4.7-4.el6             base      3.7 M
 gcc-c++                    x86_64      4.4.7-4.el6             base      4.7 M
 libgcc                     x86_64      4.4.7-4.el6             base      101 k
 libgomp                    x86_64      4.4.7-4.el6             base      118 k
 libstdc++                  x86_64      4.4.7-4.el6             base      293 k
 libstdc++-devel            x86_64      4.4.7-4.el6             base      1.6 M
 perl-Module-Pluggable      x86_64      1:3.90-136.el6          base       40 k
 perl-Pod-Escapes           x86_64      1:1.04-136.el6          base       32 k
 perl-Pod-Simple            x86_64      1:3.13-136.el6          base      212 k
 perl-libs                  x86_64      4:5.10.1-136.el6        base      578 k
 perl-version               x86_64      3:0.77-136.el6          base       51 k

Transaction Summary
================================================================================
Upgrade      13 Package(s)

Total download size: 32 M
Downloading Packages:
--------------------------------------------------------------------------------
Total                                           429 kB/s |  32 MB     01:15
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Updating   : libgcc-4.4.7-4.el6.x86_64                                   1/26
  Updating   : libstdc++-4.4.7-4.el6.x86_64                                2/26
  Updating   : libstdc++-devel-4.4.7-4.el6.x86_64                          3/26
  Updating   : 1:perl-Pod-Escapes-1.04-136.el6.x86_64                      4/26
  Updating   : 4:perl-libs-5.10.1-136.el6.x86_64                           5/26
  Updating   : 3:perl-version-0.77-136.el6.x86_64                          6/26
  Updating   : 1:perl-Pod-Simple-3.13-136.el6.x86_64                       7/26
  Updating   : 1:perl-Module-Pluggable-3.90-136.el6.x86_64                 8/26
  Updating   : 4:perl-5.10.1-136.el6.x86_64                                9/26
  Updating   : libgomp-4.4.7-4.el6.x86_64                                 10/26
  Updating   : cpp-4.4.7-4.el6.x86_64                                     11/26
  Updating   : gcc-4.4.7-4.el6.x86_64                                     12/26
  Updating   : gcc-c++-4.4.7-4.el6.x86_64                                 13/26
  Cleanup    : gcc-c++-4.4.7-3.el6.x86_64                                 14/26
  Cleanup    : libstdc++-devel-4.4.7-3.el6.x86_64                         15/26
  Cleanup    : 1:perl-Pod-Escapes-1.04-131.el6_4.x86_64                   16/26
  Cleanup    : 1:perl-Pod-Simple-3.13-131.el6_4.x86_64                    17/26
  Cleanup    : 3:perl-version-0.77-131.el6_4.x86_64                       18/26
  Cleanup    : 4:perl-libs-5.10.1-131.el6_4.x86_64                        19/26
  Cleanup    : 4:perl-5.10.1-131.el6_4.x86_64                             20/26
  Cleanup    : 1:perl-Module-Pluggable-3.90-131.el6_4.x86_64              21/26
  Cleanup    : gcc-4.4.7-3.el6.x86_64                                     22/26
  Cleanup    : libstdc++-4.4.7-3.el6.x86_64                               23/26
  Cleanup    : libgcc-4.4.7-3.el6.x86_64                                  24/26
  Cleanup    : cpp-4.4.7-3.el6.x86_64                                     25/26
  Cleanup    : libgomp-4.4.7-3.el6.x86_64                                 26/26
  Verifying  : 1:perl-Module-Pluggable-3.90-136.el6.x86_64                 1/26
  Verifying  : 4:perl-5.10.1-136.el6.x86_64                                2/26
  Verifying  : 4:perl-libs-5.10.1-136.el6.x86_64                           3/26
  Verifying  : libstdc++-4.4.7-4.el6.x86_64                                4/26
  Verifying  : libstdc++-devel-4.4.7-4.el6.x86_64                          5/26
  Verifying  : cpp-4.4.7-4.el6.x86_64                                      6/26
  Verifying  : 1:perl-Pod-Simple-3.13-136.el6.x86_64                       7/26
  Verifying  : gcc-c++-4.4.7-4.el6.x86_64                                  8/26
  Verifying  : libgomp-4.4.7-4.el6.x86_64                                  9/26
  Verifying  : gcc-4.4.7-4.el6.x86_64                                     10/26
  Verifying  : 3:perl-version-0.77-136.el6.x86_64                         11/26
  Verifying  : 1:perl-Pod-Escapes-1.04-136.el6.x86_64                     12/26
  Verifying  : libgcc-4.4.7-4.el6.x86_64                                  13/26
  Verifying  : gcc-c++-4.4.7-3.el6.x86_64                                 14/26
  Verifying  : 4:perl-5.10.1-131.el6_4.x86_64                             15/26
  Verifying  : cpp-4.4.7-3.el6.x86_64                                     16/26
  Verifying  : libstdc++-4.4.7-3.el6.x86_64                               17/26
  Verifying  : 4:perl-libs-5.10.1-131.el6_4.x86_64                        18/26
  Verifying  : 1:perl-Module-Pluggable-3.90-131.el6_4.x86_64              19/26
  Verifying  : libgcc-4.4.7-3.el6.x86_64                                  20/26
  Verifying  : 3:perl-version-0.77-131.el6_4.x86_64                       21/26
  Verifying  : libstdc++-devel-4.4.7-3.el6.x86_64                         22/26
  Verifying  : gcc-4.4.7-3.el6.x86_64                                     23/26
  Verifying  : 1:perl-Pod-Escapes-1.04-131.el6_4.x86_64                   24/26
  Verifying  : 1:perl-Pod-Simple-3.13-131.el6_4.x86_64                    25/26
  Verifying  : libgomp-4.4.7-3.el6.x86_64                                 26/26

Updated:
  gcc.x86_64 0:4.4.7-4.el6             perl.x86_64 4:5.10.1-136.el6

Dependency Updated:
  cpp.x86_64 0:4.4.7-4.el6
  gcc-c++.x86_64 0:4.4.7-4.el6
  libgcc.x86_64 0:4.4.7-4.el6
  libgomp.x86_64 0:4.4.7-4.el6
  libstdc++.x86_64 0:4.4.7-4.el6
  libstdc++-devel.x86_64 0:4.4.7-4.el6
  perl-Module-Pluggable.x86_64 1:3.90-136.el6
  perl-Pod-Escapes.x86_64 1:1.04-136.el6
  perl-Pod-Simple.x86_64 1:3.13-136.el6
  perl-libs.x86_64 4:5.10.1-136.el6
  perl-version.x86_64 3:0.77-136.el6

Complete!
Copy iso file /Applications/VirtualBox.app/Contents/MacOS/VBoxGuestAdditions.iso into the box /tmp/VBoxGuestAdditions.iso
Installing Virtualbox Guest Additions 4.3.4 - guest version is 4.2.16
Verifying archive integrity... All good.
Uncompressing VirtualBox 4.3.4 Guest Additions for Linux............
VirtualBox Guest Additions installer
Removing installed version 4.2.16 of VirtualBox Guest Additions...
Copying additional installer modules ...
Installing additional modules ...
Removing existing VirtualBox DKMS kernel modules[  OK  ]
Removing existing VirtualBox non-DKMS kernel modules[  OK  ]
Building the VirtualBox Guest Additions kernel modules[  OK  ]
Doing non-kernel setup of the Guest Additions[  OK  ]
You should restart your guest to make sure the new modules are actually used

Installing the Window System drivers[FAILED]
(Could not find the X.Org or XFree86 Window System.)
An error occurred during installation of VirtualBox Guest Additions 4.3.4. Some functionality may not work as intended.
In most cases it is OK that the "Window System drivers" installation failed.
[default] Mounting shared folders...
[default] -- /vagrant
````

すごいなー
おや？なんかエラーですか？


````
GuestAdditions versions on your host (4.3.4) and guest (4.2.16) do not match.
````
とか

````
Installing Virtualbox Guest Additions 4.3.4 - guest version is 4.2.16
````
とか

↓なので、こちら参考にVagrantFileを編集
http://blog.code-life.net/blog/2013/06/10/the-guest-additions-on-this-vm-do-not-match-the-installed-version-of-virtualbox-on-vagrant/

こちらの記事ではグローバル的なVagrantFileもなんかごニュってますが、とりあえずよくわからんので、このcentos64VMにあるVagrantファイルを編集
以下を追加する

````
# set auto_update to false,  if do NOT want to check the correct additions
# version when booting this machine
config.vbguest.auto_update = true
````

そんで今度こそ起動

```
$ vagrant reload
```
起動できたようです。



<br>

##コマンド
````
vagrant status 	状態確認
vagrant suspend 	スリープ
vagrant resume 	スリープ復帰
vagrant halt 		終了
vagrant up 		起動
vagrant reload 	再起動

vagrant destroy　仮想マシン削除
````
仮想マシンを削除してもVagrantFileがあれば、UP起動できます。

<br>
##仮想マシンへの接続
````
$ vagrant ssh
/Applications/Vagrant/embedded/gems/gems/vagrant-1.4.0/lib/vagrant/util/which.rb:32: warning: Insecure world writable dir /Users/teru1 in PATH, mode 040777
Welcome to your Vagrant-built virtual machine.
[vagrant@localhost ~]$ pwd
/home/vagrant
````

##apacheをインストール
````
sudo yum -y install httpd
sudo chkconfig httpd on
````

##apacheを起動
````
sudo service httpd start
````

##iptablesは一旦停止しておく
```
$ sudo service iptables stop
iptables: Flushing firewall rules:                         [  OK  ]
iptables: Setting chains to policy ACCEPT: filter          [  OK  ]
iptables: Unloading modules:                               [  OK  ]
```

##htmlファイルを作成
/var/www/htmlにファイルを作成

##バーチャルホストを設定
Mac側でVagrantFileを編集
以下部分をコメントはずして

````
config.vm.network :private_network, ip: "192.168.33.10"
````
VagrantFileを編集したら再起動なので

````
vagrant reload
````
だが、
<H1>エラーが出る</H1>↓ので
http://d.hatena.ne.jp/akishin999/20131213/1386929611

これで、起動した。

Macでブラウザから192.168.33.10にアクセス。
OK！

<br>

##普通のSSHでつなげるように
###VagrantFileのあるディレクトリで以下
```
$ ls
total 16
drwxr-xr-x  4 teru1  staff   136 12 13 21:41 ./
drwxr-xr-x  5 teru1  staff   170 12 14 01:09 ../
drwxr-xr-x  3 teru1  staff   102 12 13 20:56 .vagrant/
-rw-r--r--  1 teru1  staff  4845 12 13 21:41 Vagrantfile
$ vagrant ssh-config --host melody
/Applications/Vagrant/embedded/gems/gems/vagrant-1.4.0/lib/vagrant/util/which.rb:32: warning: Insecure world writable dir /Users/teru1 in PATH, mode 040777
Host melody
  HostName 127.0.0.1
  User vagrant
  Port 2222
  UserKnownHostsFile /dev/null
  StrictHostKeyChecking no
  PasswordAuthentication no
  IdentityFile /Users/teru1/.vagrant.d/insecure_private_key
  IdentitiesOnly yes
  LogLevel FATAL
$ vagrant ssh-config --host melody >> ~/.ssh/config
/Applications/Vagrant/embedded/gems/gems/vagrant-1.4.0/lib/vagrant/util/which.rb:32: warning: Insecure world writable dir /Users/teru1 in PATH, mode 040777
$ ssh melody
Last login: Thu Dec 19 13:43:34 2013 from 10.0.2.2
Welcome to your Vagrant-built virtual machine.

```