Vagrant

#Virtualbox インストール,ホストオンリーネットワーク設定
#vagrant インストール#環境パス C:\vagrant\bin 確認

 

============================
vagrant --vesion
vagrant init precise64 http://files.vagrantup.com/precise64.box
vagrant up
vagrant ssh
vagrant destroy

---------------------------
#EC2

/Vagrantfile
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "dummy"
config.vm.provider :aws do |aws, override|
aws.access_key_id = '<your access_key_id>'
aws.secret_access_key = '<your access_secret_key>'
aws.keypair_name = "tky's keys"
aws.region = "ap-northeast-1"
aws.ami = "ami-39b23d38"
end
end
vagrant up --provider=aws
#アクセスキー/シークレットアクセス作成
#EC ssh2キーペア作成
vagrant plugin install vagrant-aws
vagrant box add dummy https://github.com/mickellh/vagrant-aws/raw/master/dummy.box
vagrant init
/Vagrantfile
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "dummy"
config.vm.provider :aws do |aws, override|
aws.access_key_id = '...'
aws.secret_access_key = '...'
aws.keypair_name = "tky's keys"
aws.instance_type = "t1.micro"
aws.region = "ap-northeast-1"
## Amazon Linux AMI 2013.03.1
aws.ami = "ami-39b23d38"
aws.security_groups = [ 'vagrant' ]
aws.tags = { 'Name' => 'vagrant-test' }
override.ssh.username = 'ec2-user'
override.ssh.private_key_path = '~/.ssh/aws-tkyskey.pem'
end
end
vagrant up --provider=aws
vagrant status
vagrant ssh
vagrant ssh-config --host=vagrant-test
vagrant destroy /vagrant halt
vagrant ssh
sudo visudo
/etc/sudoers
Defalts requiretty #コメントアウト
echo "Hello, Vagrant" > hoge.txt
vagrant provision
vagrant ssh -c "cat /vagrant/hoge.txt"

/Vagrantfile
config.vm.provider :aws do |aws, override|
aws.access_key_id = ENV['AWS_ACCESS_KEY_ID']
aws.secret_access_key = ENV['AWS_SECRET_ACCESS_KEY']
...

~/.awsinit
export AMAZON_ACCESS_KEY_ID="..."
export AMAZON_SECRET_ACCES_KEY="..."

sorce ~/.awsinit
##EC2プロビジョニング
...............
packer
---------------------------
---------------------------

mkdir vagrant_book_example
cd vagrant_book_example
vagrant init precise64 http://files.vagrant

/Vagrantfile
Vagrant::Config.run do |config|
config.vm.box = "precise64"
config.vm.share_folder "v-root", "/vagrant", "."
config.vm.provision "shell" do |s|
s.path = "script.sh"
end
end

vagrant status
vagrant ssh
/Vagrantfile
vagrant reload
vagrant ssh
vagrant suspend
vagrant status
vagrant up
vagrant halt
vagrant status
vagrant halt --force
vagrant up
vagrant destroy
vagrant status
vagrant destroy --force
vagrant up

--------------------------
#vagrantfile 詳細
/Vagrant
Vagrant::Config.run do |config|
#V1設定
end
Vagrant::Configure("2") do |config|
#V2設定
end
/Vagrantfile
Vagrant::Config.run do |config|
config.vm.box = "precise64"
config.vm.box_url = "http:fils.vagrantup.com/precise64"
end
/Vagrantfile
Vagrant::Config.run do |config|
#...
config.vm.share_folder "v-root", "/foo","."
end
/Vagrantfile
Vagrant::Config.run do |config|
#...
config.vm.share_folder "data", "/data","./data"
end
/Vagrantfile
Vagrant::Config.run do |config|
#...
config.vm.forward_port 80, 8080
end
--------------------------
プロビジョニング
....
-------------------------------------
---------------------------------------
#Rails vagrant
cd ~/projects/baukis
vagarnt up
vagarnt ssh
echo "HELLO" > /vagrant/test.txt
exit
cat test.txt
rm text.txt

cd ~/projects/baukis
vagarnt ssh
rails new baukis -d mysql --skip-test-unit
----------------------------------------
------------------------------------------
#DevOps vagarnt
vagrant init

/Vagrantfile
#-*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure (2) do |config|
config.vm.box = "centos/7"
config.vm.hostname = "demo"
config.vm.network :private_network, ip: "192.168.33.10"
config.vm.synced_folder ".", "/home/vagrant/sync", disabled: true
end
vagarnt up
vagarnt ssh
uname -n
vagarnt halt
vagarnt destory
/Vagrantfile
#-*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure (2) do |config|
config.vm.box = "centos/7"
config.vm.hostname = "demo"
config.vm.network :private_network, ip: "192.168.33.10"
config.vm.synced_folder ".", "/home/vagrant/sync", disabled: true
config.vm.provision "shell", inline: $script
end
$script = <<SCRIPT
yum -y install epel-release
yum -y install nginx
echo "hello, vagarnt" > /usr/share/nginx/html/index.html/index
SCRIPT
vagarnt provision
curl http://192.168.33.10/
-------------------------------------------
-----------------------------------------
#Chef vagarnt
vagarnt init centos/7
vagarnt up
vagarnt -v
vagrant box opscode-centos-6.5 http://opscode-vm-bento.s3.amazonaws.com/vagrant/virtualbox/opscode-centos-6.5_chef-provisionerless.box
vagarnt init opscode-centos-6.5
vagarnt up
vagarnt ssh
vagarnt halt / vagarnt destory
vagarnt ssh-config --host webdb >> ~/.ssh/config
/Vagrantfile
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "opscode-centos-6.5"
config.vm.network :private_network, ip: "192.168.33.10"
end
vagarnt halt
vagarnt up
------------
/Vagrantfile
# -*- mode: ruby -*-
#vi: set ft=ruby :
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "opscode-centos-6.5"
config.vm.box_url = "http://opscode-vm-bento.s3.amazonaws.com/vagrant/virtualbox/opscode-centos-6.5_chef-provisionerless.box"
#Chef Clientの最新版を利用可能にする
config.omnibus.chef_version = :latest
config.vm.provision :chef_solo do |chef|
#クックブックの配置場所を指定
chef.cookbooks_path = "./cookbooks"
#Attributeの定義
chef.json = {
nginx: {
env: "ruby"
},
mysql: {
server_root_pasword: 'rootpass'
}
}
#適用するクックブックの定義
chef.run_list = %w{
recipe[yum-epal]
recipe[nginx]
recipe[mysql]
recipe[fluentd]
}
end
end
vagarnt plugin install vagrant-omnibus
/vagrantfile
config.omnibus.chef_version = :latest
vagarnt up --provision
vagarnt provision
...