TIL

Today I Learned. 知ったこと、学んだことを書いていく

Vagrant で Debian 環境構築 ver.共有フォルダの設定できていない

共有フォルダの設定をすることが課題

$ vagrant -v
Vagrant 1.8.6

VagrantDebianの環境構築

ここのサイトを参考にインストールを行う

base boxをダウンロードする

VirtualBoxからバニラのDebianのbase box をダウンロードする

$ vagrant box add https://atlas.hashicorp.com/debian/boxes/jessie64/ --provider virtualbox
==> box: Loading metadata for box 'https://atlas.hashicorp.com/debian/boxes/jessie64/'
==> box: Adding box 'debian/jessie64' (v8.8.1) for provider: virtualbox
    box: Downloading: https://app.vagrantup.com/debian/boxes/jessie64/versions/8.8.1/providers/virtualbox.box
    box:
==> box: Successfully added box 'debian/jessie64' (v8.8.1) for 'virtualbox'!

ボックスのリストをダウンロードする

$ vagrant box list
debian/jessie64    (virtualbox, 8.8.1)

Vagrant環境の作成と設定

環境設定を格納するためのディレクトvagrant_leaning を作成する

$ mkdir vagrant_leaning

カレントディレクトリをvagrant_leaningに変更する

$ cd vagrang_leaning

デフォルトの仮想環境を初期化する

$ vagrant init debian/jessie64
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.

日本語訳してみると

Vagrantfileがこのディレクトリに置かれました。 あなたは今、あなたの最初の仮想環境を「vagrant up」する準備が整いました! Vagrantファイルのコメントや、Vagrantの使用方法の詳細については、 vagrantup.comのドキュメントをお読みください。

早速起動してみる

$ vagrant up

するとエラーが出て起動できなかった…

Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'debian/jessie64'...
==> default: Matching MAC address for NAT networking...
==> default: Checking if box 'debian/jessie64' is up to date...
==> default: Setting the name of the VM: vagrant_learning_default_1500470447808_59330
"rsync" could not be found on your PATH. Make sure that rsync
is properly installed on your system and available on the PATH.
この部分がなんか怪しい

rsync” could not be found on your PATH. Make sure that rsync is properly installed on your system and available on the PATH.

んで、日本語に訳してみる

rsync"がPATHに見つかりませんでした。 rsyncがシステムに正しくインストールされており、PATHで使用可能であることを確認してください。

rsyncってなんだ…

ファイル転送を行うソフトウェア

だそうです。

結構前にrsyncはインストールしたはず!

と思って、コマンドプロンプトで確認したところ、rsyncがインストールされていることが確認できた。

C:\Users\takuya>rsync
rsync  version 3.1.2  protocol version 31
Copyright (C) 1996-2015 by Andrew Tridgell, Wayne Davison, and others.
Web site: http://rsync.samba.org/
Capabilities:
    64-bit files, 64-bit inums, 64-bit timestamps, 64-bit long ints,
    socketpairs, hardlinks, symlinks, IPv6, batchfiles, inplace,
    append, ACLs, no xattrs, iconv, symtimes, prealloc
(以下略)
Msys2でやっているからrsyncのパスを見れていないのでは!?

ということで、 Msys2ではWindows環境変数を引き継ぐように設定する

Windows環境変数MSYS2_PATH_TYPEinheritを設定する

環境変数を引き継いだ後に再度起動してみる
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Checking if box 'debian/jessie64' is up to date...
==> 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: Running 'pre-boot' VM customizations...
==> 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: No guest additions were detected on the base box for this VM! Guest
    default: additions are required for forwarded ports, shared folders, host only
    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 properly,
    default: in which case you may ignore this message.
==> default: Installing rsync to the VM...
==> default: Rsyncing folder: /d/program/vagrant_learning/ => /vagrant
There was an error when attempting to rsync a synced folder.
Please inspect the error message below for more info.

Host path: /d/program/vagrant_learning/
Guest path: /vagrant
Command: "rsync" "--verbose" "--archive" "--delete" "-z" "--copy-links" "--chmod=ugo=rwX" 
"--no-perms" "--no-owner" "--no-group" "--rsync-path" "sudo rsync" "-e" 
"ssh -p 2222 -o LogLevel=FATAL   -o IdentitiesOnly=yes -o StrictHostKeyChecking=no -o 
UserKnownHostsFile=/dev/null -i 'D:/program/vagrant_learning/.vagrant/machines/default/virtualbox/private_key'" 
"--exclude" ".vagrant/" "/d/program/vagrant_learning/" "vagrant@127.0.0.1:/vagrant"
Error:       1 [main] ssh (3268) C:\msys64\usr\bin\ssh.exe: *** fatal error - cygheap base mismatch detected - 0x180302408/0x1802FF408.
This problem is probably due to using incompatible versions of the cygwin DLL.
Search for cygwin1.dll using the Windows Start->Find/Search facility
and delete all but the most recent version.  The most recent version *should*
reside in x:\cygwin\bin, where 'x' is the drive on which you have
installed the cygwin distribution.  Rebooting is also suggested if you
are unable to find another cygwin DLL.
rsync: safe_read failed to read 4 bytes [sender]: Connection reset by peer (104)
rsync error: error in rsync protocol data stream (code 12) at io.c(276) [sender=3.1.2]

んんんんんんんん、起動できない!!

rsyncのエラーは消えた

エラーを見てみる1

There was an error when attempting to rsync a synced folder. Please inspect the error message below for more info.

日本語訳

同期されたフォルダをrsyncしようとするとエラーが発生しました。詳細については、以下のエラーメッセージを確認してください。

エラーを見てみる2

This problem is probably due to using incompatible versions of the cygwin DLL. Search for cygwin1.dll using the Windows Start->Find/Search facility and delete all but the most recent version. The most recent version should reside in x:\cygwin\bin, where ‘x’ is the drive on which you have installed the cygwin distribution. Rebooting is also suggested if you are unable to find another cygwin DLL.

日本語訳

この問題はおそらく、互換性のないバージョンのcygwin DLLを使用していることが原因です。 Windowsのスタート - >検索/検索機能を使用してcygwin1.dllを検索し、最新のバージョン以外のすべてを削除します。 最新のバージョン*は、x:\ cygwin \ binにあります。ここで、「x」はcygwinディストリビューションをインストールしたドライブです。 別のcygwin DLLが見つからない場合は、再起動もお勧めします。

rsync のエラーはよくわからないから放置

Vagrantfileを編集する

以下のコメントを解除する

# ローカルホスト: 8080に接続すると、ゲストOSの80版ポートに接続される
config.vm.network "forwarded_port", guest: 80, host: 8080

# ホストだけが接続できる 192.168.33.10 を設定する
config.vm.network "private_network", ip: "192.168.33.10"

設定後、最後vagrant upをする

エラーが出てるけど無視して、vagrant sshで接続する

$ vagrant ssh

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
vagrant@jessie:~$ 

接続できた!!!

初期suのユーザー:vagrant / パスワード:vagrant

共有フォルダの設定をすることが課題

参考文献