複数のアドレス指定可能な domain.locals を持つ Vagrant 単一ボックス

複数のアドレス指定可能な domain.locals を持つ Vagrant 単一ボックス

現在、Vagrant と Chef を使用して、さまざまなアプリ用に個別の Linux VM をプロビジョニングしています。

これらのアプリはホストからドメイン アドレス指定可能であり、ホスト上で他の設定は必要ありません。これは Linux ゲストの avahi を使用して実現されます。次に、ホストは次のようにゲストのホスト名を介してアクセスします。

myguest1.local -> VM#1
myguest2.local -> VM#2

今、別のアプリをインストールしようとしています。このアプリは、本番サーバーを複製するために、1 つの VM 内でアドレス指定可能な 2 つの Apache 仮想ホストを持つ必要があります。たとえば、次のようになります。

myguest3.local    
               -> VM#3
myguest4.local    

ホストマシンに変更を加えることなく、Vagrant/Chef でこれを完全に実現することもできますか?

答え1

Avahi API の Avahi.EntryGroup.AddRecord を使用してエイリアスを通知できます。Pythonの例

スクリプトを使用するための詳細な解決策はSOで提供

答え2

そのための Vagrant プラグインがあります: vagrant-hostsupdater

githubページからの抜粋:

This plugin adds an entry to your /etc/hosts file on the host system.
On up, resume and reload commands, it tries to add the information, if its not already existant in your hosts file. If it needs to be added, you will be asked for an administrator password, since it uses sudo to edit the file.

On halt and destroy, those entries will be removed again.

もありますvagrantホストマネージャー、Windows マシンをサポートしています。私はまだ使用していないので、フィードバックをお待ちしています。

githubページからの抜粋:

vagrant-hostmanager is a Vagrant 1.1+ plugin that manages the /etc/hosts file on guest machines (and optionally the host). Its goal is to enable resolution of multi-machine environments deployed with a cloud provider where IP addresses are not known in advance.

両方のプラグインはエントリを追加するプロセスを自動化しているようです/etc/hosts

答え3

確かに動作しますが、ホストの /etc/hosts ファイルで仮想ホストのエントリを手動で設定する必要があります。これがホスト マシンで必要な唯一の手順です。

関連情報