目的
Vagrant に 慣れる
OSインストールに慣れる
開発環境構築に慣れる
参考
手順
(Oracle VM) Virtual Box をインストール
- 通常は最新版を → Downloads – Oracle VM VirtualBox
Vagrantとの組み合わせで過去バージョンのほうが安全そうであれば → Download_Old_Builds – Oracle VM VirtualBox
- インストールは Wizard に従ってデフォルトで進んだ。
- 途中、ネットワーク関係のドライバをどうする?と聞かれるが、そのまま Next した。
Vagrant をインストール
- 通常は最新版を → Download Vagrant - Vagrant
場合によっては過去版を → Vagrant - Download Archives
- インストールは Wizard に従ってほぼデフォルトで進んだ。インストール先だけちょっと変えた。( C:\Vagrant にした)
- 完了後、OS再起動を求められるので、おとなしく再起動した
- その後コマンドプロンプトで vagrant -v すればバージョンが確認できる
box ファイルの add
- A list of base boxes for Vagrant - Vagrantbox.es から選択
コマンドプロンプトで以下のようなコマンドを実行する
vagrant box add {title} {url}
ダウンロードされて、以下のような場所に格納される。
- C:\Users\hisashi.soga\ .vagrant.d\boxes\centos64_01\virtualbox
box ファイルの init 、up
コマンドプロンプトで以下のようなコマンドを実行して VM 用ディレクトリを作成、移動する
C:> mkdir c:\VirtualBoxVMs\centos64_01 C:> cd c:\VirtualBoxVMs\centos64_01
vagrant init する
C:\VirtualBoxVMs\centos64_01>vagrant init centos64_01
AVagrantfile
has been placed in this directory. You are now
ready tovagrant 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.- この時点で(?あるいは up 時)、C:\Users\hisashi.soga\VirtualBox VMs\ 配下にVM実体が配置される。
vagrant up する
C:\VirtualBoxVMs\centos64_01>vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
[default] Importing base box 'centos64_01'...
[default] Matching MAC address for NAT networking...
[default] Setting the name of the VM...
[default] Clearing any previously set forwarded ports...
[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...
DL is deprecated, please use Fiddle
[default] Machine booted and ready!
[default] Mounting shared folders...
[default] -- /vagrant- /vagrant は共有ディレクトリになっている。パーミッション 777 なので Windows 側から好きにファイルを置けそう。
VM に ssh アクセスしてみる
試しに vagrant ssh
C:\VirtualBoxVMs\centos64_01>vagrant ssh
ssh
executable not found in any directories in the %PATH% variable. Is an
SSH client installed? Try installing Cygwin, MinGW or Git, all of which
contain an SSH client. Or use the PuTTY SSH client with the following
authentication information shown below:Host: 127.0.0.1
Port: 2222
Username: vagrant
Private key: C:/Users/hisashi.soga/.vagrant.d/insecure_private_key
今宵はここまで。VM をおとす
vagrant halt
C:\VirtualBoxVMs\centos64_01>vagrant halt
[default] Attempting graceful shutdown of VM...
DL is deprecated, please use Fiddle
おまけ:心配
Virtual Box インストール時に、一瞬リモートデスクトップ接続が切れた。
- 確かにふつうはリモートデスクトップ接続の状態でインストールとかしないが。。
VirtualBox をアップデートしたら vagrant up でコケた。(OSX10.8.5) - ちょんまげ狸の踊るポンポコ日記
- Mac のことらしいが。。何も起きなければいいな。。