Webサーバを作る [Chef]
Webサーバとして、hoge202(192.168.56.202)を追加します。このとき、hostnameが名前解決できるようにしておきます。(hostsファイルに設定しておく)
まず、vagrantfileを複数のGuestOSに対応するように変更する必要があります。以下のようにvagrantfileを変更します。
【vagrantfile】
vagrant upコマンドで、WebサーバのGuetsOSを起動します。
db用とWeb用の2台のGuestOSを起動するには、これまでと同じく以下のコマンドを使用します。
まず、vagrantfileを複数のGuestOSに対応するように変更する必要があります。以下のようにvagrantfileを変更します。
【vagrantfile】
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
# webという仮想サーバを定義
config.vm.define :web do |web|
web.vm.box = "centos64-ja"
web.vm.network :private_network, ip:"192.168.56.202"
end
# dbという仮想サーバを定義
config.vm.define :db do |db|
db.vm.box = "centos64-ja"
db.vm.network :private_network, ip:"192.168.56.201"
end
config.vm.provider :virtualbox do |vb|
vb.gui = false
end
# vagrant up のときに bootstrap.sh というスクリプトを実行する
config.vm.provision :shell, :path => "bootstrap.sh"
config.vm.provision :chef_solo do |chef|
chef.cookbooks_path = "./chef-repo/site-cookbooks","./chef-repo/cookbooks"
chef.http_proxy = "http://proxy.xxxxxx.co.jp:8080/"
chef.https_proxy = "http://proxy.xxxxxx.co.jp:8080/"
chef.run_list = [
"recipe[rsync]"
]
end
end
複数のvagrantノードにアクセスするためには、~/.ssh/configを修正する必要があります。Host hoge201
HostName 192.168.56.201
User vagrant
Port 22
UserKnownHostsFile /dev/null
StrictHostKeyChecking no
PasswordAuthentication no
IdentityFile C:/Users/hoge/.vagrant.d/insecure_private_key
IdentitiesOnly yes
LogLevel FATAL
Host hoge202
HostName 192.168.56.202
User vagrant
Port 22
UserKnownHostsFile /dev/null
StrictHostKeyChecking no
PasswordAuthentication no
IdentityFile C:/Users/hoge/.vagrant.d/insecure_private_key
IdentitiesOnly yes
LogLevel FATAL
上記で、knife soloした場合のサーバを区別するようになります。vagrant upコマンドで、WebサーバのGuetsOSを起動します。
C:\Users\hoge\chef-repo> vagrant up web
web用のVirtualBoxのGuestOSが起動します。db用とWeb用の2台のGuestOSを起動するには、これまでと同じく以下のコマンドを使用します。
C:\Users\hoge\chef-repo> vagrant up