スポンサーリンク

【Vagrant + VirtualBox】楽にWindows上に開発環境を作る2(仮想マシンのBoxを選ぶ、起動)

Macでの環境構築はこちら

 

こちら(仮想マシン起動)こちら(環境構築)の記事を参考に作っていく

 

1.vagrantとvirtual boxをインストール

2.vagrantプラグインをインストール

3.仮想マシンのBoxを選ぶ

4.仮想マシンを起動

5.SSHで接続

6.仮想マシン設定

 

前回からの続き

 

3.仮想マシンのBoxを選ぶ

Boxとは仮想マシン起動時のテンプレートとなるイメージファイル。(一般的なISOファイルとは異なる)

https://atlas.hashicorp.com/boxes/search でインストールするBoxファイルを検索します。

「centos」などで検索するといくつもヒットします。

ちなみにBoxファイルは自分でも作れるらしい

 

4.仮想マシンを起動

コマンドプロンプトを起動して任意のディレクトリにvagrant用のフォルダを作って移動

C:Usersr.testDesktopdevelop>mkdir vagrant

C:Usersr.testDesktopdevelop>cd vagrant

C:Usersr.testDesktopdevelop>mkdir centos7

C:Usersr.testDesktopdevelop>cd centos7

 

vagrant boxのサイトでcentos7のもののページを検索して開く

検索して以下のページをみつけた

https://app.vagrantup.com/centos/boxes/7

 

上記ページに書いてある以下画像のnewタブをクリックすると実行するコマンドが書いてある

 

C:Usersr.testDesktopdevelopvagrantcentos7>vagrant init centos/7
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.

C:Usersr.testDesktopdevelopvagrantcentos7>dir
ドライブ C のボリューム ラベルは OS です
ボリューム シリアル番号は A6AB-4CFC です

C:Usersr.testDesktopdevelopvagrantcentos7 のディレクトリ

2017/07/28 15:44 <DIR> .
2017/07/28 15:44 <DIR> ..
2017/07/28 15:44 3,085 Vagrantfile
1 個のファイル 3,085 バイト
2 個のディレクトリ 241,716,002,816 バイトの空き領域

 

Vagrantfileというファイルができているので開く

以下の部分の頭の#を消してコメントアウトを外して保存

config.vm.network “private_network”, ip:

さらにプラグインomnibusを使うため、以下を追記

# vagrant-omnibus
config.omnibus.chef_version = :latest

#ssh setting

#デフォルトでは”bash”が適用されるようでshを指定

config.ssh.shell = “sh”

 

bashが指定されていると起動時に以下のようなエラーが出るっぽい

The configured shell (config.ssh.shell) is invalid

 

Vagrantfileとは仮想マシンの構成を記述するファイル。
主に以下の項目を指定します。

  • 起動する仮想マシン指定
  • ネットワーク設定
  • 共有フォルダ設定
  • マシンスペック設定(CPUやメモリの割り当てなど)
  • プロビジョニング(シェルスクリプトや構成管理ツールの実行指定)

 

次にvagrant upをして仮想マシンを起動してみる

C:Usersr.testDesktopdevelopvagrantcentos7>vagrant up

 

・・・ずっと反応なし

たまらずCtr + cでキャンセル

C:Usersr.testDesktopdevelopvagrantcentos7>Exiting due to interrupt.

 

以降数回試したみたが結果は同じ

調べてみるとこちらのようにvagrant1.9.7の不具合っぽい

windows10だといけるのかな・・・

※windows10だと1.9.7でも動作しました

 

一度1.9.7をコントロールパネルからアンインストールして

一つ前の1.9.6をこちらからダウンロードしてインストール

 

再度vagrant upしてみる

C:Usersr.testDesktopdevelopvagrantcentos7>vagrant up
Bringing machine ‘default’ up with ‘virtualbox’ provider…
==> default: Box ‘centos/7’ could not be found. Attempting to find and install..
.
default: Box Provider: virtualbox
default: Box Version: >= 0
==> default: Loading metadata for box ‘centos/7’
default: URL: https://vagrantcloud.com/centos/7
==> default: Adding box ‘centos/7’ (v1706.02) for provider: virtualbox
default: Downloading: https://vagrantcloud.com/centos/boxes/7/versions/1706.
02/providers/virtualbox.box
default: Progress: 100% (Rate: 5666k/s, Estimated time remaining: –:–:–)
==> default: Successfully added box ‘centos/7’ (v1706.02) for ‘virtualbox’!
==> default: Importing base box ‘centos/7’…
==> default: Matching MAC address for NAT networking…
==> default: Checking if box ‘centos/7’ is up to date…
==> default: Setting the name of the VM: centos7_default_1501475955382_18316
==> default: Fixed port collision for 22 => 2222. Now on port 2200.
==> 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 (guest) => 2200 (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:2200
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: No guest additions were detected on the base box for this VM! Guest

default: additions are required for forwarded ports, shared folders, host on
ly
default: networking, and more. If SSH fails on this machine, please install
default: the guest additions and repackage the box to continue.
default:
default: This is not an error message; everything may continue to work prope
rly,
default: in which case you may ignore this message.
==> default: Configuring and enabling network interfaces…
default: SSH address: 127.0.0.1:2200
default: SSH username: vagrant
default: SSH auth method: private key
==> default: Rsyncing folder: /cygdrive/c/Users/r.test/Desktop/develop/vagrant/
centos7/ => /vagrant

登録されたboxの一覧を表示してみる

C:Usersr.testDesktopdevelopvagrantcentos7>vagrant box list
centos/7 (virtualbox, 1706.02)

成功したようだ

 

次回最終章、SSHで接続、仮想マシン設定を行います

コメント

タイトルとURLをコピーしました