我正在尝试连接两个流浪环境。一个是带有相关postgres数据库的web应用程序。另一个是API应用程序,它调用第一台vagrant机器上的postgres数据库。有谁能就如何实现这一目标提供建议吗。我相信我需要更改database.yml或environment.rb文件,但不确定如何更改。我的vagrantfiles和database.yml文件当前如下:
前端机器漫游文件:
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
前端计算机数据库.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
最佳答案
当我阅读代码时,我没有看到任何配置多台机器的方法。
您可以在使用前通过重新配置来绕过此问题。。
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)
关于ruby-on-rails - 连接两台游民机,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/38345196/