vagrant tutorial
いろいろ説明が抜けているところもありますが、サクッとチュートリアル。
環境
Mac OS X 10.8.5Virtual Box 4.2.18
Vagrant 1.3.3
index
・uninstall
・virtual box で Ubuntu12.04 LTS 32-bit が動き出す
・vagrant で起動したマシンへ ssh
・VM を止める
・Vagrantfile の作成
・Vagrantfile へ、add box
・add box した box を使用できるよう名前変更
・host と guest の共有ディレクトリ
・shell の実行
・suspending
uninstall
rm /Applications/Vagrant
rm /usr/bin/vagrant
rm ~/.vagrant.d
virtual box で Ubuntu12.04 LTS 32-bit が動き出す
初期化と、sample の Ubuntu をダウンロードするところから。
% vagrant init precise32 http://files.vagrantup.com/precise32.box
A `Vagrantfile` has been placed in this directory. You are now
ready to `vagrant up` your first virtual environment! Please read
the comments in the Vagrantfile as well as documentation on
`vagrantup.com` for more information on using Vagrant.
そしてダウンロードしてきた Ubuntu を起動する。
% vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
[default] Box 'precise32' was not found. Fetching box from specified URL for
the provider 'virtualbox'. Note that if the URL does not have
a box for this provider, you should interrupt Vagrant now and add
the box yourself. Otherwise Vagrant will attempt to download the
full box prior to discovering this error.
Downloading or copying the box...
Extracting box...te: 961k/s, Estimated time remaining: --:--:--)
Successfully added box 'precise32' with provider 'virtualbox'!
[default] Importing base box 'precise32'...
[default] Matching MAC address for NAT networking...
[default] Setting the name of the VM...
[default] Clearing any previously set forwarded ports...
[default] Creating shared folders metadata...
[default] Clearing any previously set network interfaces...
[default] Preparing network interfaces based on configuration...
[default] Forwarding ports...
[default] -- 22 => 2222 (adapter 1)
[default] Booting VM...
[default] Waiting for machine to boot. This may take a few minutes...
[default] Machine booted and ready!
[default] Mounting shared folders...
[default] -- /vagrant
vagrant で起動したマシンへ ssh
% vagrant ssh
Welcome to Ubuntu 12.04 LTS (GNU/Linux 3.2.0-23-generic-pae i686)
* Documentation: https://help.ubuntu.com/
Welcome to your Vagrant-built virtual machine.
Last login: Fri Sep 14 06:22:31 2012 from 10.0.2.2
ovagrant@precise32:~$
VM を止める
% vagrant destroy
Are you sure you want to destroy the 'default' VM? [y/N] y
[default] Forcing shutdown of VM...
[default] Destroying VM and associated drives...
Vagrantfile の作成
% mkdir vagrant
% cd vagrant
% vagrant init
A `Vagrantfile` has been placed in this directory. You are now
ready to `vagrant up` your first virtual environment! Please read
the comments in the Vagrantfile as well as documentation on
`vagrantup.com` for more information on using Vagrant.
Vagrantfile へ、add box
% vagrant box add precise32 http://files.vagrantup.com/precise32.box
add box した box を使用できるよう名前変更
Vagrantfile へ、
Vagrant.configure("2") do |config|
config.vm.box = "precise32"
end
そして Vagrantfile があるところで起動
% vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
[default] Importing base box 'precise32'...
[default] Matching MAC address for NAT networking...
[default] Setting the name of the VM...
[default] Clearing any previously set forwarded ports...
[default] Fixed port collision for 22 => 2222. Now on port 2200.
[default] Creating shared folders metadata...
[default] Clearing any previously set network interfaces...
[default] Preparing network interfaces based on configuration...
[default] Forwarding ports...
[default] -- 22 => 2200 (adapter 1)
[default] Booting VM...
[default] Waiting for machine to boot. This may take a few minutes...
[default] Machine booted and ready!
[default] Mounting shared folders...
[default] -- /vagrant
host と guest の共有ディレクトリ
host の vagrant init したディレクトリと、guest の /vagrant ディレクトリが共有する
shell の実行
vagrant init した場所に、
bootstrap.sh を書く
#!/usr/bin/env bash
apt-get update
apt-get install -y apache2
rm -rf /var/www
ln -fs /vagrant /var/www
中身はこんな感じ
Vagrantfile へ
Vagrant.configure("2") do |config|
config.vm.box = "precise32"
config.vm.provision :shell, :path => "bootstrap.sh"
end
Vagrantfile がある場所が、location の root になる
% vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
[default] Importing base box 'precise32'...
[default] Matching MAC address for NAT networking...
[default] Setting the name of the VM...
[default] Clearing any previously set forwarded ports...
[default] Fixed port collision for 22 => 2222. Now on port 2200.
[default] Creating shared folders metadata...
[default] Clearing any previously set network interfaces...
[default] Preparing network interfaces based on configuration...
### 省略 ###
Setting up apache2 (2.2.22-1ubuntu1.4) ...
Setting up ssl-cert (1.0.28ubuntu0.1) ...
Processing triggers for libc-bin ...
ldconfig deferred processing now taking place
ポートフォワーディング
Vagrant.configure("2) do |config|
config.vm.box = "precise32"
config.vm.provision :shell, :path => "bootstrap.sh"
config.vm.network :forwarded_port, host, 4567, guest:80
end
%vagrant reload か % vagrant up
suspending
% vagrant suspend
[default] Saving VM state and suspending execution...
でサスペンドできる
再度動かすには、いつもの
% vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
[default] Resuming suspended VM...
[default] Booting VM...
その他 provider での実行
% vagrant up --provider=vmware_fusion
コメント
コメントを投稿