新手问题 rails 绑定 80 端口访问 pg 出错

patxiao · 2014年05月22日 · 最后由 patxiao 回复于 2014年05月24日 · 2959 次阅读

绑定 3000 或其它端口正常

执行以下命令出错: rvmsudo rails s -p 80

提示: Warning: can not check /etc/sudoers for secure_path, falling back to call via /usr/bin/env, this breaks rules from /etc/sudoers. Run:

export rvmsudo_secure_path=1

to avoid the warning, put it in shell initialization file to make it persistent.

In case there is no secure_path in /etc/sudoers. Run:

export rvmsudo_secure_path=0

to avoid the warning, put it in shell initialization file to make it persistent.

程序还是启动了,当浏览器访问 ip:80 时候会报错: Started GET "/" for 123.112.109.4 at 2014-05-22 22:44:25 +0800

PG::ConnectionBad (FATAL: Peer authentication failed for user "lpxiao" ): activerecord (4.0.3) lib/active_record/connection_adapters/postgresql_adapter.rb:831:in initialize' activerecord (4.0.3) lib/active_record/connection_adapters/postgresql_adapter.rb:831:innew' activerecord (4.0.3) lib/active_record/connection_adapters/postgresql_adapter.rb:831:in connect' activerecord (4.0.3) lib/active_record/connection_adapters/postgresql_adapter.rb:548:ininitialize' activerecord (4.0.3) lib/active_record/connection_adapters/postgresql_adapter.rb:41:in new' activerecord (4.0.3) lib/active_record/connection_adapters/postgresql_adapter.rb:41:inpostgresql_connection' activerecord (4.0.3) lib/active_record/connection_adapters/abstract/connection_pool.rb:440:in new_connection' activerecord (4.0.3) lib/active_record/connection_adapters/abstract/connection_pool.rb:450:incheckout_new_connection' activerecord (4.0.3) lib/active_record/connection_adapters/abstract/connection_pool.rb:421:in acquire_connection' activerecord (4.0.3) lib/active_record/connection_adapters/abstract/connection_pool.rb:356:inblock in checkout' /home/lpxiao/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/monitor.rb:211:in mon_synchronize' activerecord (4.0.3) lib/active_record/connection_adapters/abstract/connection_pool.rb:355:incheckout' activerecord (4.0.3) lib/active_record/connection_adapters/abstract/connection_pool.rb:265:in block in connection' /home/lpxiao/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/monitor.rb:211:inmon_synchronize' activerecord (4.0.3) lib/active_record/connection_adapters/abstract/connection_pool.rb:264:in connection' activerecord (4.0.3) lib/active_record/connection_adapters/abstract/connection_pool.rb:546:inretrieve_connection' activerecord (4.0.3) lib/active_record/connection_handling.rb:79:in retrieve_connection' activerecord (4.0.3) lib/active_record/connection_handling.rb:53:inconnection' activerecord (4.0.3) lib/active_record/query_cache.rb:51:in restore_query_cache_settings' activerecord (4.0.3) lib/active_record/query_cache.rb:43:inrescue in call' activerecord (4.0.3) lib/active_record/query_cache.rb:32:in call' activerecord (4.0.3) lib/active_record/connection_adapters/abstract/connection_pool.rb:626:incall' actionpack (4.0.3) lib/action_dispatch/middleware/callbacks.rb:29:in block in call' activesupport (4.0.3) lib/active_support/callbacks.rb:373:inrun1677853200884953723call_callbacks' activesupport (4.0.3) lib/active_support/callbacks.rb:80:in run_callbacks' actionpack (4.0.3) lib/action_dispatch/middleware/callbacks.rb:27:incall' actionpack (4.0.3) lib/action_dispatch/middleware/reloader.rb:64:in call' actionpack (4.0.3) lib/action_dispatch/middleware/remote_ip.rb:76:incall' actionpack (4.0.3) lib/action_dispatch/middleware/debug_exceptions.rb:17:in call' actionpack (4.0.3) lib/action_dispatch/middleware/show_exceptions.rb:30:incall' railties (4.0.3) lib/rails/rack/logger.rb:38:in call_app' railties (4.0.3) lib/rails/rack/logger.rb:20:inblock in call' activesupport (4.0.3) lib/active_support/tagged_logging.rb:67:in block in tagged' activesupport (4.0.3) lib/active_support/tagged_logging.rb:25:intagged' activesupport (4.0.3) lib/active_support/tagged_logging.rb:67:in tagged' railties (4.0.3) lib/rails/rack/logger.rb:20:incall' actionpack (4.0.3) lib/action_dispatch/middleware/request_id.rb:21:in call' rack (1.5.2) lib/rack/methodoverride.rb:21:incall' rack (1.5.2) lib/rack/runtime.rb:17:in call' activesupport (4.0.3) lib/active_support/cache/strategy/local_cache.rb:83:incall' rack (1.5.2) lib/rack/lock.rb:17:in call' actionpack (4.0.3) lib/action_dispatch/middleware/static.rb:64:incall' rack (1.5.2) lib/rack/sendfile.rb:112:in call' railties (4.0.3) lib/rails/engine.rb:511:incall' railties (4.0.3) lib/rails/application.rb:97:in call' rack (1.5.2) lib/rack/lock.rb:17:incall' rack (1.5.2) lib/rack/content_length.rb:14:in call' rack (1.5.2) lib/rack/handler/webrick.rb:60:inservice'

首先,使用 root 用户跑 web 应用是很危险的,其次,提示信息已经说得很清楚了,除非你不懂那些术语。。

@patxiao PG::ConnectionBad (FATAL: Peer authentication failed for user "lpxiao" ):,问题已经很清楚了吧

#2 楼 @ailen @pynix 我用的 rvmsudo,有 root 权限而非 root 用户,另外 lpxiao 是有 pg 权限的,正文已说明,绑定 1024 以上端口一切正常,我怀疑是 rvmsudo 导致一些环境没有 load

#3 楼 @patxiao 也不是没有可能,不过 bash 脚本调式貌似挺麻烦。

来结贴: 今天使用 root 登录 pg 失败同样报错 PG::ConnectionBad (FATAL: Peer authentication failed for user "lpxiao" 增加 -h 之后成功登录 故在 database.yml 的 host 填写 localhost 后正常运行 又碰到新问题,原因未研究

需要 登录 后方可回复, 如果你还没有账号请 注册新账号