LoginSignup
3
2

More than 5 years have passed since last update.

windows10でvagrantをつかってみる

Last updated at Posted at 2017-11-26

Qiitaに何か書いてみる+Vagrantお試しメモです

Vagrantについて
知る前はいまいちイメージがつかなくて、dockerのような新しいタイプの仮想化なのかなと思ってたのですが、要するにVirtualBoxでのOSとかミドルウェア構築を簡易化できるツールって感じですね。誰かが配布してくれてるOSとかミドルウェアの構築済みイメージを利用して、そこの構築を簡易化できると。
*VirtualBox限定ではないですけど

手順はとっても簡単でした。
以下のところだけ引っかかったので、先に確認しておくと良いです

  • BIOSで仮想化テクノロジーを有効化しておく
    • 私のHPのPCでは電源投入時にF10でBIOSを起動して、System Configuration -> Virtualization TechnologyをDisabledからEnabledに変更しました
    • Qiitaやインターネット上の情報を見て自分のPCでもやってみた感じですが、AMDの1.8GHzのCPUを載せた安価なPCでも設定があったことに感動しました
  • VirtualBoxは最新ではなく5.1以下をインストールする
    • 5.2はVagrantが対応してません

手順は以下のような感じです(試して失敗したところも時系列で書いてるので、実際にインストールするために参考にしてくださる方は、一旦最後まで読み切ってから参考にしてください)。

まずvagrantのインストーラをDLしてインストールする

インストールできたら、以下コマンドでPathが通っていること(vagrantコマンドが打てること)を確認できます

C:\Users\Administrator>vagrant -v

Oracle Virtual BoxのインストーラをDLしてインストールする

コマンドプロンプトを起動して仮想マシンイメージを保存するフォルダを作る

C:\Users\Administrator>cd C:\
C:\>
C:\>mkdir vagrant
C:\>
C:\>cd vagrant
C:\vagrant>

今回はVagrantを試してみたいだけなので利用してみるOSはなんでも良いのですが、せっかくなのでubuntuの最新にしてみました。bentoで配布されてるものが良さそうです

C:\vagrant>vagrant init bento/ubuntu-17.04
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:\vagrant>
C:\vagrant>vagrant up --provider virtualbox
The provider 'virtualbox' that was requested to back the machine
'default' is reporting that it isn't usable on this system. The
reason is shown below:

Vagrant has detected that you have a version of VirtualBox installed
that is not supported by this version of Vagrant. Please install one of
the supported versions listed below to use Vagrant:

4.0, 4.1, 4.2, 4.3, 5.0, 5.1

A Vagrant update may also be available that adds support for the version
you specified. Please check www.vagrantup.com/downloads.html to download
the latest version.

C:\vagrant>

VirtualBoxのバージョン選ぶのかorz
(リファレンスとか読まずに適当にやってるのでまあ良いのですが)
5.1以下が必要だったらしいので、プログラムと機能からアンインストールして5.1をインストール

インストーラのDLページ
https://www.virtualbox.org/wiki/Download_Old_Builds_5_1
今回利用したバージョン: 5.1.30

気を取り直してもう一度

C:\vagrant>vagrant up --provider virtualbox
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Box 'bento/ubuntu-17.04' could not be found. Attempting to find and install...
    default: Box Provider: virtualbox
    default: Box Version: >= 0
==> default: Loading metadata for box 'bento/ubuntu-17.04'
    default: URL: https://atlas.hashicorp.com/bento/ubuntu-17.04
==> default: Adding box 'bento/ubuntu-17.04' (v201710.25.0) for provider: virtualbox
    default: Downloading: https://vagrantcloud.com/bento/boxes/ubuntu-17.04/versions/201710.25.0/providers/virtualbox.box
    default: Progress: 100% (Rate: 3887k/s, Estimated time remaining: --:--:--)
==> default: Successfully added box 'bento/ubuntu-17.04' (v201710.25.0) for 'virtualbox'!
==> default: Importing base box 'bento/ubuntu-17.04'...
==> default: Matching MAC address for NAT networking...
==> default: Checking if box 'bento/ubuntu-17.04' is up to date...
==> default: Setting the name of the VM: Vagrant_default_1511598367125_25864
==> 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
Timed out while waiting for the machine to boot. This means that
Vagrant was unable to communicate with the guest machine within
the configured ("config.vm.boot_timeout" value) time period.

If you look above, you should be able to see the error(s) that
Vagrant had when attempting to connect to the machine. These errors
are usually good hints as to what may be wrong.

If you're using a custom box, make sure that networking is properly
working and you're able to connect to the machine. It is a common
problem that networking isn't setup properly in these boxes.
Verify that authentication configurations are also setup properly,
as well.

If the box appears to be booting properly, you may want to increase
the timeout ("config.vm.boot_timeout") value.

C:\vagrant>

成功したのかな?
ubuntuにSSHで接続するための情報を表示してみる

C:\vagrant> vagrant ssh-config
Host default
  HostName 127.0.0.1
  User vagrant
  Port 2222
  UserKnownHostsFile /dev/null
  StrictHostKeyChecking no
  PasswordAuthentication no
  IdentityFile C:/Users/user/.vagrant.d/insecure_private_key
  IdentitiesOnly yes
  LogLevel FATAL


C:\vagrant>

こちらの簡易表示でも十分です

C:\vagrant>vagrant ssh
`ssh` executable not found in any directories in the %PATH% variable. Is an
SSH client installed? Try installing Cygwin, MinGW or Git, all of which
contain an SSH client. Or use your favorite SSH client with the following
authentication information shown below:

Host: 127.0.0.1
Port: 2222
Username: vagrant
Private key: C:/Users/user/.vagrant.d/insecure_private_key

C:\vagrant>

Teratermで127.0.0.1:2222にアクセス
ユーザ名: vagrant
パスワードは空白で。
SSH鍵: 表示されたもの(C:\Users\user.vagrant.dフォルダに移動して、ファイルの種類ですべてを選択すると、insecure_private_keyというファイルが表示されます)
*ポート番号が2222なのが面白いと思いました。ただここを変えるのは結構面倒なようです(Qiitaに記事あり)

しかし・・
- OKをクリックしても反応がない
- OKを連打すると、入力画面は閉じてDOS窓だけ残された状態になるけど反応がない
- しばらくするとSSHエラーが発生してTeratermが落ちる

冒頭で書いたように、VagrantはVirtualBox(とかの仮想化ソフト)の補助ツールでありVirtualBoxが実体ということが分かったので、スタートメニューからVirtualBoxを開いてみると、状態が一時停止になってる。
VirtualBoxの操作で直接起動をかけてみようとすると・・

ホストマシンの仮想化支援機能(VT-x/AMD-V)が使用できません。
64ビット ゲストOSは64ビットCPUを検出できず、起動できません。

なるほど、これは接続できんわ。
でもTeratermでつないだときに、一切反応がないなら分かるけど、ユーザー名とか聞いてきたりしてるので接続可能状態と勘違いしたよ。。sshdデーモンが半端に起動してるような状態なんだろうか?

このエラーの解消は、調べてみるとBIOS触るらしい。
Boot Sequence以外で最近BIOS触ることってないなあ~
*ESXiで仮想マシンの入れなおすときに起動順序を光学ドライブ優先にしてインストールDVD読み込ませたりとかくらい

以下、冒頭に書いた繰り返しですが、これをやります

  • BIOSで仮想化テクノロジーを有効化する
    • 私のHPのPCでは電源投入時にF10でBIOSを起動して、System Configuration -> Virtualization TechnologyをDisabledからEnabledに変更しました

そのあとvagrant upを実行したら、VirtualBox上でも仮想マシンのステータスが実行中となり、Teratermからubuntuに接続できるようになりました!
*vagrant upのときに--provierはつけなくても良くなってました(記憶してくれた?)。
*rubyのエラーはでてますが気にしてません

C:\vagrant>vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Checking if box 'bento/ubuntu-17.04' is up to date...
==> 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
C:/Program Files/HashiCorp/Vagrant/embedded/gems/gems/net-ssh-4.1.0/lib/net/ssh/transport/server_version.rb:54:in `readpartial': An established connection was aborted by the software in your host machine. (Errno::ECONNABORTED)
        from C:/Program Files/HashiCorp/Vagrant/embedded/gems/gems/net-ssh-4.1.0/lib/net/ssh/transport/server_version.rb:54:in `block (2 levels) in negotiate!'
        from C:/Program Files/HashiCorp/Vagrant/embedded/gems/gems/net-ssh-4.1.0/lib/net/ssh/transport/server_version.rb:52:in `loop'
        from C:/Program Files/HashiCorp/Vagrant/embedded/gems/gems/net-ssh-4.1.0/lib/net/ssh/transport/server_version.rb:52:in `block in negotiate!'
        from C:/Program Files/HashiCorp/Vagrant/embedded/gems/gems/net-ssh-4.1.0/lib/net/ssh/transport/server_version.rb:50:in `loop'
        from C:/Program Files/HashiCorp/Vagrant/embedded/gems/gems/net-ssh-4.1.0/lib/net/ssh/transport/server_version.rb:50:in `negotiate!'
        from C:/Program Files/HashiCorp/Vagrant/embedded/gems/gems/net-ssh-4.1.0/lib/net/ssh/transport/server_version.rb:32:in `initialize'
        from C:/Program Files/HashiCorp/Vagrant/embedded/gems/gems/net-ssh-4.1.0/lib/net/ssh/transport/session.rb:84:in `new'
        from C:/Program Files/HashiCorp/Vagrant/embedded/gems/gems/net-ssh-4.1.0/lib/net/ssh/transport/session.rb:84:in `initialize'
        from C:/Program Files/HashiCorp/Vagrant/embedded/gems/gems/net-ssh-4.1.0/lib/net/ssh.rb:233:in `new'
        from C:/Program Files/HashiCorp/Vagrant/embedded/gems/gems/net-ssh-4.1.0/lib/net/ssh.rb:233:in `start'
        from C:/Program Files/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.9.4/plugins/communicators/ssh/communicator.rb:397:in `block (2 levels) in connect'
        from C:/Program Files/HashiCorp/Vagrant/embedded/lib/ruby/2.2.0/timeout.rb:88:in `block in timeout'
        from C:/Program Files/HashiCorp/Vagrant/embedded/lib/ruby/2.2.0/timeout.rb:32:in `block in catch'
        from C:/Program Files/HashiCorp/Vagrant/embedded/lib/ruby/2.2.0/timeout.rb:32:in `catch'
        from C:/Program Files/HashiCorp/Vagrant/embedded/lib/ruby/2.2.0/timeout.rb:32:in `catch'
        from C:/Program Files/HashiCorp/Vagrant/embedded/lib/ruby/2.2.0/timeout.rb:103:in `timeout'
        from C:/Program Files/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.9.4/plugins/communicators/ssh/communicator.rb:371:in `block in connect'
        from C:/Program Files/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.9.4/lib/vagrant/util/retryable.rb:17:in `retryable'
        from C:/Program Files/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.9.4/plugins/communicators/ssh/communicator.rb:370:in `connect'
        from C:/Program Files/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.9.4/plugins/communicators/ssh/communicator.rb:68:in `block in wait_for_ready'
        from C:/Program Files/HashiCorp/Vagrant/embedded/lib/ruby/2.2.0/timeout.rb:88:in `block in timeout'
        from C:/Program Files/HashiCorp/Vagrant/embedded/lib/ruby/2.2.0/timeout.rb:32:in `block in catch'
        from C:/Program Files/HashiCorp/Vagrant/embedded/lib/ruby/2.2.0/timeout.rb:32:in `catch'
        from C:/Program Files/HashiCorp/Vagrant/embedded/lib/ruby/2.2.0/timeout.rb:32:in `catch'
        from C:/Program Files/HashiCorp/Vagrant/embedded/lib/ruby/2.2.0/timeout.rb:103:in `timeout'
        from C:/Program Files/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.9.4/plugins/communicators/ssh/communicator.rb:46:in `wait_for_ready'
        from C:/Program Files/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.9.4/lib/vagrant/action/builtin/wait_for_communicator.rb:16:in `block in call'

C:\vagrant>

おしまい

3
2
1

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
3
2