我对部署Rails完全是一个新手,对PostgreSQL更是新手。我正在运行CentOS 6.6服务器,我的部署任务不断失败,出现以下db:migrate errors:
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]$
谢谢你的帮助。
亚历克西斯
您的用户"me"没有连接数据库的权限。权限在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
和me
替换为all
使权限更广,这意味着本地所有Postgres用户都可以连接到所有数据库。如果您想要额外的方便并且不担心安全性,您还可以将password
替换为trust
,这意味着您可以直接连接而无需提供任何密码:
host all all ::1/128 trust
添加权限后,您需要通过service postgresql-9.4 restart
重新加载Postgres(如果您安装的是Postgres 9.4,否则请相应地更改版本)
您可以通过尝试使用psql pg_sampleapp me
登录数据库来测试它是否正确工作。如果是,用CTRL+ d退出psql。
请参阅pg_hba.conf上的Postgres文档以获取更多信息-它非常可读且非常详细