68
96

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

MacにVagrantとVirtualBoxを入れてみる

Last updated at Posted at 2016-05-25

VagrantとVirtualBoxを入れてみたメモ。

環境

ホスト:MacOSX 10.10.5(14F27)
Vagrant 1.8.1
VirtualBox 5.0.20
ゲスト:CentOS 7.0 x64

vagrantのインストール

ver 1.8.1(2016/5/25時点の最新)
https://www.vagrantup.com/downloads.html

vagrant_1.8.1.dmgをDLしてインストール。後バージョン確認。

$ vagrant --version
Vagrant 1.8.1

VirtualBoxのインストール

VirtualBox 5.0.20(2016/5/25時点の最新)
https://www.virtualbox.org/wiki/Downloads

VirtualBox-5.0.20-106931-OSX.dmgをDLしてインストール。

Boxの追加

http://www.vagrantbox.es/
から該当のBoxを取得できる。
今回は"CentOS 7.0 x64"にする。

  1. URLをコピー
  2. コマンド実行。
    フォーマットは
vagrant box add {name} {url}

なので、とりあえずnameを"centos64"として

$ vagrant box add centos64 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 'centos64' (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: Successfully added box 'centos64' (v0) for 'virtualbox'!

しばらく待って完了。
boxの確認。

$ vagrant box list
centos64 (virtualbox, 0)

余談)・・・つけてからbox名を変えたくなったらboxのディレクトリでmvコマンドで変更できる。

$ cd ~/.vagrant.d/boxes/
$ mv {old} {new}

centosのverにしておけばよかったーとおもったので

$ cd ~/.vagrant.d/boxes/
$ mv centtos64 centos70

で変更完了。確認してみる。

$ vagrant box list
centos70 (virtualbox, 0)

VMの作成&起動

~/Vagrant/CentOS70を作業ディレクトリにしてみます。

$ mkdir -p ~/Vagrant/CentOS70
$ cd Vagrant/CentOS70/

で初期化コマンドを投げる。

$ vagrant init centos70
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.

でできあがり。

$ ls
Vagrantfile

Vagrantfile なるものができている。

起動!

$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'centos70'...
==> default: Matching MAC address for NAT networking...
==> default: Setting the name of the VM: CentOS70_default_1464159432389_76331
==> 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: 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: Warning: Remote connection disconnect. 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 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: Mounting shared folders...
    default: /vagrant => /Users/xxxx/Vagrant/CentOS70

VirtualBoxを見るとCentOSが起動してくれてる。

状態確認!

$ vagrant status
Current machine states:

default                   running (virtualbox)

The VM is running. To stop this VM, you can run `vagrant halt` to
shut it down forcefully, or you can run `vagrant suspend` to simply
suspend the virtual machine. In either case, to restart it again,
simply run `vagrant up`.

停止!

$ vagrant halt
==> default: Attempting graceful shutdown of VM...

Vagrantへ接続

$ vagrant ssh

とりあえずここまで

参考)
http://easyramble.com/install-vagrant-virtualbox-on-mac.html
http://weblabo.oscasierra.net/install-vagrant-onto-macosx/
http://weblabo.oscasierra.net/macosx-vagrant-1/
http://nori3tsu.hatenablog.com/entry/2013/12/28/231257

68
96
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
68
96

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?