広告 Windows

WindowsにVagrantをインストール

Ansibleの検証を効率良く進めるためにローカルマシンに
VirtualBox + Vagrant をぶっこみたいと思います。

もちろん、お手軽開発環境としてもお使いいただけますので、ぜひお使いください。

今回はWin7 64bitなPCで作業を進めていきます。

VirtualBoxをインストールする

VagrantはVirtualBox上で動きますので、まずはVirtualBoxをインストールします。

以下へアクセスし、最新の「VirtualBox *** for Windows hosts x86/amd64」
を選択し、ダウンロードしてください。

https://www.virtualbox.org/wiki/Downloads

パッケージをダウンロードし終わったらインストーラをデフォルトで進めていってください

Vagrantをインストールする

続いて、Vagrantをインストールしていきましょう!
以下へアクセスし現状の最新版を選択し、その後Windows版をダウンロードしましょう。
http://downloads.vagrantup.com/

パッケージをダウンロードし終わったらインストーラをデフォルトで進めていってください。

OSをインストールする

今回は CentOS 64bit版をインストールしていきます。

以下へアクセスして、最新のCentOS(VirtualBox用)を探します。
見つかったら「COPY」ボタンを押して、URLをコピーしましょう。

http://www.vagrantbox.es/

次にコマンドプロンプトを立ち上げます。
[ Win + R] を押して、「ファイル名を指定して実行」を呼び出して、cmd と打って OK 押せば立ち上がります。

今回はユーザーのディレクトリの下にwin_localVMというフォルダを作成し、
「C:Usersユーザー名win_localVM」の中にCentOSをインストールしていきます。

以下のコマンドを順に流していきましょう!

$ mkdir win_localVM
$ cd win_localVM/
$ vagrant box add centos https://github.com/2creatives/vagrant-centos/releases/download/v6.5.1/centos65-x86_64-20131205.box
$ vagrant init centos
$ vagrant up

こんな感じでインストールされていきます

C:Usersbacchi>mkdir win_localVM
C:Usersbacchi>cd win_localVM
C:Usersbacchiwin_localVM>vagrant box add centos https://github.com/2creatives/
vagrant-centos/releases/download/v6.5.1/centos65-x86_64-20131205.box
==> box: Adding box \'centos\' (v0) for provider:
    box: Downloading: https://github.com/2creatives/vagrant-centos/releases/down
load/v6.5.1/centos65-x86_64-20131205.box
    box: Progress: 100% (Rate: 1572k/s, Estimated time remaining: --:--:--)
==> box: Successfully added box \'centos\' (v0) for \'virtualbox\'!
C:Usersbacchiwin_localVM>vagrant init centos
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.
C:Usersbacchiwin_localVM>vagrant up
Bringing machine \'default\' up with \'virtualbox\' provider...
==> default: Importing base box \'centos\'...
==> default: Matching MAC address for NAT networking...
==> default: Setting the name of the VM: win_localVM_default_1413968435051_45328
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
==> default: Forwarding ports...
    default: 22 => 2222 (adapter 1)
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address: 127.0.0.1:2222
    default: SSH username: vagrant
    default: SSH auth method: private key
    default: Warning: Connection timeout. Retrying...
    default: Warning: Connection timeout. Retrying...
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
==> default: Mounting shared folders...
    default: /vagrant => C:/Users/bacchi/win_localVM
C:Usersbacchiwin_localVM>vagrant box list
cent6  (virtualbox, 0)
centos (virtualbox, 0)
C:Usersbacchiwin_localVM>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 your favorite SSH client with the following
authentication information shown below:
Host: 127.0.0.1
Port: 2222
Username: vagrant
Private key: C:/Users/bacchi/.vagrant.d/insecure_private_key

エラーが発生!?

作業を進めてると以下の様なエラーメッセージが発生する可能性があります。

■仮想化支援機能(VT-x/AMD-V)を有効化できません

そんな時はBIOSで仮想化支援機構(VT-x/AMD-V)が有効化すれば解決します。
手順等についてはまたまとめようと思います。

作ったサーバーに接続する

VagrantはSSHのコマンドが用意されていますが、Windowsでは使えません。
なので、PuttyやPoderosaなんかのSSHクライアントを使います。
接続情報は以下のとおりです

Host    : 127.0.0.1
Port    : 2222
User    : vagrant
PassWord: vagrant

作った環境を削除する

がんばって作った環境がいらなくなれば、簡単に削除できます。
コマンドプロンプトを立ち上げて、以下のコマンドを流すだけ

vagrant destroy centos

Win環境での設定方法をざっとまとめました。
Mac環境でVagrant走らせる方法もまとめます!

Sponsor Link

-Windows