Domain-Name-System

具有多個可定址 domain.locals 的 Vagrant 單框

  • November 23, 2014

我目前利用 Vagrant 和 Chef 為不同的應用程序配置單獨的 linux VM。

這些應用程序可從主機進行域定址,無需在主機上進行任何其他設置。這是在 linux 客戶機上使用 avahi 實現的。主機然後通過訪客的主機名訪問,例如:

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

我現在要安裝另一個應用程序,用於複製生產伺服器,應該有 2 個 Apache 虛擬主機可在一個 VM 中定址,例如:

myguest3.local    
              -> VM#3
myguest4.local    

我也可以使用 Vagrant/Chef 完全實現這一點,而不需要對主機進行任何修改嗎?

您可以使用 Avahi.EntryGroup.AddRecord: python example通過 Avahi API 宣布別名。

SO上提供了使用腳本的詳細解決方案

有一個 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-hostmanager,它支持 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

引用自:https://serverfault.com/questions/564241