12/08/2018, 09:29

Vagrant構築 入門

この先の開発環境を考えててVagrantを導入する事にしました。 当面の目標はrailsの環境を構築することですが、今回はひとまずVagrantにsshで接続するところまでを確認します。 必要なものはVirtual BoxとVagrant 実行環境 OS X Yosemite Iterm2 Build 2.1.1 仮想環境 Virtual Box 4.3.20 vagrant 1.7.2 VirtualBoxはインストール済みだったのでVagrantだけbrew-caskでインストール eiji% brew cask install ...

この先の開発環境を考えててVagrantを導入する事にしました。

当面の目標はrailsの環境を構築することですが、今回はひとまずVagrantにsshで接続するところまでを確認します。

必要なものはVirtual BoxとVagrant

実行環境

  • OS X Yosemite
  • Iterm2 Build 2.1.1

仮想環境

  • Virtual Box 4.3.20
  • vagrant 1.7.2

VirtualBoxはインストール済みだったのでVagrantだけbrew-caskでインストール

eiji% brew cask install vagrant
==> Downloading https://dl.bintray.com/mitchellh/vagrant/vagrant_1.7.2.dmg
Already downloaded: /Library/Caches/Homebrew/vagrant-1.7.2.dmg
==> Running installer for vagrant; your password may be necessary.
==> Package installers may write to any location; options such as --appdir are i
==> installer: Package name is Vagrant
==> installer: Upgrading at base path /
==> installer: The upgrade was successful.
  vagrant staged at '/opt/homebrew-cask/Caskroom/vagrant/1.7.2' (6 files, 79M)

Vagrantをダウンロードして無事にインストールできました。

VagrantDocsに以下のような指示があったので実行してみます。

$ vagrant init hashicorp/precise32
$ vagrant up

vagrant initでVagrantfileをhashicorp/precise32に初期化して, vagrant upで仮想マシンの構築をします。

eiji% vagrant init hashicorp/precise32
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.
eiji% vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Box 'hashicorp/precise32' could not be found. Attempting to find and install...
    default: Box Provider: virtualbox
    default: Box Version: >= 0
==> default: Loading metadata for box 'hashicorp/precise32'
    default: URL: https://atlas.hashicorp.com/hashicorp/precise32
==> default: Adding box 'hashicorp/precise32' (v1.0.0) for provider: virtualbox
    default: Downloading: https://atlas.hashicorp.com/hashicorp/boxes/precise32/versions/1.0.0/providers/virtualbox.box
==> default: Successfully added box 'hashicorp/precise32' (v1.0.0) for 'virtualbox'!
==> default: Importing base box 'hashicorp/precise32'...
==> default: Matching MAC address for NAT networking...
==> default: Checking if box 'hashicorp/precise32' is up to date...
==> default: Setting the name of the VM: eiji_default_1432651898383_88916
==> 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:
    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: 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.0
    default: VirtualBox Version: 4.3
==> default: Mounting shared folders...
    default: /vagrant => /Users/eiji

最後にVagrant sshで仮想マシンにアクセスしてみます。

eiji% vagrant ssh
Welcome to Ubuntu 12.04 LTS (GNU/Linux 3.2.0-23-generic-pae i686)

 * Documentation:  https://help.ubuntu.com/
New release '14.04.2 LTS' available.
Run 'do-release-upgrade' to upgrade to it.

Welcome to your Vagrant-built virtual machine.
Last login: Fri Sep 14 06:22:31 2012 from 10.0.2.2

vagrant@precise32:~$ pwd
/home/vagrant
vagrant@precise32:~$ whoami
vagrant

ひとまず仮想マシンを立ててアクセスできるようになりました。

しかし何がどうなっているのか全然理解できていないので、railsの開発環境を仮想マシン上に作るという目標に向かってこれから触っていきます。

0