Vagrant Boxをダウンロードしてとりあえず仮想マシンを起動まで!
前回、 Vagrant,Chef,knife-soloがインストール出来ました。
VagrantのBoxをダウンロード
VagrantのBoxが公開されているサイトからダウンロードしてくるBoxを決める。
A list of base boxes for Vagrant - Vagrantbox.es
で見てみると色々ありますが、VirtualBoxを使って、
CentOS64ビットでということに
にしたいので、
CentOS 6.4 x86_64 Minimal (VirtualBox Guest Additions 4.2.16, Chef 11.6.0, Puppet 3.2.3)
というものに決めて、そのURLをコピーしてくる。
ターミナルでVagarantBoxのダウンロード。
これがなぜか2時間くらいかかったよ。
長いなー。俺の家がわるいのかな。。
$ vagrant box add centos64 http://developer.nrel.gov/downloads/vagrant-boxes/CentOS-6.4-x86_64-v20130731.box Downloading or copying the box... Extracting box...te: 24649/s, Estimated time remaining: --:--:--) Successfully added box 'centos64' with provider 'virtualbox'! $ vagrant box list centos64 (virtualbox) $ ls ~/.vagrant.d/boxes centos64
box add
で追加したBoxは、リスト表示させることもできますが、
~/.vagrant.d/boxes
にダウンロードされるので
ここを見ると物理ファイルがあります。
Vagrant初期化
仮想マシンを配置するディレクトリを作成して、Vagrantを初期化。
$ cd ~ $ mkdir VagrantVM/centos01 $ cd VagrantVM/centos01 $ vagrant init centos01 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.
Vagrantfileが出来上がる。 Vagrantfileには仮想マシンの起動条件が書かれています。
仮想マシン起動!!
起動は1分くらいで完了しました!!!
$ vagrant up 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] Creating shared folders metadata... [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! [default] The guest additions on this VM do not match the installed version of VirtualBox! In most cases this is fine, but in rare cases it can cause things such as shared folders to not work properly. If you see shared folder errors, please update the guest additions within the virtual machine and reload your VM. Guest Additions Version: 4.2.16 VirtualBox Version: 4.3 [default] Configuring and enabling network interfaces... [default] Mounting shared folders... [default] -- /vagrant
これで完了です。
仮想マシンに接続
Vagrant流のSSHがあるので、これを使えば、仮想マシンにログインできます。
$ vagrant ssh Welcome to your Vagrant-built virtual machine. [vagrant@localhost ~]$ [vagrant@localhost ~]$ pwd /home/vagrant
できました
ステータスの確認
仮想マシンが動いているか確認できます。
$ vagrant status Current machine states: default running (virtualbox) The VM is running. To stop this VM, you can run `vagrant halt` to shut it down forcefully, or you can run `vagrant suspend` to simply suspend the virtual machine. In either case, to restart it again, simply run `vagrant up`.
起動中は、VirtualBoxは起動中になってます。
メモ 仮想マシンの停止、削除
$ vagrant suspend ←停止 $ vagrant resume ←再開 $ vagrant destroy ←削除
仮想マシンの容量について
ここまできて気になるのは、 仮想マシンが食っているディスク容量です。 うちのMacbookAirは、いつもディスクが少なくて。。。
Vagrantのテンプレートとなるファイル(~/.vagrant.d/boxes
の中にあるイメージファイル)
は、493MBでした。
出来上がった仮想マシンのイメージは、
1.6GB
くらいでした。
もろもろインストールするので、もっと容量は必要になりますが、
10GB必要とかそういうのではないので、
エコだわ。