ローカル検証環境の構築(Vagrantで)
はじめに
先日、Chef実践入門を読みました。
ようやくChefとVagrantの使い道がわかってきました。
Chef実践入門 ~コードによるインフラ構成の自動化 (WEB+DB PRESS plus)
- 作者: 吉羽龍太郎,安藤祐介,伊藤直也,菅井祐太朗,並河祐貴
- 出版社/メーカー: 技術評論社
- 発売日: 2014/05/22
- メディア: 単行本(ソフトカバー)
- この商品を含むブログ (13件) を見る
業務で検証用のCentOSをVirtualBoxにインストールする作業をよくやるのですが
飽きました。今後はVagrantでやろうと思いました。
Vagrantの準備は Chef実践入門 の 第2章:Chef Soloによるローカル開発環境の自動構築 に
書いてあるのでWindowsマシンでやってみます。
環境
Windows7
Virtualbox 4.3.12 インストール済み
Vagrant準備
インストール
Windowsのインストーラがありました。
Vagrant_1.3.5.msiを下記からダウンロードしてインストールしました。
http://downloads.vagrantup.com/
イメージ取得
20分以上かかりました。初回のみです。
c:\>vagrant box add opscode_centos-6.5-i386 http://opscode-vm-bento.s3.amazonaws.com/vagrant/virtualbox/opscode_centos-6.5-i386_chef-provisionerless.box ==> box: Adding box 'opscode_centos-6.5-i386' (v0) for provider: box: Downloading: http://opscode-vm-bento.s3.amazonaws.com/vagrant/virtualbox/opscode_centos-6.5-i386_chef-provisionerless.box box: Progress: 100% (Rate: 206k/s, Estimated time remaining: --:--:--) ==> box: Successfully added box 'opscode_centos-6.5-i386' (v0) for 'virtualbox'!
作成
c:\>vagrant init opscode_centos-6.5-i386 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.
ここにVagrantfile作るのかよ。本には書いてある。
起動
c:\>vagrant up Bringing machine 'default' up with 'virtualbox' provider... ==> default: Importing base box 'opscode_centos-6.5-i386'... ==> default: Matching MAC address for NAT networking... ==> default: Setting the name of the VM: _default_1402483243996_96207 ==> 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: Machine booted and ready! ==> default: Checking for guest additions in VM... ==> default: Mounting shared folders... default: /vagrant => C:/
起動できたみたいです。
ネットワーク設定
Vagrantfileの下記のコメントアウトをはずす
config.vm.network "private_network", ip: "192.168.33.10"
で再起動
c:\>vagrant halt c:\>vagrant up
ほかの環境を作りたい場合
ほかのフォルダに作るんでしょう、たぶん。
c:\>mkdir .\hoka c:\>cd .\hoka c:\>vagrant init opscode_centos-6.5-i386
VagrantfileのIPアドレスいじって
c:\>vagrant up
まとめ
Vagrantの使い方、実際にやってみてわかりました。
VirtualboxのGUI使ってやるより早く、楽になるかと思います。
で yum update するのをChefでやるんですね。来週やってみよう。