ruby-on-rails - 数据库 :migrate (PostgreSQL) fails on Rails deployment with Capistrano

标签 ruby-on-rails centos web-deployment

我完全是部署 Rails 的菜鸟,甚至是 PostgreSQL 的新手。我正在运行 CentOS 6.6 服务器,并且我的部署任务不断失败,并出现以下 db:migrate 错误:

cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing as deploy@xxx.xxx.xxx.xxx: rake exit status: 1
rake stdout: /var/www/rally_app/shared/bundle/ruby/2.2.0/gems/fog-1.23.0/lib/fog/rackspace/mock_data.rb:42: warning: duplicated key at line 80 ignored: "name"
rake aborted!
PG::ConnectionBad: FATAL:  no pg_hba.conf entry for host "::1", user "me", database "pg_sampleapp", SSL off
/var/www/rally_app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/postgresql_adapter.rb:651:in `initialize'
/var/www/rally_app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/postgresql_adapter.rb:651:in `new'
/var/www/rally_app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/postgresql_adapter.rb:651:in `connect'
/var/www/rally_app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/postgresql_adapter.rb:242:in `initialize'
/var/www/rally_app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/postgresql_adapter.rb:44:in `new'
/var/www/rally_app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/postgresql_adapter.rb:44:in `postgresql_connection'
/var/www/rally_app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:436:in `new_connection'
/var/www/rally_app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:446:in `checkout_new_connection'
/var/www/rally_app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:422:in `acquire_connection'
/var/www/rally_app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:349:in `block in checkout'
/var/www/rally_app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:348:in `checkout'
/var/www/rally_app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:263:in `block in connection'
/var/www/rally_app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:262:in `connection'
/var/www/rally_app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:565:in `retrieve_connection'
/var/www/rally_app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_handling.rb:113:in `retrieve_connection'
/var/www/rally_app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_handling.rb:87:in `connection'
/var/www/rally_app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/migration.rb:913:in `initialize'
/var/www/rally_app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/migration.rb:820:in `new'
/var/www/rally_app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/migration.rb:820:in `up'
/var/www/rally_app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/migration.rb:798:in `migrate'
/var/www/rally_app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/tasks/database_tasks.rb:137:in `migrate'
/var/www/rally_app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/railties/databases.rake:44:in `block (2 levels) in <top (required)>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
rake stderr: Nothing written
/home/me/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/sshkit-1.7.1/lib/sshkit/runners/parallel.rb:16:in `rescue in block (2 levels) in execute'
/home/me/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/sshkit-1.7.1/lib/sshkit/runners/parallel.rb:12:in `block (2 levels) in execute'
SSHKit::Command::Failed: rake exit status: 1
rake stdout: /var/www/rally_app/shared/bundle/ruby/2.2.0/gems/fog-1.23.0/lib/fog/rackspace/mock_data.rb:42: warning: duplicated key at line 80 ignored: "name"
rake aborted!
PG::ConnectionBad: FATAL:  no pg_hba.conf entry for host "::1", user "me", database "pg_sampleapp", SSL off
/var/www/rally_app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/postgresql_adapter.rb:651:in `initialize'
/var/www/rally_app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/postgresql_adapter.rb:651:in `new'
/var/www/rally_app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/postgresql_adapter.rb:651:in `connect'
/var/www/rally_app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/postgresql_adapter.rb:242:in `initialize'
/var/www/rally_app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/postgresql_adapter.rb:44:in `new'
/var/www/rally_app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/postgresql_adapter.rb:44:in `postgresql_connection'
/var/www/rally_app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:436:in `new_connection'
/var/www/rally_app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:446:in `checkout_new_connection'
/var/www/rally_app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:422:in `acquire_connection'
/var/www/rally_app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:349:in `block in checkout'
/var/www/rally_app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:348:in `checkout'
/var/www/rally_app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:263:in `block in connection'
/var/www/rally_app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:262:in `connection'
/var/www/rally_app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:565:in `retrieve_connection'
/var/www/rally_app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_handling.rb:113:in `retrieve_connection'
/var/www/rally_app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_handling.rb:87:in `connection'
/var/www/rally_app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/migration.rb:913:in `initialize'
/var/www/rally_app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/migration.rb:820:in `new'
/var/www/rally_app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/migration.rb:820:in `up'
/var/www/rally_app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/migration.rb:798:in `migrate'
/var/www/rally_app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/tasks/database_tasks.rb:137:in `migrate'
/var/www/rally_app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/railties/databases.rake:44:in `block (2 levels) in <top (required)>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
rake stderr: Nothing written
/home/me/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/sshkit-1.7.1/lib/sshkit/command.rb:95:in `exit_status='
/home/me/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/sshkit-1.7.1/lib/sshkit/backends/netssh.rb:179:in `block in _execute'
/home/me/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/sshkit-1.7.1/lib/sshkit/backends/netssh.rb:133:in `tap'
/home/me/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/sshkit-1.7.1/lib/sshkit/backends/netssh.rb:133:in `_execute'
/home/me/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/sshkit-1.7.1/lib/sshkit/backends/netssh.rb:66:in `execute'
/home/me/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/capistrano-rails-1.1.3/lib/capistrano/tasks/migrations.rake:16:in `block (5 levels) in <top (required)>'
/home/me/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/sshkit-1.7.1/lib/sshkit/backends/abstract.rb:85:in `with'
/home/me/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/capistrano-rails-1.1.3/lib/capistrano/tasks/migrations.rake:15:in `block (4 levels) in <top (required)>'
/home/me/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/sshkit-1.7.1/lib/sshkit/backends/abstract.rb:77:in `within'
/home/me/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/capistrano-rails-1.1.3/lib/capistrano/tasks/migrations.rake:14:in `block (3 levels) in <top (required)>'
/home/me/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/sshkit-1.7.1/lib/sshkit/backends/netssh.rb:54:in `instance_exec'
/home/me/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/sshkit-1.7.1/lib/sshkit/backends/netssh.rb:54:in `run'
/home/me/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/sshkit-1.7.1/lib/sshkit/runners/parallel.rb:13:in `block (2 levels) in execute'
Tasks: TOP => deploy:migrate
The deploy has failed with an error: Exception while executing as deploy@xxx.xxx.xxx.xxx: rake exit status: 1
rake stdout: /var/www/rally_app/shared/bundle/ruby/2.2.0/gems/fog-1.23.0/lib/fog/rackspace/mock_data.rb:42: warning: duplicated key at line 80 ignored: "name"
rake aborted!
PG::ConnectionBad: FATAL:  no pg_hba.conf entry for host "::1", user "me", database "pg_sampleapp", SSL off
/var/www/rally_app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/postgresql_adapter.rb:651:in `initialize'
/var/www/rally_app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/postgresql_adapter.rb:651:in `new'
/var/www/rally_app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/postgresql_adapter.rb:651:in `connect'
/var/www/rally_app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/postgresql_adapter.rb:242:in `initialize'
/var/www/rally_app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/postgresql_adapter.rb:44:in `new'
/var/www/rally_app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/postgresql_adapter.rb:44:in `postgresql_connection'
/var/www/rally_app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:436:in `new_connection'
/var/www/rally_app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:446:in `checkout_new_connection'
/var/www/rally_app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:422:in `acquire_connection'
/var/www/rally_app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:349:in `block in checkout'
/var/www/rally_app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:348:in `checkout'
/var/www/rally_app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:263:in `block in connection'
/var/www/rally_app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:262:in `connection'
/var/www/rally_app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:565:in `retrieve_connection'
/var/www/rally_app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_handling.rb:113:in `retrieve_connection'
/var/www/rally_app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_handling.rb:87:in `connection'
/var/www/rally_app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/migration.rb:913:in `initialize'
/var/www/rally_app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/migration.rb:820:in `new'
/var/www/rally_app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/migration.rb:820:in `up'
/var/www/rally_app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/migration.rb:798:in `migrate'
/var/www/rally_app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/tasks/database_tasks.rb:137:in `migrate'
/var/www/rally_app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/railties/databases.rake:44:in `block (2 levels) in <top (required)>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
rake stderr: Nothing written
** Invoke deploy:failed (first_time)
** Execute deploy:failed
[me@localhost rally_app]$ 

谢谢你的帮助。

亚历克西斯

最佳答案

您的用户“我”无权连接到您的数据库。权限在 Postgres 的 pg_hba.conf 中定义.我没用过 CentOS,但据我所知,你应该可以在 /var/lib/pgsql/<your Postgres version>/data 找到那个文件。 .

在文本编辑器中打开配置文件(您可能需要使用 sudo 运行它才能获得编辑权限),然后滚动到最后。

添加这一行:

host    pg_sampleapp             me             ::1/128                 password

给你的用户me访问数据库的权限pg_sampleapp在提供正确的密码之后——但只能来自本地主机,这意味着来自您的服务器本身,而不是从外部连接到它时。

您可以通过替换 pg_sampleapp 使权限更广泛和 meall ,意味着本地所有 Postgres 用户都可以连接到所有数据库。如果你想要额外的方便并且不担心安全性,你也可以替换passwordtrust ,这意味着您可以直接连接而无需提供任何密码:
host    all             all             ::1/128                 trust

添加权限后,需要通过 service postgresql-9.4 restart 重新加载 Postgres (如果您安装了 Postgres 9.4,否则相应地更改版本)。

您可以通过尝试使用psql pg_sampleapp me 登录数据库来测试它是否正常工作。 .如果是这样,请使用 CTRL+D 退出 psql。

Postgres documentation on pg_hba.conf欲了解更多信息——它非常易读且非常详细。

关于ruby-on-rails - 数据库 :migrate (PostgreSQL) fails on Rails deployment with Capistrano,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30289358/

相关文章:

ruby-on-rails - 数据库查询 - 不包括的数组

ruby-on-rails - Rails 服务器不会在 Windows 7 中使用 CTR+C 关闭

ruby-on-rails - 在 Solr 中,如何最大化结果集页面内的可变性?

centos - 如何使用 ZLIB 支持重新编译 HAProxy?

eclipse - 如何将 Web 应用程序部署到 Google App Engine

css - Bootstrap 导航栏居中链接并右对齐其他链接

Django 1.10,Apache 2.4 Serving Basic App on CentOS7 得到 403 Forbidden to/

asp.net-mvc - 同一域上的两个 azure 网站 (webapps)

css - OVH 服务器中没有 CSS 内容的 Symfony 2 应用程序?

docker 登录到 nexus 连接被拒绝