Vagrant(ベイグラント)とは仮想の開発環境を簡単に構築・管理出来る開発環境自動化作成ツールです。
実際の仮想環境の作成にはVirtualBox等が利用出来ます。
Vagrantのインストール
1. VirtualBoxのインストール
先ずはVirtualBoxをインストールします。
下記公式サイトからインストーラーをダウンロードしてインストールしておきます。
※今回はWindows8で実行しています。
2.Vagrantのインストール
次ぐにVagrantをインストールします。
同様に以下の公式サイトからインストーラーをダウンロードしてインストールします。
デフォルトでは以下にインストールされます。
1C:\HashiCorp\Vagrant3.boxの設定
VagrantではOSインストール済みの仮想イメージを利用して仮想マシンを起動します。
今回は以下のサイトから探したUbuntuの公式イメージを取得してみます。
以下コマンドでboxイメージを取得します。
1C:\HashiCorp\Vagrant>vagrant box add ubuntu-14.04 http://cloud-images.ubuntu.com/vagrant/trusty/current/trusty-server-cloudimg-amd64-vagrant-disk1.boxlistコマンドで確認してみます。
1C:\HashiCorp\Vagrant>vagrant box list2ubuntu-14.04 (virtualbox, 0)4.起動
次ぐにVagrantの設定ファイルを作成します。
1C:\HashiCorp\Vagrant>vagrant init ubuntu-14.042A `Vagrantfile` has been placed in this directory. You are now3ready to `vagrant up` your first virtual environment! Please read4the comments in the Vagrantfile as well as documentation on5`vagrantup.com` for more information on using Vagrant.続いて仮想マシンを起動してみます。
1C:\HashiCorp\Vagrant>vagrant up2Bringing machine 'default' up with 'virtualbox' provider...3==> default: Importing base box 'ubuntu-14.04'...4==> default: Matching MAC address for NAT networking...5==> default: Setting the name of the VM: Vagrant_default_1398912051348_755626==> default: Clearing any previously set forwarded ports...7==> default: Clearing any previously set network interfaces...8==> default: Preparing network interfaces based on configuration...9 default: Adapter 1: nat10==> default: Forwarding ports...11 default: 22 => 2222 (adapter 1)12==> default: Booting VM...13==> default: Waiting for machine to boot. This may take a few minutes...14 default: SSH address: 127.0.0.1:222215 default: SSH username: vagrant16 default: SSH auth method: private key17 default: Warning: Connection timeout. Retrying...18 default: Warning: Remote connection disconnect. Retrying...19==> default: Machine booted and ready!20==> default: Checking for guest additions in VM...21==> default: Mounting shared folders...22 default: /vagrant => C:/HashiCorp/Vagrantステータスコマンドで確認してみます。
runningで起動しているのが分かります。
1C:\HashiCorp\Vagrant>vagrant status2Current machine states:34default running (virtualbox)56The VM is running. To stop this VM, you can run `vagrant halt` to7shut it down forcefully, or you can run `vagrant suspend` to simply8suspend the virtual machine. In either case, to restart it again,9simply run `vagrant up`.SSHコマンドを実行してみます。
※SSHクライアントが設定されていないと下記の様に表示されます。
1C:\HashiCorp\Vagrant>vagrant ssh2`ssh` executable not found in any directories in the %PATH% variable. I3SSH client installed? Try installing Cygwin, MinGW or Git, all of which4contain an SSH client. Or use the PuTTY SSH client with the following5authentication information shown below:67Host: 127.0.0.18Port: 22229Username: vagrant10Private key: C:/Users/ユーザー名/.vagrant.d/insecure_private_keyクライアントを利用して接続してみます。
1login as: vagrant2vagrant@localhost's password:3Welcome to Ubuntu 14.04 LTS (GNU/Linux 3.13.0-24-generic x86_64)45 * Documentation: https://help.ubuntu.com/67 System information as of Wed May 7 05:25:58 UTC 201489 System load: 0.04 Processes: 7610 Usage of /: 3.0% of 39.34GB Users logged in: 011 Memory usage: 24% IP address for eth0: 10.0.2.1512 Swap usage: 0%1314 Graph this data and manage this system at:15 https://landscape.canonical.com/1617 Get cloud support with Ubuntu Advantage Cloud Guest:18 http://www.ubuntu.com/business/services/cloud19207 packages can be updated.217 updates are security updates.2223Last login: Wed May 7 05:25:58 2014 from 10.0.2.224vagrant@vagrant-ubuntu-trusty-64:~$無事接続出来ました!
5.停止
最後に停止コマンドで終了します。
1C:\HashiCorp\Vagrant>vagrant haltいかがでしたでしょうか?
次回は『OSS編~Jubatusを試してみる①~』と題して、オンライン機械学習向けの分散処理フレームワークのJubatusを試してみたいと思います。
お楽しみに!!!