#はじめに
巷で話題のVagrantとItamaeを触ってみる。
スーパーユーザで操作する。
#Vagrantのインストール
ここ からVagrantをダウンロードし、インストールする。
#boxファイルの追加
# vagrant box add CentOS7Minimal https://github.com/tommy-muehle/puppet-vagrant-boxes/releases/download/1.1.0/centos-7.0-x86_64.box
==> box: Box file was not detected as metadata. Adding it directly...
==> box: Adding box 'CentOS7Minimal' (v0) for provider:
box: Downloading: https://github.com/tommy-muehle/puppet-vagrant-boxes/releases/download/1.1.0/centos-7.0-x86_64.box
==> box: Box download is resuming from prior download progress
==> box: Successfully added box 'CentOS7Minimal' (v0) for 'virtualbox'!
#インストール確認
#vagrant box list
CentOS7Minimal (virtualbox, 0)
#Vagrant の初期化/設定
# mkdir VM_CentOS
# cd VM_CentOS
# vagrant init CentOS7Minimal
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ファイルが作られるため、viにて以下の行を有効にする
config.vm.network "private_network", ip: "192.168.33.10"
(私は192.168.57.10とした)
#起動/ログイン
#vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'CentOS7Minimal'...
==> default: Matching MAC address for NAT networking...
==> default: Setting the name of the VM: VM_CentOS_default_1461734128813_67812
==> 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: Adapter 2: hostonly
==> default: Forwarding ports...
default: 22 (guest) => 2222 (host) (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:
default: Vagrant insecure key detected. Vagrant will automatically replace
default: this with a newly generated keypair for better security.
default:
default: Inserting generated public key within guest...
default: Removing insecure key from the guest if it's present...
default: Key inserted! Disconnecting and reconnecting using new SSH key...
==> 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.28
default: VirtualBox Version: 5.0
==> default: Configuring and enabling network interfaces...
==> default: Mounting shared folders...
default: /vagrant => [パス]/VM_CentOS
#vagrant ssh
Last login: Thu Jul 16 08:48:31 2015 from 10.0.2.2
Welcome to your Vagrant-built virtual machine.
#Itamaeのインストール
# gem install itamae
# itamae version
Itamae v1.9.6
#Itamaeによるnginx/PHP/MySQLのインストール
/usr/local/setup.rb
package "nginx" do
action :install
end
package "php" do
action :install
end
package "mysql" do
action :install
end
#itamae local setup.rb
INFO : Starting Itamae...
INFO : Recipe: /usr/local/setup.rb
INFO : package[nginx] installed will change from 'false' to 'true'
INFO : package[php] installed will change from 'false' to 'true'
INFO : package[mysql] installed will change from 'false' to 'true'
#Vagrantから抜ける
# exit
#Vagrantの終了
# vagrant halt
#仮想マシンの破棄
# vagrant destroy
#おわりに
VagrantはIP指定が簡単!CentOS 7からはnmtuiコマンドで
比較的簡単にIPの設定が可能ですが、Vagrantの簡単さには敵わない所感。
Itamaeについて非常に簡単にしか触らなかったが、
設定ファイルの配置やリモートサーバへの操作も可能。