我目前正在尝试连接两个流浪者环境。一个是带有相关postgres数据库的Web应用程序。另一个是API应用程序,它在第一个流浪汉机器上调用postgres数据库。任何人都可以就如何实现这一目标提供建议。我相信我需要更改我的database.yml或envirornment.rb文件,但不太确定如何。我的vagrantfiles和database.yml文件目前是这样的:
前端机器Vagrantfile:
Vagrant.configure("2") do |config|
config.vm.box = "hashicorp/precise64"
config.vm.network "forwarded_port", guest: 3000, host: 3000
config.vm.synced_folder "../Base", "/Base"
config.vm.synced_folder "../api", "/API"
end
前端机器database.yml:
default: &default
adapter: postgresql
database: chsh
development: &development
<<: *default
host: localhost
username: username
password: password
database: database_name
pool: 10
API机器:
Vagrant.configure("2") do |config|
config.vm.box = "hashicorp/precise64"
config.vm.network "forwarded_port", guest: 3002, host: 3002
config.vm.synced_folder "../Base", "/Base"
config.vm.provider "virtualbox" do |vb|
vb.gui = true
end
end
答案 0 :(得分:0)
当我阅读代码时,我没有看到任何配置多台机器的方法。
您可以在使用前通过重新配置来绕过这个..
module Vagrant
def set(name)
send(name) if respond_to?(name)
end
def front_end
Vagrant.configure("2") do |config|
config.vm.box = "hashicorp/precise64"
config.vm.network "forwarded_port", guest: 3000, host: 3000
config.vm.synced_folder "../Base", "/Base"
config.vm.synced_folder "../api", "/API"
end
end
def api
Vagrant.configure("2") do |config|
config.vm.box = "hashicorp/precise64"
config.vm.network "forwarded_port", guest: 3002, host: 3002
config.vm.synced_folder "../Base", "/Base"
config.vm.provider "virtualbox" do |vb|
vb.gui = true
end
end
end
end
然后你就可以做到这样的事情:
Vagrant.set(:front_end)
Vagrant.set(:api)