色々自分でWebサービスを構築することを勉強し始めたら、仮想化がすごく便利な気がしてきたので試してみることにしました。
ドットインストールの手順に従っただけだけど、バージョンや引っかかった点のメモなどに。
準備
VirtualBoxのインストール
仮想マシンそのものって言うか仮想化環境って言ったらいいのかな。
ふだんMacでWindowsを動かすためにVMWare Fusionも持ってるけど、応用がききそうなのでVirtualBoxをインストール。
インストールしたバージョンは4.3.0。
Vagrantのインストール
Version1.3.5をインストールした。
仮想マシンの作成
Boxのダウンロード
Boxとは何かというと、公式サイトによると、
Vagrant uses a base image to quickly clone a virtual machine. These base images are known as boxes in Vagrant, and specifying the box to use for your Vagrant environment is always the first step after creating a new Vagrantfile.
Vagrantでは仮想マシンのクローンを手軽に作れるように、"Box"と呼ばれる基本となるイメージを使います、だそうです。まぁよくわかりません。先に進みます。
%> vagrant box add precise32 http://files.vagrantup.com/precise32.box Downloading or copying the box... Progress: 0% (Rate: 92288/s, Estimated time remaining: 1:15:34))
すでにダウンロードしたBoxを一覧表示するのは、
%> vagrant box list precise32 (virtualbox)
とします。
そのほかにいろんな有志からBoxが提供されています。
参考:Vagrantbox.es
ドットインストールで、CentOS6を追加していたので同じく実行。
vagrant box add centos64 https://dl.dropbox.com/u/5721940/vagrant-boxes/vagrant-centos-6.4-x86_64-vmware_fusion.box
個人的にはCentOSでRedmineを立ち上げるつもりなので、ちょうどいい。
と思ったら間違ってvmware_fusion用をダウンロードしてた。
追加でVirtualBox用をダウンロードした。
vagrant box add centos64 http://developer.nrel.gov/downloads/vagrant-boxes/CentOS-6.4-x86_64-v20130731.box
そこで気付いたのが、同じ名前でBoxをダウンロードしていたこと。公式サイトを見る限り、それ自体は問題ない模様。ただし、仮想マシンの初期化の時に"provider"(仮想環境)を指定する方法がぱっと見でわからなかったので、
VMWare Fusion用のBoxを削除することにした。これは公式サイトでコマンドを見た。
vagrant box remove centos64 vmware_fusion
仮想マシンの初期化
vagrant init centos64
ここでバージョンに関して警告が発生。
The guest additions on this VM do not match the installed version of VirtualBox! In most cases this is fine, but in rare cases it can cause things such as shared folders to not work properly. If you see shared folder errors, please update the guest additions within the virtual machine and reload your VM. Guest Additions Version: 4.2.16 VirtualBox Version: 4.3
ただ、"In most cases this is fine"とあるので、とりあえずこのまま進めることにした。
仮想マシンの起動
コマンド一発で仮想マシンが起動します。これは便利。OSのインストールもセットアップも終わっている・・・。vagrant up
>% vagrant status Current machine states: default running (virtualbox) The VM is running. To stop this VM, you can run `vagrant halt` to shut it down forcefully, or you can run `vagrant suspend` to simply suspend the virtual machine. In either case, to restart it again, simply run `vagrant up`.
仮想マシンへの接続
%>vagrant ssh Welcome to your Vagrant-built virtual machine. $
これで仮想マシンに接続できます。
とりあえず今回はここまで。(ドットインストールの#06まで)
今後、目標としているのは下記。
- Macで稼働させているRedmineを仮想マシンに移行させること
- Wordpressのいろんなお試しを仮想マシンで行えるようにすること
- Ruby on Railsを使ったWebサービス構築を仮想マシンで行うこと
とりあえず、ドットインストールで勉強しながら頑張ります。
