vagrant
vagrantとは
仮想マシンを動かすラッパーツール
仮想マシンは選択可能
- VirtualBox
- VMware
- Amazon EC2
用語
プロバイダ
- 仮想環境のこと、VirtualBoxなど
Vagrantfile
- 仮想マシンの構成を記述する
- Rubyベース
- 基本的に、本ファイルがあればどこでも同じ環境を再現できる
用語
プロビジョニング
- vagrant upをした後に実行される一連の処理のこと
- シェルスクリプト、Chef(chef-solo, chef-client)、Puppetなどが使えます
Boxファイル
- 仮想マシン起動の際にベースとなるテンプレートファイル
- ISOファイルではありません
- 仮想環境別に必要、通常はOSイメージから作成する
- Vagrant利用の上で最低限必要な設定(ユーザの作成、sshdの起動、プロビジョニング
ツールのインストール)のみを行っておく
vagrant up
1. 必要なツールをインストールする
https://www.vagrantup.com/
https://www.virtualbox.org/
2. vagrant box を取得する
http://www.vagrantbox.es/
vagrant box add [url]
3. 仮想マシンの初期化
vagrant init [box-name]
4. 仮想マシンの立ち上げ
vagrant up
vagrant file
vagrant init
Vagrant.configure(2) do |config|
config.vm.box = "base"
# config.vm.box_check_update = false
# Create a forwarded port mapping
# config.vm.network "forwarded_port", guest: 80, host: 8080
# Create a private network
# config.vm.network "private_network", ip: "192.168.33.10"
# Create a public network, which generally matched to bridged network.
# config.vm.network "public_network"
# Share an additional folder to the guest VM.
# config.vm.synced_folder "../data", "/vagrant_data"
# config.vm.provider "virtualbox" do |vb|
# # Display the VirtualBox GUI when booting the machine
# vb.gui = true
# # Customize the amount of memory on the VM:
# vb.memory = "1024"
# end
# config.vm.provision "shell", inline: <<-SHELL
# sudo apt-get update
# sudo apt-get install -y apache2
# SHELL
end
vagrant file
network
Vagrant.configure(2) do |config|
config.vm.box = "base"
# config.vm.box_check_update = false
# Create a forwarded port mapping
# config.vm.network "forwarded_port", guest: 80, host: 8080
# Create a private network
# config.vm.network "private_network", ip: "192.168.33.10"
# Create a public network, which generally matched to bridged network.
# config.vm.network "public_network"
# Share an additional folder to the guest VM.
# config.vm.synced_folder "../data", "/vagrant_data"
# config.vm.provider "virtualbox" do |vb|
# # Display the VirtualBox GUI when booting the machine
# vb.gui = true
# # Customize the amount of memory on the VM:
# vb.memory = "1024"
# end
# config.vm.provision "shell", inline: <<-SHELL
# sudo apt-get update
# sudo apt-get install -y apache2
# SHELL
end
vagrant file
provisioning
Vagrant.configure(2) do |config|
config.vm.box = "base"
# config.vm.box_check_update = false
# Create a forwarded port mapping
# config.vm.network "forwarded_port", guest: 80, host: 8080
# Create a private network
# config.vm.network "private_network", ip: "192.168.33.10"
# Create a public network, which generally matched to bridged network.
# config.vm.network "public_network"
# Share an additional folder to the guest VM.
# config.vm.synced_folder "../data", "/vagrant_data"
# config.vm.provider "virtualbox" do |vb|
# # Display the VirtualBox GUI when booting the machine
# vb.gui = true
# # Customize the amount of memory on the VM:
# vb.memory = "1024"
# end
# config.vm.provision "shell", inline: <<-SHELL
# sudo apt-get update
# sudo apt-get install -y apache2
# SHELL
end
vagrant コマンド
vagrant box add [box-name] [box-url]
vagrant box list
Vagrant box remove [box-name]
vagrant up 立ち上げ
vagrant halt 停止、シャットダウン
vagrant suspend 中断
vagrant resume 復帰
vagrant destroy 仮想マシン削除(Boxの削除ではない)
vagrant コマンド
vagrant reload 設定変更(vagrant file)を反映する、ネットワークの構成変更等
vagarnt provision プロビジョンを実行する(vagrant upした後でも可能)
共有フォルダ
デフォルトで 以下は共有フォルダになっています
- host OS の vagrant fileを置いてあるフォルダ
- guest os の /vagrant
※virtualbox guest additions
共有フォルダ
config.vm.synced_folder “host_path”, “guest_path”, type: “nfs”
type
- virtualbox(Windows/Mac/Linux)
- NFS(Mac/Linux)
- rsync(Windows/Mac/Linux)
- SMB(Windows)
共有フォルダ
config.vm.synced_folder “host_path”, “guest_path”, type: “nfs”
type
- virtualbox(Windows/Mac/Linux) 遅い
- NFS(Mac/Linux) それなりに高速
- rsync(Windows/Mac/Linux) ホスト OS 側から仮想環境への一方向だけの同期
- SMB(Windows)
ss-vagrant
https://github.com/shirasagi/ss-vagrant
VirtualBox + CentOS + Shirasagi
- 自治体サンプル
- 企業サンプル
ss-vagrant
Vagrant.configure(2) do |config|
config.vm.box = "ss-vagrant-v1.2.0"
config.vm.box_url = https://github.com/shirasagi/ss-vagrant/releases/download/v1.2.0/ss-vagrant-virtualbox-
x86_64.box
config.vm.network :forwarded_port, guest: 3000, host: 3000
config.vm.network "private_network", ip: "192.168.33.10“
config.vm.provider :virtualbox do |vb|
# IPv6 と DNS でのネットワーク遅延対策で追記
vb.customize ["modifyvm", :id, "--natdnsproxy1", "off"]
vb.customize ["modifyvm", :id, "--natdnshostresolver1", "off"]
end
end
windowsでの簡単な立ち上げ方(オフライン)
1. VirtualBoxをインストール
2. vagrantをインストール
3. sshクライアントをインストール
4. VagrantFile と ss-vagrant-virtualbox-x86_64.box を用意
5. フォルダー C:vagrant を作成します
6. VagrantFile と ss-vagrant-virtualbox-x86_64.box を作成したフォルダーにコピーします
7. コマンドプロンプトを立ち上げて以下のコマンドを実行します
> cd C:vagrant
> vagrant box add ss ss-vagrant-virtualbox-x86_64.box
> vagrant up
windowsでの簡単な立ち上げ方(オフライン)
8. ssh で仮想環境にログイン
9. シラサギを起動
$ cd $HOME/shirasagi
$ bundle exec rake unicorn:start
10. ブラウザから確認
自治体サンプル http://localhost:3000/
企業サンプル http://192.168.33.10:3000/
管理画面 http://localhost:3000/.mypage
Vagrant Box build
仮想環境上で vagrant package
packer を使う
- https://www.packer.io/downloads.html
- template.jsonを元にBoxを作成
packer build [template.json]
- centos用テンプレート: https://github.com/boxcutter/centos
Vagrant plugin
vagrant plugin install [plugin-name]
sahara
- サンドボックスモードを有効にするプラグイン
- ロールバック機能で実行前の状態に戻すことができます
vagrant-hostmanager
- HOST名の書き換え(host OS含む)

More Related Content

PDF
ヤギにサーバーを管理してもらう話
PDF
サーバ構築実践入門
PDF
BHyVeってなんや
PPTX
Packerで自動化
PPTX
Ansible ではじめるインフラのコード化入門
ODP
Bhyve code reading
PDF
BHyVe: The BSD Hypervisor
PDF
Vagrant intro
ヤギにサーバーを管理してもらう話
サーバ構築実践入門
BHyVeってなんや
Packerで自動化
Ansible ではじめるインフラのコード化入門
Bhyve code reading
BHyVe: The BSD Hypervisor
Vagrant intro

What's hot (20)

KEY
Lxc on cloud
PDF
WSL2+docker+JupyterとVS Codeリモート環境の構築
PDF
openSUSEで最強仮想環境をつくろう - ゲーミングから仮想通貨まで - OSC名古屋2017セミナー資料
PPTX
PowerShell de Azure
PDF
2014/11/08 第3回 一撃サーバー構築シェルスクリプト勉強会(懇親会もあるよ!) 発表資料
PDF
Wocker 秒速で WordPress 開発環境を構築する
PDF
XenServerとZFSストレージでサーバ仮想化 - OSC2011 Tokyo/Spring 自宅SAN友の会(後半)
PDF
第1回 一撃サーバー構築シェルスクリプト勉強会
PDF
Puppet on AWS
PDF
Docker+CoreOS+GCEで自動スケール分散レイトレ
PPTX
Casperjsのインストール
PDF
UEFI時代のブートローダ
KEY
軽快なPlan 9 Update - Illumos KVM上陸 -
PDF
Ansible 2.0を使って組む kubernetesクラスタ vol.1
PDF
ChefとPuppetの比較
PPTX
FreeBSD VPSでLive Migration
PDF
こんてなぐらし!〜FreeBSD VPSでライブマイグレーション〜
PDF
Okinawa Open Days 2015 Handson - Ansible
PDF
COMSTARでiSCSI - OpenSolaris勉強会 2011.08
PPTX
AWSのRedHatにMySQL最速インストール
Lxc on cloud
WSL2+docker+JupyterとVS Codeリモート環境の構築
openSUSEで最強仮想環境をつくろう - ゲーミングから仮想通貨まで - OSC名古屋2017セミナー資料
PowerShell de Azure
2014/11/08 第3回 一撃サーバー構築シェルスクリプト勉強会(懇親会もあるよ!) 発表資料
Wocker 秒速で WordPress 開発環境を構築する
XenServerとZFSストレージでサーバ仮想化 - OSC2011 Tokyo/Spring 自宅SAN友の会(後半)
第1回 一撃サーバー構築シェルスクリプト勉強会
Puppet on AWS
Docker+CoreOS+GCEで自動スケール分散レイトレ
Casperjsのインストール
UEFI時代のブートローダ
軽快なPlan 9 Update - Illumos KVM上陸 -
Ansible 2.0を使って組む kubernetesクラスタ vol.1
ChefとPuppetの比較
FreeBSD VPSでLive Migration
こんてなぐらし!〜FreeBSD VPSでライブマイグレーション〜
Okinawa Open Days 2015 Handson - Ansible
COMSTARでiSCSI - OpenSolaris勉強会 2011.08
AWSのRedHatにMySQL最速インストール
Ad

Similar to 勉強会0614 vagrant (20)

PDF
Hadoop on LXC
ODP
Docker on Vagrant
PDF
hbstudy37 doc
PDF
ソフトウェア工学2023 06 コンテナ仮想化
PDF
Dockerの導入
PDF
Hbstudy41 auto scaling
PDF
Wakame Project - 自作クラウド研究会
PDF
CloudFoundry 2 on Apache CloudStack 4.2.1
PDF
Dockerでらくらく開発・運用を体感しよう
PPTX
ラズパイ2で動く Docker PaaSを作ってみたよ
PDF
Vagrant+Chef
PDF
Docker超入門
PPTX
Dockerでlamp環境を作って見る
PDF
もう XAMPP / MAMP はいらない!
Vagrant で作る PHP 開発環境
PDF
クラウド環境向けZabbixカスタマイズ紹介(第5回Zabbix勉強会)
PPTX
ネットワークエンジニアのための Puppet / Chef
PDF
Vagrant on SoftLayer
PDF
社内勉強会資料(Varnish Module)
PDF
Docker講習会資料
PPTX
ラズパイ2で動く Docker PaaS
Hadoop on LXC
Docker on Vagrant
hbstudy37 doc
ソフトウェア工学2023 06 コンテナ仮想化
Dockerの導入
Hbstudy41 auto scaling
Wakame Project - 自作クラウド研究会
CloudFoundry 2 on Apache CloudStack 4.2.1
Dockerでらくらく開発・運用を体感しよう
ラズパイ2で動く Docker PaaSを作ってみたよ
Vagrant+Chef
Docker超入門
Dockerでlamp環境を作って見る
もう XAMPP / MAMP はいらない!
Vagrant で作る PHP 開発環境
クラウド環境向けZabbixカスタマイズ紹介(第5回Zabbix勉強会)
ネットワークエンジニアのための Puppet / Chef
Vagrant on SoftLayer
社内勉強会資料(Varnish Module)
Docker講習会資料
ラズパイ2で動く Docker PaaS
Ad

More from Yu Ito (8)

PPTX
Kof2017 シラサギ導入
PPTX
ウェブチップス勉強会 Action cable
PPTX
シラサギハンズオン 2016 05-26
PPTX
シラサギハンズオン 1015 1016
PPTX
徳島OSS勉強会第四回 シラサギハンズオン 0925
PPTX
シラサギハンズオン 東京
PPTX
シラサギハンズオン 大阪
PDF
シラサギハンズオン 松江
Kof2017 シラサギ導入
ウェブチップス勉強会 Action cable
シラサギハンズオン 2016 05-26
シラサギハンズオン 1015 1016
徳島OSS勉強会第四回 シラサギハンズオン 0925
シラサギハンズオン 東京
シラサギハンズオン 大阪
シラサギハンズオン 松江

勉強会0614 vagrant

  • 3. 用語 プロバイダ - 仮想環境のこと、VirtualBoxなど Vagrantfile - 仮想マシンの構成を記述する - Rubyベース - 基本的に、本ファイルがあればどこでも同じ環境を再現できる
  • 4. 用語 プロビジョニング - vagrant upをした後に実行される一連の処理のこと - シェルスクリプト、Chef(chef-solo, chef-client)、Puppetなどが使えます Boxファイル - 仮想マシン起動の際にベースとなるテンプレートファイル - ISOファイルではありません - 仮想環境別に必要、通常はOSイメージから作成する - Vagrant利用の上で最低限必要な設定(ユーザの作成、sshdの起動、プロビジョニング ツールのインストール)のみを行っておく
  • 5. vagrant up 1. 必要なツールをインストールする https://www.vagrantup.com/ https://www.virtualbox.org/ 2. vagrant box を取得する http://www.vagrantbox.es/ vagrant box add [url] 3. 仮想マシンの初期化 vagrant init [box-name] 4. 仮想マシンの立ち上げ vagrant up
  • 6. vagrant file vagrant init Vagrant.configure(2) do |config| config.vm.box = "base" # config.vm.box_check_update = false # Create a forwarded port mapping # config.vm.network "forwarded_port", guest: 80, host: 8080 # Create a private network # config.vm.network "private_network", ip: "192.168.33.10" # Create a public network, which generally matched to bridged network. # config.vm.network "public_network" # Share an additional folder to the guest VM. # config.vm.synced_folder "../data", "/vagrant_data" # config.vm.provider "virtualbox" do |vb| # # Display the VirtualBox GUI when booting the machine # vb.gui = true # # Customize the amount of memory on the VM: # vb.memory = "1024" # end # config.vm.provision "shell", inline: <<-SHELL # sudo apt-get update # sudo apt-get install -y apache2 # SHELL end
  • 7. vagrant file network Vagrant.configure(2) do |config| config.vm.box = "base" # config.vm.box_check_update = false # Create a forwarded port mapping # config.vm.network "forwarded_port", guest: 80, host: 8080 # Create a private network # config.vm.network "private_network", ip: "192.168.33.10" # Create a public network, which generally matched to bridged network. # config.vm.network "public_network" # Share an additional folder to the guest VM. # config.vm.synced_folder "../data", "/vagrant_data" # config.vm.provider "virtualbox" do |vb| # # Display the VirtualBox GUI when booting the machine # vb.gui = true # # Customize the amount of memory on the VM: # vb.memory = "1024" # end # config.vm.provision "shell", inline: <<-SHELL # sudo apt-get update # sudo apt-get install -y apache2 # SHELL end
  • 8. vagrant file provisioning Vagrant.configure(2) do |config| config.vm.box = "base" # config.vm.box_check_update = false # Create a forwarded port mapping # config.vm.network "forwarded_port", guest: 80, host: 8080 # Create a private network # config.vm.network "private_network", ip: "192.168.33.10" # Create a public network, which generally matched to bridged network. # config.vm.network "public_network" # Share an additional folder to the guest VM. # config.vm.synced_folder "../data", "/vagrant_data" # config.vm.provider "virtualbox" do |vb| # # Display the VirtualBox GUI when booting the machine # vb.gui = true # # Customize the amount of memory on the VM: # vb.memory = "1024" # end # config.vm.provision "shell", inline: <<-SHELL # sudo apt-get update # sudo apt-get install -y apache2 # SHELL end
  • 9. vagrant コマンド vagrant box add [box-name] [box-url] vagrant box list Vagrant box remove [box-name] vagrant up 立ち上げ vagrant halt 停止、シャットダウン vagrant suspend 中断 vagrant resume 復帰 vagrant destroy 仮想マシン削除(Boxの削除ではない)
  • 10. vagrant コマンド vagrant reload 設定変更(vagrant file)を反映する、ネットワークの構成変更等 vagarnt provision プロビジョンを実行する(vagrant upした後でも可能)
  • 11. 共有フォルダ デフォルトで 以下は共有フォルダになっています - host OS の vagrant fileを置いてあるフォルダ - guest os の /vagrant ※virtualbox guest additions
  • 12. 共有フォルダ config.vm.synced_folder “host_path”, “guest_path”, type: “nfs” type - virtualbox(Windows/Mac/Linux) - NFS(Mac/Linux) - rsync(Windows/Mac/Linux) - SMB(Windows)
  • 13. 共有フォルダ config.vm.synced_folder “host_path”, “guest_path”, type: “nfs” type - virtualbox(Windows/Mac/Linux) 遅い - NFS(Mac/Linux) それなりに高速 - rsync(Windows/Mac/Linux) ホスト OS 側から仮想環境への一方向だけの同期 - SMB(Windows)
  • 14. ss-vagrant https://github.com/shirasagi/ss-vagrant VirtualBox + CentOS + Shirasagi - 自治体サンプル - 企業サンプル
  • 15. ss-vagrant Vagrant.configure(2) do |config| config.vm.box = "ss-vagrant-v1.2.0" config.vm.box_url = https://github.com/shirasagi/ss-vagrant/releases/download/v1.2.0/ss-vagrant-virtualbox- x86_64.box config.vm.network :forwarded_port, guest: 3000, host: 3000 config.vm.network "private_network", ip: "192.168.33.10“ config.vm.provider :virtualbox do |vb| # IPv6 と DNS でのネットワーク遅延対策で追記 vb.customize ["modifyvm", :id, "--natdnsproxy1", "off"] vb.customize ["modifyvm", :id, "--natdnshostresolver1", "off"] end end
  • 16. windowsでの簡単な立ち上げ方(オフライン) 1. VirtualBoxをインストール 2. vagrantをインストール 3. sshクライアントをインストール 4. VagrantFile と ss-vagrant-virtualbox-x86_64.box を用意 5. フォルダー C:vagrant を作成します 6. VagrantFile と ss-vagrant-virtualbox-x86_64.box を作成したフォルダーにコピーします 7. コマンドプロンプトを立ち上げて以下のコマンドを実行します > cd C:vagrant > vagrant box add ss ss-vagrant-virtualbox-x86_64.box > vagrant up
  • 17. windowsでの簡単な立ち上げ方(オフライン) 8. ssh で仮想環境にログイン 9. シラサギを起動 $ cd $HOME/shirasagi $ bundle exec rake unicorn:start 10. ブラウザから確認 自治体サンプル http://localhost:3000/ 企業サンプル http://192.168.33.10:3000/ 管理画面 http://localhost:3000/.mypage
  • 18. Vagrant Box build 仮想環境上で vagrant package packer を使う - https://www.packer.io/downloads.html - template.jsonを元にBoxを作成 packer build [template.json] - centos用テンプレート: https://github.com/boxcutter/centos
  • 19. Vagrant plugin vagrant plugin install [plugin-name] sahara - サンドボックスモードを有効にするプラグイン - ロールバック機能で実行前の状態に戻すことができます vagrant-hostmanager - HOST名の書き換え(host OS含む)