Vagrantで仮想環境を作成

これから勉強するために仮想環境をつくります。
自分のPCでやってもいいのですが、失敗した時のことを考えて、、、

仮想環境を作ってみる

Vagrant と VirtualBox を使って、仮想環境を作ってみます。

Vagrant をインストール

こちらのサイトからdmgファイルをインストール

Download Vagrant – Vagrant

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

1
2
$ vagrant --version
Vagrant 1.7.1

VirtualBox をインストール

こちらのサイトからdmgファイルをインストール

Downloads – Oracle VM VirtualBox

Launcpad に VirtualBox のアイコンがあればOK

仮想マシンを作成

まずはboxを確認

1
2
3
4
$ vagrant box list
centos65 (virtualbox, 0)
chef/centos-6.5 (virtualbox, 1.0.0)
precise32 (virtualbox, 0)

Vagrantfileを作成

1
2
3
4
5
6
7
8
9
$ mkdir -p ./Vagrant/CentOS65
$ cd ./Vagrant/CentOS65
$ vagrant init chef/centos-6.5
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.
$ ls
Vagrantfile

作成されたVagrantfileの中身を確認して、config.vm.box = "chef/centos-6.5"となっていれば大丈夫。

VMを起動する

1
2
3
4
$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'chef/centos-6.5'...
・・・

ネットワーク設定をする

Vagrantfileの下記の記述のコメントアウトを削除

1
# config.vm.network "private_network", ip: "192.168.33.10"

vagrant のリロード

1
2
3
4
$ vagrant reload
==> default: Attempting graceful shutdown of VM...
==> default: Checking if box 'chef/centos-6.5' is up to date...
・・・

これで192.168.33.10 というIPでアクセスできるようになりました

1
2
3
4
$ ping 192.168.33.10
PING 192.168.33.10 (192.168.33.10): 56 data bytes
64 bytes from 192.168.33.10: icmp_seq=0 ttl=64 time=0.585 ms
64 bytes from 192.168.33.10: icmp_seq=1 ttl=64 time=0.583 ms

仮想環境に接続

1
2
3
$ vagrant ssh
Last login: Mon Dec 29 09:03:57 2014 from 10.0.2.2
[vagrant@localhost ~]$

これで、仮想環境の準備はOK!

というわけで、今日はここまで、、、、
Geoな話までいかなかった、、、、