Download - Vagrant + VirtualBox + Chef を使った環境構築方法について
![Page 1: Vagrant + VirtualBox + Chef を使った環境構築方法について](https://reader034.vdocuments.net/reader034/viewer/2022052310/55615189d8b42adb6b8b52b7/html5/thumbnails/1.jpg)
2013/12/08 福岡西区勉強会
開発環境を楽しく手軽に作ろうVagrant + VirtualBox + Chef を使った環境構築方法について
![Page 2: Vagrant + VirtualBox + Chef を使った環境構築方法について](https://reader034.vdocuments.net/reader034/viewer/2022052310/55615189d8b42adb6b8b52b7/html5/thumbnails/2.jpg)
アジェンダ
✤ Vagrant、VirtualBox、Chefの紹介!
✤ Vagrant + VirtualBox + Chefを使った開発環境構築のデモ
![Page 3: Vagrant + VirtualBox + Chef を使った環境構築方法について](https://reader034.vdocuments.net/reader034/viewer/2022052310/55615189d8b42adb6b8b52b7/html5/thumbnails/3.jpg)
はじめに
![Page 4: Vagrant + VirtualBox + Chef を使った環境構築方法について](https://reader034.vdocuments.net/reader034/viewer/2022052310/55615189d8b42adb6b8b52b7/html5/thumbnails/4.jpg)
自己紹介
名前:木下 真哉 (Shinya Kinoshita) 所属:からくり株式会社 (契約社員)
! 福岡生まれ、福岡育ちの32歳。 アプリ開発、インフラ構築と幅広く対応するマルチなソフトウェアエンジニアとして活動中。 !地元の大学卒業後、6年ほど業務系システムの開発プロジェクトに常駐型派遣エンジニアとして参加 (Java、COBOL) その後、社内SNS国内シェアNo.1と言われているBeat Communication に入社。パッケージソフトの開発や保守を担当。 !東日本大震災がきっかけで福岡に帰還し、派遣社員や業務委託等でさまざまプロジェクトに参加。 !現在は在宅勤務という形で、からくり株式会社 (東京) でiOSアプリやサーバーサイドプログラム (Python)の開発に従事。
!
![Page 5: Vagrant + VirtualBox + Chef を使った環境構築方法について](https://reader034.vdocuments.net/reader034/viewer/2022052310/55615189d8b42adb6b8b52b7/html5/thumbnails/5.jpg)
持ち帰ってほしいこと
✤ Vagrant + VirtualBox + Chef を使えば、今まで面倒だった開発環境の構築が楽になる。!
✤ Vagrant + VirtualBox + Chef を一つの手段として、所属するプロジェクト及び社内で活用することで何か改善されることがあるか。
![Page 6: Vagrant + VirtualBox + Chef を使った環境構築方法について](https://reader034.vdocuments.net/reader034/viewer/2022052310/55615189d8b42adb6b8b52b7/html5/thumbnails/6.jpg)
Vagrant + VirtualBox + Chef の紹介
![Page 7: Vagrant + VirtualBox + Chef を使った環境構築方法について](https://reader034.vdocuments.net/reader034/viewer/2022052310/55615189d8b42adb6b8b52b7/html5/thumbnails/7.jpg)
Vagrant とは
✤ 仮想マシンを簡単に構築・管理し、配布することができるツール。!
✤ VirtualBox、VMWare、AWS といった環境で動かすことができる。!
! *) VMWare 上で動かす場合、有償版を購入しないといけないみたい。!
! *) AWS 上で動かす場合の手順は調査中。!
! *) Vagrant を使用する場合は、VirtualBoxを使用するのが一番。!
✤ 公式サイト:http://www.vagrantup.com
![Page 8: Vagrant + VirtualBox + Chef を使った環境構築方法について](https://reader034.vdocuments.net/reader034/viewer/2022052310/55615189d8b42adb6b8b52b7/html5/thumbnails/8.jpg)
VirtualBox とは
✤ ライセンスフリーで利用可能な仮想化ツール!
✤ Oracleから提供されている。!
✤ 公式サイト:https://www.virtualbox.org
![Page 9: Vagrant + VirtualBox + Chef を使った環境構築方法について](https://reader034.vdocuments.net/reader034/viewer/2022052310/55615189d8b42adb6b8b52b7/html5/thumbnails/9.jpg)
Chef とは
✤ サーバーの設定や更新を自動化するためのツール!
✤ Rubyを使ってサーバーの設定や更新のための手順を書く!
✤ 公式サイト:http://www.opscode.com/chef/
![Page 10: Vagrant + VirtualBox + Chef を使った環境構築方法について](https://reader034.vdocuments.net/reader034/viewer/2022052310/55615189d8b42adb6b8b52b7/html5/thumbnails/10.jpg)
実際に開発環境を作ってみよう
![Page 11: Vagrant + VirtualBox + Chef を使った環境構築方法について](https://reader034.vdocuments.net/reader034/viewer/2022052310/55615189d8b42adb6b8b52b7/html5/thumbnails/11.jpg)
手順
1. Boxを入手する。!
2. Vagrantfileを作成する。!
3. Vagrantfileを修正する。!
4. 仮想マシンを起動する。
![Page 12: Vagrant + VirtualBox + Chef を使った環境構築方法について](https://reader034.vdocuments.net/reader034/viewer/2022052310/55615189d8b42adb6b8b52b7/html5/thumbnails/12.jpg)
Boxとは
✤ Box とは、Vagrant が仮想マシンを作成する際に使用するテンプレートファイル。!
✤ Box はネット上で公開されている。!
! URL:http://www.vagrantbox.es!
✤ Box の作成方法は現在調査中・・・。
![Page 13: Vagrant + VirtualBox + Chef を使った環境構築方法について](https://reader034.vdocuments.net/reader034/viewer/2022052310/55615189d8b42adb6b8b52b7/html5/thumbnails/13.jpg)
Vagrantfile とは
✤ Vagrantが仮想マシンを起動する際に参照する設定ファイル。!
✤ Vagrantfileで仮想マシンのネットワーク構成、メモリ容量etcを指定することができる。
![Page 14: Vagrant + VirtualBox + Chef を使った環境構築方法について](https://reader034.vdocuments.net/reader034/viewer/2022052310/55615189d8b42adb6b8b52b7/html5/thumbnails/14.jpg)
1. Boxを入手する。
✤ ローカル環境上にBoxファイルをインストールする場合、以下のコマンドを実行する。!
! !! コマンド: vagrant add (Box名) (BoxのURL)!
*) Box名は任意!
例: vagrant box add precise32 http://files.vagrantup.com/precise32.box
![Page 15: Vagrant + VirtualBox + Chef を使った環境構築方法について](https://reader034.vdocuments.net/reader034/viewer/2022052310/55615189d8b42adb6b8b52b7/html5/thumbnails/15.jpg)
2. Vagrantfileを作成する。
✤ Vagrant コマンド:「vagrant init」を実行する。!
<実行例1: ローカル環境上にインストールされているBoxを使う場合>!
コマンド: vagrant init (Box名)!
例: vagrant init precise32!
<実行例2: ネットワーク上のBoxを使う場合>!
コマンド: vagrant init (Box名) (BoxのURL)!
例: vagrant init precise32 http://files.vagrantup.com/precise32.box
![Page 16: Vagrant + VirtualBox + Chef を使った環境構築方法について](https://reader034.vdocuments.net/reader034/viewer/2022052310/55615189d8b42adb6b8b52b7/html5/thumbnails/16.jpg)
3. Vagrantfileを修正する。
✤ ネットワークの設定!!
# ホストオンリー接続する場合!config.vm.network :private_network, ip: “192.168.33.10"!!# ブリッジ接続する場合!config.vm.network :public_network
![Page 17: Vagrant + VirtualBox + Chef を使った環境構築方法について](https://reader034.vdocuments.net/reader034/viewer/2022052310/55615189d8b42adb6b8b52b7/html5/thumbnails/17.jpg)
3. Vagrantfileを修正する。
✤ メモリサイズの設定!!
# メモリサイズを1024MB (1GB)に設定!vb.customize ["modifyvm", :id, "--memory", "1024"]
![Page 18: Vagrant + VirtualBox + Chef を使った環境構築方法について](https://reader034.vdocuments.net/reader034/viewer/2022052310/55615189d8b42adb6b8b52b7/html5/thumbnails/18.jpg)
3. Vagrantfileを修正する。
✤ 仮想マシン起動時にChefを実行する際の設定!!
# 仮想マシン起動時に実行するChefの設定!config.vm.provision :chef_solo do |chef|! chef.cookbooks_path = "./chef-repo/site-cookbooks"! chef.roles_path = "./chef-repo/roles"! chef.data_bags_path = "./chef-repo/data_bags"! chef.add_recipe "lamp"! chef.json = { }!end!
![Page 19: Vagrant + VirtualBox + Chef を使った環境構築方法について](https://reader034.vdocuments.net/reader034/viewer/2022052310/55615189d8b42adb6b8b52b7/html5/thumbnails/19.jpg)
4. 仮想マシンを起動する
✤ Vagrant コマンド:「vagrant up」を実行する。!!! *) 仮想マシン起動後、「vagrant ssh」コマンドでSSH接続をすること!! ができる。!
![Page 20: Vagrant + VirtualBox + Chef を使った環境構築方法について](https://reader034.vdocuments.net/reader034/viewer/2022052310/55615189d8b42adb6b8b52b7/html5/thumbnails/20.jpg)
まとめ
✤ Vagrant を使うことで、必要なときに素早く仮想マシンを入手することができる。(簡単に仮想マシンを捨てることもできる。)!
✤ Chef を使うことで、仮想マシン起動時にサーバーの設定を自動化することができる。!
→ 時間の短縮および自動化により、正確かつ迅速な開発環境の構築が実現する!
![Page 21: Vagrant + VirtualBox + Chef を使った環境構築方法について](https://reader034.vdocuments.net/reader034/viewer/2022052310/55615189d8b42adb6b8b52b7/html5/thumbnails/21.jpg)
最後に
✤ 今回の発表に関する内容はQiita (キータ)にも記載しています。是非、チェックしてみてください。!
! URL: http://qiita.com/skinoshita/items/57ac059ff8b1008f5e1d!
✤ Vagrantの動作を確認できるように、Bitbucketにサンプルソースを置いています。興味のある方は使ってみてください。!
! URL: https://bitbucket.org/skinoshita/vagrant-samplebox!
✤ 次回、発表の機会があれば、Chefについての発表をする予定です。
![Page 22: Vagrant + VirtualBox + Chef を使った環境構築方法について](https://reader034.vdocuments.net/reader034/viewer/2022052310/55615189d8b42adb6b8b52b7/html5/thumbnails/22.jpg)
ご清聴ありがとうございました。