如何在无所事事的虚拟机上访问postgresql? [英] How to access to postgresql on vagranted virtual machine?
问题描述
我通过带有Postgresql的Vagrant虚拟机进行制作,并希望将其用作我的Rails应用数据库。
I make via Vagrant virtual machine with postgresql and want to use it as my rails app database.
我使用类似的Vagrantfile:
I use similar Vagrantfile:
Vagrant.configure("2") do |config|
config.vm.network :private_network, ip: "192.168.33.18"
config.vm.provision :chef_solo do |chef|
# I take cookbook from https://github.com/opscode-cookbooks/postgresql
chef.add_recipe "postgresql::server"
chef.json = {
postgresql: {
config: {
ssl: false,
listen_addresses: '*'
},
password: {
postgres: 'postgres'
}
}
}
end
end
接下来我无所事事
,并期望下一个 database.yml
可以工作:
Next I vagrant up
and expect that next database.yml
will be worked:
development:
database: app_development
adapter: postgresql
host: '192.168.33.18'
username: root
但这不会发生。耙任务失败,并显示错误:
But this is not happen.. Rake task fails with error:
could not connect to server: Connection refused
Is the server running on host "192.168.33.18" and accepting
TCP/IP connections on port 5432?
我看到端口实际上没有打开
And I see that port is actually not opened
$ nmap -p 5432 192.168.33.18
Starting Nmap 6.25 ( http://nmap.org ) at 2013-05-07 22:05 FET
Nmap scan report for 192.168.33.18
Host is up (0.00047s latency).
PORT STATE SERVICE
5432/tcp closed postgresql
我可以看到一些postgres在vm上进行处理,并且在游标输出中没有任何错误,因此我相信postgres可以正常工作。
And I can see some postgres processes on vm, and there no any errors in vagrant output, so I believe postgres works normally.
932 postgres 20 0 126m 9.9m 8916 S 0 2.7 0:00.03
postgres
941 postgres 20 0 97460 1348 192 S 0 0.4 0:00.00 postgres
944 postgres 20 0 126m 1728 548 S 0 0.5 0:00.06 postgres
945 postgres 20 0 126m 1488 316 S 0 0.4 0:00.05 postgres
946 postgres 20 0 126m 2768 1000 S 0 0.7 0:00.00 postgres
947 postgres 20 0 97456 1584 352 S 0 0.4 0:00.00 postgres
如何在我的Rails应用程序中设置Vagrant在虚拟机上使用db?
How to setup Vagrant to use db on virtual machine in my rails app?
更新我 pg_hba.conf
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all peer
###########
# Other authentication configurations taken from chef node defaults:
###########
local all all trust
host all all 0.0.0.0/0 md5
推荐答案
我阿波罗向所有读者开放,但问题出在我的注意力上。尽管我在配置中指向 listen_addresses:'*'
,但是我意外重置了此配置,因此在最终配置中使用了默认的 listen_addresses:'localhost'
值。修复后,该端口打开了。
I apologize to all readers, but problem was in my inattention. Though I point listen_addresses: '*'
in config, then I reset this config accidentally, so in final config was taken default listen_addresses: 'localhost'
value. After fix this port became opened.
这篇关于如何在无所事事的虚拟机上访问postgresql?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!