Vagrantの導入メモ+box addのエラー
※2017/03/09 ちょっと更新
こちらのブログを参考にしました。
vdeep.net
環境は以下の通りです。
・Mac OS X ElCapitan (10.11.6)
・iTerm2 (3.0.12)
VagrantとVirtualBoxのインストール
必要なもの
Vagrant 1.8.7
Download -> Mac OS X
VitrualBox 5.1.8
Downloads -> VirtualBox 5.1.8 for OS X hosts amd64
■Vagrantのインストール
実行ファイルpkgをダブルクリック、そのままインストール。
■VirtualBoxのインストール
Vagrantと同じように実行ファイルpkgをダブルクリック、インストール。
■インストールの確認
ターミナルを立ち上げて、以下のコマンドを入力。バージョン確認。
$ vagrant -v Vagrant 1.8.7
Boxの取得とインストール
とりあえずいろんなサイトみてCentOS使ってる方が多いのでCentOS7を使います。
こちらからどうぞ。
Vagrantbox.es
copyをクリックするとコピーできますので、それを以下のコマンドにいれてください。
$ vagrant box add [使うboxの名前] [コピーしたURL]
とりあえず使うboxの名前は「centos7」、コピーしたURLは上のサイトの「CentOS 7.0 x64 (Minimal, VirtualBox Guest Additions 4.3.28, Puppet 3.8.1 - see here for more infos)」です。
できるかと思いやエラーキタ━━━━━(゚∀゚)━━━━━!!!!
テンション爆上がりですね。
$ vagrant box add centos7 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 'centos7' (v0) for provider: box: Downloading: https://github.com/tommy-muehle/puppet-vagrant-boxes/releases/download/1.1.0/centos-7.0-x86_64.box An error occurred while downloading the remote file. The error message, if any, is reproduced below. Please fix this error and try again.
しゃあない、わからんので検索しましょう。
$ rm -rf ~/.vagrant.d/tmp/box*
これでいけるっていう記事が多かったんですけど、そもそもtmpにboxがなかったんですよねー。
多分一度入れたことある環境の場合なんですかね?
で色々悩んでたら知人が解決策が書かれてるブログをぶん投げてくれました。
こちらを参考にしました。
Vagrant1.8.7のcurlが動いてないそうな。わからねーわ_(:3 」∠)_
curlってなんぞやというかたはこちらをどうぞ。
/opt/vagrant/embedded/bin/curlを一度消す。もしcurlが別で入ってたらそれが動きます。
$ vagrant box add centos7 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 'centos7' (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 'centos7' (v0) for 'virtualbox'!
出来たぞー!わーい!
■ターミナルで確認
$ vagrant box list centos7 (virtualbox, 0)
ちゃんと入ってるね。
仮想マシンの初期化
Boxを使って仮想マシンを立ち上げるわけで、仮想マシン毎にディレクトリを作成しました。「~/Vagrant/myCentOS7VM」にあります。
初期化のコマンドは以下の通り。
$ vagrant init [boxの名前]
$ cd ~/Vagrant/myCentOS7VM $ vagrant init centos7 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.
これでOKだと思う。多分。
他にもSSLRead()でエラーがでるケースもあるようです。以下を記事をご覧ください。
qiita.com
仮想マシンを立ち上げる
先程のディレクトリ内で以下のコマンドを実行。
$ vagrant up
で、実行すると以下のようになります。長いので最初のほうだけ。
$ vagrant up Bringing machine 'default' up with 'virtualbox' provider... ==> default: Importing base box 'centos7'... ==> default: Matching MAC address for NAT networking... (省略)
これができたらVirtualBoxで確認。
立ち上がってますね。やった。
仮想マシンの状態確認
$ vagrant status
$ 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`.
running(virtualbox)になってるのでOKですね。