Vagrantを使ってみた
◯ Vagrantとは
コレ => Discover Vagrant Boxes | Atlas by HashiCorp
- 要は仮想環境構築ツール
仮想マシンの作成/OSインストールといった作業も含め、 設定管理の自動化を行うことができる。
https://vagrantcloud.com から使いたい Vagrantfile を探して、「vagrant init [使いたいやつ] 」で
環境構築が完了しちゃうすぐれもの。
ちなみに自分はboxにコレを使用=> https://vagrantcloud.com/chef/centos-6.5
テスト環境を構築したい場合や複数人で開発している場合など、
揃えた環境を複数作成したいときに便利。
内部的にはVMを使ったりEC2を使ったりできるみたい。
ちなみに自分はVMで起動。
◯ 実際に導入してみる
- vagrant 用のディレクトリ作成して
$ mkdir vagrant/ $ cd vagrant/
- Vagrantfileを作成して、ディスクイメージを取得する準備をする
$ vagrant init chef/centos-6.5 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: Box 'chef/centos-6.5' could not be found. Attempting to find and install... default: Box Provider: virtualbox default: Box Version: >= 0 ==> default: Loading metadata for box 'chef/centos-6.5' default: URL: https://vagrantcloud.com/chef/centos-6.5 ==> default: Adding box 'chef/centos-6.5' (v1.0.0) for provider: virtualbox default: Downloading: https://vagrantcloud.com/chef/centos-6.5/version/1/provider/virtualbox.box ==> default: Successfully added box 'chef/centos-6.5' (v1.0.0) for 'virtualbox'! ==> default: Importing base box 'chef/centos-6.5'... ==> default: Matching MAC address for NAT networking... ==> default: Checking if box 'chef/centos-6.5' is up to date... ==> default: Setting the name of the VM: rails_centos_default_1398300190981_12857 ==> 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: 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.3.8 default: VirtualBox Version: 4.2 ==> default: Mounting shared folders... default: /vagrant => /Users/asai.momoko/work/hobby/vagrant/rails_centos
$ vagrant ssh Last login: Fri Mar 7 16:57:20 2014 from 10.0.2.2 [vagrant@localhost ~]$
すばらしい