Vagrant Provisioning

  • Setup Scripting = Provisioning
  • 工具:ansible、Puppet、Chef….

設定

  • 使用Vagrantfile進行設定

Sell Provisioning

  • provision-tomcat.sh
#!/bin/bash

apt-get update -y
apt-get upgrade -y
apt-get install -y nano git openjdk-7-jdk openjdk-7-jre-headless

cd /usr/local
wget http://apache.cs.utah.edu/tomcat/tomcat-8.0.30/apache-tomcat-8.0.30.tar.gz
tar -xzvf apache-tomcat-8.0.30.tar.gz
ln -s apache-tomcat-8.0.30 tomcat

cp /vagrant/tomcat8 /etc/init.d/tomcat8  // 事先寫好的Tomcat設定檔
chmod 755 /etc/init.d/tomcat8
update-rc.d tomcat8 defaults
service tomcat8 start
  • Vagrantfile
config.vm.box = "ubuntu/trusty64"
config.vm.hostname = "tomcat8"

config.vm.network "forwarded_port", guest: 8080, host: 8080
config.vm.provision "shell", path: "provision-tomcat.sh"

config.vm.provider "virtualbox" do |vb| 
   vb.name = "TomcatDev"
     vb.memory = "1024"
     vb.cpus = 2  // 超過1顆CPU才設定
end

對應

  • 重啟
vagrant  provision