VagrantとchefとServer Specの実験

chefとserver specのための環境

気軽にぶっ壊せて、気軽に作業に入れるCentOS環境が欲しかったのでもしかしたらいいのかもしれないと思ってwindows上でVagrantをはじめて触ってみようの会です。 この記事はVagrantが起動するところまでを書いていきます。

まずVirtualBoxをダウンロードしてきました

よくわからないけれどVirtualBoxが必要ということだったのでダウンロードしてきました。

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

ダウンロードしたらインストールします。私がダウンロードした時のバージョンは VirtualBox 4.3.10 for Windows hosts でした。

vagrantのインストール

VagrantさんはRubyらしいので、gemでインストールできるようです。 
※現在は公式サイトからのダウンロードが推奨されているようです。以下のものは動きませんでした。
※rubyがない人はRubyのダウンロードをよろしくです。

$ gem install vagrant
Fetching: vagrant-1.5.0.gem (100%)

1 gem installed

ちなみに私のRubyは

$ ruby -v
ruby 2.0.0p451 (2014-02-24) [i386-mingw32]

でした参考までに。

VMの追加と起動

起動するためにboxというファイルをもってきます。いわゆるイメージファイルでvirtual box的なイメージでしょうか?ちがいますか?

http://www.vagrantbox.es/ こちらにいろいろ有ります。 わたしは 「http://developer.nrel.gov/downloads/vagrant-boxes/CentOS-6.4-i386-v20130731.box」を使ってみることにしました。

下記のように起動するようです

# 使うboxと名前付けを追加
$ vagrant box add CentOS http://developer.nrel.gov/downloads/vagrant-boxes/CentOS-6.4-i386-v20130731.box
# 先ほどの名前のものを設定ファイル生成
$ vagrant init CentOS
# 起動
$ vagrant up
という感じです。
一行目で何か変なの出てきた

Thanks for wanting to use Vagrant! Unfortunately, this is not the way to install Vagrant anymore. We now make installers for the various operating systems Vagrant supports. 中略 If you want to learn more about why we don’t distribute using RubyGems anymore, please read this: http://mitchellh.com/abandoning-rubygems 要は最新はもうgemじゃないんだぜ、webサイト来てくれ、的な話しらしいです(?)というかもうだめらしい。インストールし直しでした。悲しいね。

というわけで入れなおした。WEBサイトからダウンロードしてきてインストールをしました。 バージョンは下記のとおりです。
$ vagrant -v
Vagrant 1.5.4
気を取り直して、さきほどのコマンドを一行目からいきます。 まず、ダウンロードがはじまって進捗と残時間とかが出てきます。 ※ 結構ダウンロードに時間がかかるためのちほどダウンロードしてきたものを使うことにしました。   その際はhttp://から始まる部分に該当ファイルパスを指定してください。
box: Adding box 'CentOS' (v0) for provider:
box: Downloading: http://developer.nrel.gov/downloads/vagrant-boxes/CentOS-6.4-x86_64-v20130731.box
box: Progress: 100% (Rate: 9282k/s, Estimated time remaining: --:--:--)
==> box: Successfully added box 'CentOS' (v0) for 'virtualbox'!
大体10分ぐらい?完了したらとりあえず続行します。
$ 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.
とりあえず続行します。
$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Clearing any previously set forwarded ports...
==> 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: Warning: Connection timeout. Retrying...
default: Warning: Connection timeout. Retrying… から進まない事象が発生。
Connection timeout. Retrying…のままタイムアウトの対策(windos)
散々粘っていろいろ試してみたのですが、結論から言うとWINDOWSの場合BIOSの設定で VTを有効にしないとboxが立ち上がらないようです。
参考 => http://qiita.com/rch850/items/ba254063df4a9ff15354
再立ち上げ
BIOSの設定を変えたところで、再度upを試してみたところ無事に立ち上がりました。 Retryingも2回でてますが、前はそこからさきに進みませんでしたからね。
$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Clearing any previously set forwarded ports...
==> 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: The guest additions on this VM do not match the installed version of
default: VirtualBox! In most cases this is fine, but in rare cases it can
default: prevent things such as shared folders from working properly. If you see
default: shared folder errors, please make sure the guest additions within the
default: virtual machine match the version of VirtualBox you have installed
on
default: your host and reload your VM.
default:
default: Guest Additions Version: 4.2.16
default: VirtualBox Version: 4.3
==> default: Mounting shared folders...
default: /vagrant => C:/Users/XXXX
立ち上がったあとのいろいろ
ステータスの確認 => $ 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`.
起動中のVMにssh接続 => $ vagrant ssh
Welcome to your Vagrant-built virtual machine.
[vagrant@localhost ~]$
# 立ち上げたBMX試しにinitスクリプトのフォルダを覗いておいた
[vagrant@localhost ~]$ ls /etc/init.d/
auditd iscsi netfs rpcbind sshd
blk-availability iscsid network rpcgssd udev-post
crond killall nfs rpcidmapd vboxadd
dkms_autoinstaller lvm2-lvmetad nfslock rpcsvcgssd vboxadd-service
functions lvm2-monitor postfix rsyslog vboxadd-x11
halt mdmonitor puppet sandbox
ip6tables multipathd rdisc saslauthd
iptables netconsole restorecond single
起動したVMの停止 => $ vagrant halt
==> default: Attempting graceful shutdown of VM...
default: Guest communication could not be established! This is usually because
default: SSH is not running, the authentication information was changed,
default: or some other networking issue. Vagrant will force halt, if
default: capable.
==> default: Forcing shutdown of VM...
あとは 再起動 => $ vagrant reload
中断 => $ vagrant suspend
中断からの再開 => $ vagrant resume
マシンの停止と作られる過程で生成されたすべてのリソースの削除 => $ vagrant destroy
次の記事ではVagrantの具体的な設定を行いたい
今回はとりあえず起動までを記事にしました。 次はVagrantfileの設定の勉強をしてから記事にしたいと思います。 その次はchefの方を行います。