
我目前使用 Vagrant 和 Chef 為不同的應用程式配置單獨的 Linux 虛擬機器。
這些應用程式可以從主機進行網域尋址,無需在主機上進行任何其他設定。這是在 Linux 客戶機上使用 avahi 實現的。然後主機透過訪客的主機名稱進行訪問,例如:
myguest1.local -> VM#1
myguest2.local -> VM#2
我現在要安裝另一個應用程序,用於複製生產伺服器,在一個虛擬機中應該有 2 個可尋址的 Apache 虛擬主機,例如:
myguest3.local
-> VM#3
myguest4.local
我也可以使用 Vagrant/Chef 來完全實現這一點,而不需要對主機進行任何修改嗎?
答案1
答案2
有一個 Vagrant 插件: 流浪者主機更新程序
摘自 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.
還有流浪者主機管理員,支援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 檔案中手動設定虛擬主機的條目。這應該是主機上所需的唯一步驟。