在不同的流浪环境中发布帖子

时间:2016-07-13 11:50:35

标签: postgresql curl vagrant

我正在尝试使用两台流浪汉机器来设置环境。一个包含一个应用程序(portal)和一个postgres数据库实例,另一个包含一个API(api),我希望从中运行curl命令来查询门户数据库。

通过在流浪汉中使用私人网络

门户环境

Vagrantfile:

Vagrant.configure("2") do |config|
  config.vm.box = "hashicorp/precise64"
  config.vm.network "forwarded_port", guest: 3000, host: 3000
  config.vm.network "forwarded_port", guest: 5432, host: 5432         -- Fix
  config.vm.network "private_network", ip: "192.168.33.10"
  config.vm.synced_folder "../Base", "/Base"
  config.vm.synced_folder "../alacrity-v2-api", "/API"
end

的database.yml

development: &development
  adapter: postgresql
  database: payments_development
  username: payments
  password: payments
  host:     localhost
  port:     5432
  pool: 10
  reconnect: true
  min_messages: warning

API环境

Vagrantfile:

Vagrant.configure("2") do |config|
  config.vm.box = "hashicorp/precise64"
  config.vm.network "forwarded_port", guest: 3002, host: 3002
  config.vm.network "private_network", ip: "192.168.33.11"     --Fix
  config.vm.synced_folder "../Base", "/Base"
  config.vm.provider "virtualbox" do |vb|
    vb.gui = true
  end

end

的database.yml

development: &development
  adapter: postgresql
  database: chsh
  host: 192.168.33.10
  port: 3000
  username: payments
  password: payments
  database: payments_development
  pool: 10

现在我运行curl命令(出于安全原因删除了基本的auth密码):

curl -v -L http://localhost:9292/v2.2/ -H "Authorization: Basic ??????????????????????????"

在我的API环境中返回以下内容

* About to connect() to localhost port 9292 (#0)
*   Trying 127.0.0.1... connected
> GET /v2.2/ HTTP/1.1
> User-Agent: curl/7.22.0 (x86_64-pc-linux-gnu) libcurl/7.22.0 OpenSSL/1.0.1 zlib/1.2.3.4 libidn/1.23 librtmp/2.3
> Host: localhost:9292
> Accept: */*
> Authorization: Basic emFpbmFnZ3JlZ180MTZfbGl2ZTo4b3Jlc3B1Y3Jv
>
< HTTP/1.1 500 Internal Server Error
< Content-Length: 6866
<
Puma caught this error: received invalid response to SSL negotiation: H
 (PG::ConnectionBad)

在我的Portal环境中,我得到了这个:

Invalid request: Invalid HTTP format, parsing fails.
        /home/vagrant/.rvm/gems/ruby-2.3.0/gems/thin-1.7.0/lib/thin/request.rb:84:in `execute'
        /home/vagrant/.rvm/gems/ruby-2.3.0/gems/thin-1.7.0/lib/thin/request.rb:84:in `parse'
        /home/vagrant/.rvm/gems/ruby-2.3.0/gems/thin-1.7.0/lib/thin/connection.rb:39:in `receive_data'
        /home/vagrant/.rvm/gems/ruby-2.3.0/gems/eventmachine-1.2.0.1/lib/eventmachine.rb:194:in `run_machine'
        /home/vagrant/.rvm/gems/ruby-2.3.0/gems/eventmachine-1.2.0.1/lib/eventmachine.rb:194:in `run'
        /home/vagrant/.rvm/gems/ruby-2.3.0/gems/thin-1.7.0/lib/thin/backends/base.rb:73:in `start'
        /home/vagrant/.rvm/gems/ruby-2.3.0/gems/thin-1.7.0/lib/thin/server.rb:162:in `start'
        /home/vagrant/.rvm/gems/ruby-2.3.0/gems/rack-1.4.7/lib/rack/handler/thin.rb:13:in `run'
        /home/vagrant/.rvm/gems/ruby-2.3.0/gems/rack-1.4.7/lib/rack/server.rb:268:in `start'
        /home/vagrant/.rvm/gems/ruby-2.3.0/gems/railties-3.2.22/lib/rails/commands/server.rb:70:in `start'
        /home/vagrant/.rvm/gems/ruby-2.3.0/gems/railties-3.2.22/lib/rails/commands.rb:55:in `block in <top (required)>'
        /home/vagrant/.rvm/gems/ruby-2.3.0/gems/railties-3.2.22/lib/rails/commands.rb:50:in `tap'
        /home/vagrant/.rvm/gems/ruby-2.3.0/gems/railties-3.2.22/lib/rails/commands.rb:50:in `<top (required)>'
        script/rails:6:in `require'
        script/rails:6:in `<main>'

任何人都可以帮助我了解问题所在或如何解决问题。

1 个答案:

答案 0 :(得分:0)

编辑问题以显示我的工作配置。我认为其中一个主要问题是接受来自其他VM的连接。编辑了pg_hba.conf并添加了

主持所有*信任

基于其他地方的答案。最后添加一些变体以确保我被覆盖。添加的行包括:

托管所有192.168.33.11信任 主持所有192.168.33.11 md5 主持所有*信任

另外看看vagrantfiles。它们可能并不完美,但它让它运转起来,所以我很开心。希望这可以帮助别人把头撞在墙上。