読者です 読者をやめる 読者になる 読者になる

manatee-itの備忘ログ

プログラム初心者のブログ。ruby on railsでWebサービスを作成中。(仕事が忙しくなかななか進まず) つまずいた所をなんでも記録。 環境:Ruby2.1 + Rails4.1.1 + Passenger + CentOS6.4(Apache + sqlite/MySQL)

Vagrantのboxの適用

以下を参考にboxの導入方法を確認しました。

dotinstall.com

■boxの適用

Box毎にディレクトリを分ける。

$ mkdir -p VagrantTest/testcentos
$ cd VagrantTest/testcentos

Boxの初期化

$ 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.

ネットワークの有効化。

$ vim Vagrantfile
  #config.vm.network "private_network", ip: "192.168.33.10"
  ↓
  config.vm.network "private_network", ip: "192.168.33.10"

IPアドレスを編集したところ、"vagrant up"でエラーとなったため、そのままコメントアウト

$ grep -v -e '^\s*#' -e '^\s*$' Vagrantfile
Vagrant.configure(2) do |config|
  config.vm.box = "chef/centos-7.1"
  config.vm.network "private_network", ip: "192.168.33.10"
end

$ 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://atlas.hashicorp.com/chef/centos-6.5
==> default: Adding box 'chef/centos-6.5' (v1.0.0) for provider: virtualbox
    default: Downloading: https://atlas.hashicorp.com/chef/boxes/centos-6.5/versions/1.0.0/providers/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: testcentos65_default_1436103308988_60424
==> default: Fixed port collision for 22 => 2222. Now on port 2201.
==> 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 => 2201 (adapter 1)
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address: 127.0.0.1:2201
    default: SSH username: vagrant
    default: SSH auth method: private key
    default: Warning: Connection timeout. Retrying...
    default: Warning: Remote connection disconnect. Retrying...
    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 its present...
    default: Key inserted! Disconnecting and reconnecting using new SSH key...
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
==> default: Configuring and enabling network interfaces...
==> default: Mounting shared folders...
    default: /vagrant => /home/manatee/VagrantTest/testcentos65

IPアドレスを変更したところ、以下のようにエラーとなった。ホストと同じセグメントするためには、パブリックネットワークの設定を行う必要がある。

Vagrantのネットワーク周りのあれこれ | Septeni Engineers' Blog | セプテーニ エンジニアブログ vagrantのネットワークについて - Qiita

$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Box 'chef/centos-7.1' could not be found. Attempting to find and install...
    default: Box Provider: virtualbox
    default: Box Version: >= 0
==> default: Loading metadata for box 'chef/centos-7.1'
    default: URL: https://atlas.hashicorp.com/chef/centos-7.1
==> default: Adding box 'chef/centos-7.1' (v1.0.0) for provider: virtualbox
    default: Downloading: https://atlas.hashicorp.com/chef/boxes/centos-7.1/versions/1.0.0/providers/virtualbox.box
==> default: Successfully added box 'chef/centos-7.1' (v1.0.0) for 'virtualbox'!
==> default: Importing base box 'chef/centos-7.1'...
==> default: Matching MAC address for NAT networking...
==> default: Checking if box 'chef/centos-7.1' is up to date...
==> default: Setting the name of the VM: testcentos_default_1436101003101_87114
==> default: Fixed port collision for 22 => 2222. Now on port 2200.
==> default: Clearing any previously set network interfaces...
The specified host network collides with a non-hostonly network!
This will cause your specified IP to be inaccessible. Please change
the IP or name of your host only network so that it no longer matches that of
a bridged or non-hostonly network.

$ vagrant ssh
Last login: Fri Mar  7 16:57:20 2014 from 10.0.2.2

■ゲストOSの設定

ドットインストールにて用意されたスクリプトを実行。 Ansibleを利用して基本的な設定が一括して行われる様子。

gitをインストール

$ sudo yum -y install git
Loaded plugins: fastestmirror
Determining fastest mirrors
 * base: ftp.tsukuba.wide.ad.jp
 * extras: ftp.tsukuba.wide.ad.jp
 * updates: ftp.tsukuba.wide.ad.jp
 :
 :

ドットインストールのスクリプトをダウンロード

$ git clone https://github.com/dotinstallres/centos65.git
Initialized empty Git repository in /home/vagrant/centos65/.git/
remote: Counting objects: 89, done.
remote: Total 89 (delta 0), reused 0 (delta 0), pack-reused 89
Unpacking objects: 100% (89/89), done.

スクリプトを実行

$ cd centos65/
$ ./run.sh