Más contenido relacionado La actualidad más candente (20) Similar a Vagrant体験入門 (20) Más de Masashi Shinbara (13) Vagrant体験入門3. (c) 2014 Masashi Shinbara @shin1x1
Vagrantで作るPHP開発環境
http://www.slideshare.net/shin1x1/xampp-mamp-vagrant-php
4. (c) 2014 Masashi Shinbara @shin1x1
Vagrantで作るPHP開発環境[実践編]
http://www.slideshare.net/shin1x1/vagrant-php
5. (c) 2014 Masashi Shinbara @shin1x1
VagrantX
http://shin1x1.github.io/vagrantx/
8. エンジニアSさん
(c) 2014 Masashi Shinbara @shin1x1
1162 <VirtualHost *:80>!
1163 ServerName candycane.local!
1164 DocumentRoot "/Users/shin/sandbox/demo/candycane/app/webroot"!
1165 </VirtualHost>!
1166 !
1167 <VirtualHost *:80>!
1168 ServerName demo.local!
1169 DocumentRoot "/Users/shin/sandbox/demo/20140601_phpcon"!
1170 php_value vld.active 1!
1171 </VirtualHost>!
1172 !
1173 <VirtualHost *:80>!
1174 ServerName evememo.local!
1175 DocumentRoot "/Users/shin/work/1x1/evememo/app/webroot"!
1176 </VirtualHost>!
1177 !
1178 <VirtualHost *:80>!
1179 ServerName kusaon.local!
1180 DocumentRoot "/Users/shin/work/kusaon/app/webroot"!
1181 </VirtualHost>!
9. エンジニアSさん
(c) 2014 Masashi Shinbara @shin1x1
1162 <VirtualHost *:80>!
1163 ServerName candycane.local!
1164 DocumentRoot "/Users/shin/sandbox/demo/candycane/app/webroot"!
1165 </VirtualHost>!
1166 !
1167 <VirtualHost *:80>!
1168 ServerName demo.local!
1169 DocumentRoot "/Users/shin/sandbox/demo/20140601_phpcon"!
1170 php_value vld.active 1!
1171 </VirtualHost>!
1172 !
1173 <VirtualHost *:80>!
1174 ServerName evememo.local!
1175 DocumentRoot "/Users/shin/work/1x1/evememo/app/webroot"!
1176 </VirtualHost>!
1177 !
1178 <VirtualHost *:80>!
1179 ServerName kusaon.local!
1180 DocumentRoot "/Users/shin/work/kusaon/app/webroot"!
1181 </VirtualHost>!
溢れる
VirtualHost
14. (c) 2014 Masashi Shinbara @shin1x1
# tar xvzf postgresql-8.3.9.tar.gz!
# mv postgresql-8.3.9 /usr/local/src!
# cd /usr/local/src/postgresql-8.3.9!
# ./congure {prex=/usr/local/pgsql!
# gmake && gmake install!
!/usr/local/pgsql/lib/pgxs/cong/install-sh!
/bin/sh ../cong/install-sh -c -m 755 ./mkinstalldirs!
/usr/local/pgsql/lib/pgxs/cong/mkinstalldirs!
!gmake[1]: Leaving directory `/usr/local/src/postgresql-8.3.9/cong'!
PostgreSQL installation complete.!
!# .bash prole!
# Get the aliases and functions!
if [ -f ~/.bashrc ]; then!
.!
~/.bashrc!
!# User specic environment and startup programs!
PATH=$PATH:$HOME/bin!
PATH=$PATH:/usr/java/jdk1.5.0 21/bin!
export PATH!
unset USERNAME!
export JAVA HOME=/usr/java/jdk1.5.0 21/!
export CATALINA HOME=/usr/local/tomcat!
export CLASSPATH=$CLASSPATH:$CATALINA HOME/common/lib!
export CATALINA OPTS="-server -Xms512m -Xmx512m -Xss512k -XX:PermSize=64m -XX:MaxPermSize=64m"!
!# tar xvzf postgresql-8.3.9.tar.gz!
# mv postgresql-8.3.9 /usr/local/src!
# cd /usr/local/src/postgresql-8.3.9!
# ./congure {prex=/usr/local/pgsql!
# gmake && gmake install!
!/usr/local/pgsql/lib/pgxs/cong/install-sh!
/bin/sh ../cong/install-sh -c -m 755 ./mkinstalldirs!
/usr/local/pgsql/lib/pgxs/cong/mkinstalldirs!
!gmake[1]: Leaving directory `/usr/local/src/postgresql-8.3.9/cong'!
PostgreSQL installation complete.!
!# .bash prole!
# Get the aliases and functions!
if [ -f ~/.bashrc ]; then!
.!
~/.bashrc!
!# User specic environment and startup programs!
PATH=$PATH:$HOME/bin!
PATH=$PATH:/usr/java/jdk1.5.0 21/bin!
export PATH!
unset USERNAME!
export JAVA HOME=/usr/java/jdk1.5.0 21/!
export CATALINA HOME=/usr/local/tomcat!
export CLASSPATH=$CLASSPATH:$CATALINA HOME/common/lib!
export CATALINA OPTS="-server -Xms512m -Xmx512m -Xss512k -XX:PermSize=64m -XX:MaxPermSize=64m"!
とある開発チーム新人Cさん
15. (c) 2014 Masashi Shinbara @shin1x1
# tar xvzf postgresql-8.3.9.tar.gz!
# mv postgresql-8.3.9 /usr/local/src!
# cd /usr/local/src/postgresql-8.3.9!
# ./congure {prex=/usr/local/pgsql!
# gmake && gmake install!
!
/usr/local/pgsql/lib/pgxs/cong/install-sh!
/bin/sh ../cong/install-sh -c -m 755 ./mkinstalldirs!
/usr/local/pgsql/lib/pgxs/cong/mkinstalldirs!
!
gmake[1]: Leaving directory `/usr/local/src/postgresql-8.3.9/cong'!
PostgreSQL installation complete.!
!
# .bash prole!
# Get the aliases and functions!
if [ -f ~/.bashrc ]; then!
.!
~/.bashrc!
!
# User specic environment and startup programs!
PATH=$PATH:$HOME/bin!
PATH=$PATH:/usr/java/jdk1.5.0 21/bin!
export PATH!
unset USERNAME!
export JAVA HOME=/usr/java/jdk1.5.0 21/!
export CATALINA HOME=/usr/local/tomcat!
export CLASSPATH=$CLASSPATH:$CATALINA HOME/common/lib!
export CATALINA OPTS="-server -Xms512m -Xmx512m -Xss512k -XX:PermSize=64m -XX:MaxPermSize=64m"!
とある開発チーム新人Cさん
これやるの・・・
16. (c) 2014 Masashi Shinbara @shin1x1
# tar xvzf postgresql-8.3.9.tar.gz!
# mv postgresql-8.3.9 /usr/local/src!
# cd /usr/local/src/postgresql-8.3.9!
# ./congure {prex=/usr/local/pgsql!
# gmake && gmake install!
!
/usr/local/pgsql/lib/pgxs/cong/install-sh!
/bin/sh ../cong/install-sh -c -m 755 ./mkinstalldirs!
/usr/local/pgsql/lib/pgxs/cong/mkinstalldirs!
!
gmake[1]: Leaving directory `/usr/local/src/postgresql-8.3.9/cong'!
PostgreSQL installation complete.!
!
# .bash prole!
# Get the aliases and functions!
if [ -f ~/.bashrc ]; then!
.!
~/.bashrc!
!
# User specic environment and startup programs!
PATH=$PATH:$HOME/bin!
PATH=$PATH:/usr/java/jdk1.5.0 21/bin!
export PATH!
unset USERNAME!
export JAVA HOME=/usr/java/jdk1.5.0 21/!
export CATALINA HOME=/usr/local/tomcat!
export CLASSPATH=$CLASSPATH:$CATALINA HOME/common/lib!
export CATALINA OPTS="-server -Xms512m -Xmx512m -Xss512k -XX:PermSize=64m -XX:MaxPermSize=64m"!
とある開発チーム新人Cさん
しかも動かない!
28. Vagrant
(c) 2014 Masashi Shinbara @shin1x1
• HashiCorp が開発した OSS(MIT)
• Ruby
• 仮想環境の構築、プロビジョニングを
実行するコマンドラインツール
• 構築手順をコードで定義(Vagrantfile)
29. (c) 2014 Masashi Shinbara @shin1x1
Vagrant
仮想環境
仮想マシン構築
Vagrant
CentOS, Ubuntu,
FreeBSD, etc
30. (c) 2014 Masashi Shinbara @shin1x1
仮想環境
仮想マシン構築
Vagrant
プロビジョニング
Vagrant
Apache, PHP,
MySQL, Redis, etc
31. (c) 2014 Masashi Shinbara @shin1x1
仮想環境
仮想マシン構築
Vagrant
プロビジョニング
Vagrant
$ vagrant up
32. Vagrant ワークフロー
(c) 2014 Masashi Shinbara @shin1x1
$ git clone REPO/project!
$ cd project!
$ vagrant up
• 環境構築はこれだけ
• こうなるように構成しておく!
33. vagrant 主なコマンド
(c) 2014 Masashi Shinbara @shin1x1
• 仮想サーバ起動
$ vagrant up
• 仮想サーバへ SSH ログイン
$ vagrant ssh
• 仮想サーバ停止
$ vagrant halt
• 仮想サーバ停止+破棄
$ vagrant destroy
36. Box
(c) 2014 Masashi Shinbara @shin1x1
• 仮想マシンイメージ
• CentOS, Ubuntu, FreeBSD, OSX, etc
• Vagrant Cloud
• Bento - Chef社が作成したBox
https://github.com/opscode/bento
https://vagrantcloud.com/
37. Box
(c) 2014 Masashi Shinbara @shin1x1
• 仮想マシンイメージ
• CentOS, Ubuntu, FreeBSD, OSX, etc
• Vagrant Cloud
• Bento - Chef社が作成したBox
https://github.com/opscode/bento
https://vagrantcloud.com/
!
ハンズオンでは、
Bento の CentOS 6.5
を使います。
39. Provisioner
(c) 2014 Masashi Shinbara @shin1x1
If you've never used a configuration
management system before,
it is recommended you start with
basic shell scripts for provisioning.
http://docs.vagrantup.com/v2/provisioning/index.html
40. Synced Folder
(c) 2014 Masashi Shinbara @shin1x1
•ホストPCのディレクトリと
仮想サーバのディレクトリを同期
•開発はホストPCで、
実行は仮想サーバで
•PhpStormやEclipseで開発可能
41. (c) 2014 Masashi Shinbara @shin1x1
$ ls .!
Vagrantfile
$ ls /vagrant!
Vagrantfile
ホストPC
仮想マシン
Synced Folder
42. Synced Folder
(c) 2014 Masashi Shinbara @shin1x1
• Shared Folder(デフォルト)
• NFS(ホストがNFSサーバになる)
• Rsync(自動でrsync実行)
44. Vagrantfile
(c) 2014 Masashi Shinbara @shin1x1
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|!
config.vm.box = "opscode-centos65"!
config.vm.network “private_network", ip: "192.168.33.10"!
!
config.vm.provision "shell", inline: <<-EOT!
yum -y install httpd!
cp -a /vagrant/httpd.conf /etc/httpd/conf/!
/sbin/service httpd restart!
/sbin/chkconfig httpd on!
EOT!
end
47. (c) 2014 Masashi Shinbara @shin1x1
流れ
1. USBメモリから必要なファイルコピー
2. Qiita に書いた手順でハンズオン
3. 上手く動いたら tweet (#DevKan)
48. (c) 2014 Masashi Shinbara @shin1x1
手順資料
#DevKan
http://qiita.com/shin1x1/items/
3288d9de7f04192b6ad8
50. Git で管理
(c) 2014 Masashi Shinbara @shin1x1
• Vagrantfile とプロビジョニング
ファイルをリポジトリへ
• .vagrant/ は .gitignore
• ソースコードリポジトリに同梱
51. チームで共有
(c) 2014 Masashi Shinbara @shin1x1
• 環境を揃える
VirtualBox
private ip
shared_folder
• Box は、必要最低限な構成
(Bento)
52. Sahara Plugin
(c) 2014 Masashi Shinbara @shin1x1
• Vagrant Plugin
https://github.com/jedi4ever/sahara
• 仮想サーバの状態を DB の
ROLLBACK のように戻せる
54. Sahara Plugin
(c) 2014 Masashi Shinbara @shin1x1
$ vagrant sandbox on
• sandbox モード開始 = BEGIN;
$ vagrant sandbox rollback
• 元に戻す = ROLLBACK;
$ vagrant sandbox commit
• 変更確定 = COMMIT;
$ vagrant sandbox off
• sandbox モード終了