はじめに
MacでVirtualBox+Vagrant+CentOS環境を作成した+ちょっと躓いたのでメモ
環境
- Mac OSX 10.13.2
- VirtualBox 5.2.4
- Vagrant 2.0.1
Virtualboxのインストール
https://www.virtualbox.org/wiki/Downloads
本家サイトからpkgファイルをDL、普通にインストールする
(今回のバージョンは5.2.4)
Vagrantのインストール
https://www.vagrantup.com/downloads.html
本家サイトからpkgファイルをDL、普通にインストールする
(今回のバージョンは2.0.1)
# vagrant --version
Vagrant 2.0.1
Boxのインストール
http://www.vagrantbox.es/
本家サイトよりお目当てのBoxのURLを取得しコマンドにてインストール
- 今回はCentOS7を使用する
- CentOS 7 x64 (Minimal, Shrinked, Guest Additions 4.3.26) (Monthly updates)
- コマンドはvagrant box add <ホスト名> <CopyしたBoxのURL>
なんかエラーが出た
$ vagrant box add CentOS7 https://github.com/holms/vagrant-centos7-box/releases/download/7.1.1503.001/CentOS-7.1.1503-x86_64-netboot.box
==> box: Box file was not detected as metadata. Adding it directly...
==> box: Adding box 'CentOS7' (v0) for provider:
box: Downloading: https://github.com/holms/vagrant-centos7-box/releases/download/7.1.1503.001/CentOS-7.1.1503-x86_64-netboot.box
An error occurred while downloading the remote file. The error
message, if any, is reproduced below. Please fix this error and try
again.
OpenSSL SSL_read: SSL_ERROR_SYSCALL, errno 50
どうやらSSLでの接続がうまくいってないみたい?
なのでHTTPS接続時にSSL認証をチェックしない様にする--insecureオプションをつけた
$ vagrant box add --insecure CentOS7 https://github.com/holms/vagrant-centos7-box/releases/download/7.1.1503.001/CentOS-7.1.1503-x86_64-netboot.box
==> box: Box file was not detected as metadata. Adding it directly...
==> box: Adding box 'CentOS7' (v0) for provider:
box: Downloading: https://github.com/holms/vagrant-centos7-box/releases/download/7.1.1503.001/CentOS-7.1.1503-x86_64-netboot.box
==> box: Box download is resuming from prior download progress
==> box: Successfully added box 'CentOS7' (v0) for 'virtualbox'!
うまくいった。
仮想マシンの起動まで
仮想マシンを稼働させるためのVagrantファイルを作る作業ディレクトリが必要となるため、適当に作成してvagrant init
コマンドで準備する。
$ mkdir ~/Vagrant/CentOS7
$ 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.
ここまでできればあとはvagrant up
で仮想マシンが起動できる。
# vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'CentOS7'...
==> default: Matching MAC address for NAT networking...
==> default: Setting the name of the VM: CentOS7_default_1514128510858_77752
==> 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:
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: 5.0.0
default: VirtualBox Version: 5.2
==> default: Mounting shared folders...
default: /vagrant => /Users/<user_name>/Vagrant/CentOS7
一応、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`.
大丈夫っぽい。
SSHで繋いでみる
起動したVagrantの仮想マシンではvagrant ssh
コマンドでSSHログインできる。
# vagrant ssh
Welcome to your Vagrant-built virtual machine.
[vagrant@localhost ~]$cat /etc/redhat-release
CentOS Linux release 7.1.1503 (Core)
ちゃんとCentOS7で立ち上がっているみたい。
参考
MacにVagrant + VirtualBox + CentOSでWEB開発環境を構築しておいた その1
VagrantでリモートのboxをaddしようとしたらSSL read: error:00000000:lib(0):func(0):reason(0)で止まる
Vagrant コマンドラインインターフェース BOX