我刚刚完成了“部署 Rails”一书的工作,但我卡在 capaistrano 调用 db:migrate 的地方。
我已经设置了两个虚拟机——app und db——每个虚拟机都可以完美地工作。虚拟机应用程序托管在 nginx/unicorn 和虚拟机数据库托管 PostgreSQL。我可以“vagrant ssh”进入虚拟机,一切看起来都不错。
这是我定义了两个 VM 的 Vagrant 文件(我使用的是 Vagrant 1.0.3 版):
Vagrant::Config.run do |config|
config.vm.define :app do |app_config|
app_config.vm.customize ["modifyvm", :id, "--name", "app", "--memory", "512"]
app_config.vm.box = "lucid64_rb193_pp2719"
app_config.vm.host_name = "app"
app_config.vm.forward_port 22, 2200, :auto => true
app_config.vm.forward_port 80, 8080
app_config.vm.network :hostonly, "33.33.13.37"
app_config.vm.share_folder "puppet", "/etc/puppet", "../log4job_ops"
end
config.vm.define :db do |db_config|
db_config.vm.customize ["modifyvm", :id, "--name", "db", "--memory", "512"]
db_config.vm.box = "lucid64_rb193_pp2719"
db_config.vm.host_name = "db"
db_config.vm.forward_port 22, 2201, :auto => true
db_config.vm.forward_port 5432, 5432
db_config.vm.network :hostonly, "33.33.13.38"
db_config.vm.share_folder "puppet", "/etc/puppet", "../log4job_ops"
end
end
如您所见,发送到端口 8080 的数据被转发到应用程序 VM 的端口 80,并且运行良好。
当 PostgreSQL 监听端口 5432 时,我设置了 4532(Host)->4532(VM) 的端口转发。
但是,当运行“cap deploy:cold”或“cap deploy:migrate”时,它会收到以下错误消息(cap deploy:migrate):
* executing `deploy:migrate'
* executing "ls -x /var/log4job/releases"
servers: ["localhost"]
[localhost] executing command
command finished in 37ms
* executing "cd /var/log4job/releases/20120905140228 && bundle exec rake RAILS_ENV=production db:migrate"
servers: ["localhost"]
[localhost] executing command
*** [err :: localhost] rake aborted!
*** [err :: localhost] could not connect to server: Connection refused
*** [err :: localhost] Is the server running on host "localhost" and accepting
*** [err :: localhost] TCP/IP connections on port 5432?
*** [err :: localhost] could not connect to server: Connection refused
*** [err :: localhost] Is the server running on host "localhost" and accepting
*** [err :: localhost] TCP/IP connections on port 5432?
*** [err :: localhost]
*** [err :: localhost] Tasks: TOP => db:migrate => environment
*** [err :: localhost] (See full trace by running task with --trace)
command finished in 4128ms
failed: "sh -c 'cd /var/log4job/releases/20120905140228 && bundle exec rake RAILS_ENV=production db:migrate'" on localhost
问题:
我究竟做错了什么?
是在虚拟机“app”上运行的“rake db:migrate”命令。我假设,因为项目源代码部署到 /var/log4job/releases/20120905140228
如果我在上面 nr 2 的假设是正确的,难怪它不起作用。PostgreSQL 在虚拟机“db”上运行。但是你到底是如何设置这种类型的服务的呢?我是否在 database.yml 中配置了错误的数据库连接。
这是 database.yml 的生产部分:
production:
adapter: postgresql
template: template0
username: log4jobuid
password: log4jobpwd
database: wl_prod
host: localhost
encoding: unicode
port: 5432
舒尔。它说它应该听“localhost”;-) 但是我如何配置它,以连接到另一个 VM(“db”VM)?
欢迎任何提示!谢谢!