生产服务器设置问题

生产服务器设置问题

我正在尝试在 Ubuntu VPS 服务器上设置 rails 3.0.10。我使用的是 postgres 9.0.4、Apache 和 Passenger。当我运行服务器时,出现此错误:

PGError 无法连接到服务器:没有此文件或目录服务器是否在本地运行并接受 Unix 域套接字“/var/run/postgresql/.s.PGSQL.5432”上的连接?

当然,postgres 服务器正在运行,如果我执行“rails 服务器”,该应用程序就可以与 webbrick 很好地配合使用。

在安装过程中,我以 root 身份安装了 Postgres 和 Apache,而以另一个用户身份使用 rvm 安装了 ruby​​ 和 rails。可能是这样吗?

对于 Linux 用户来说,安装生产服务器的正确方法是什么?以 root 身份安装所有内容,还是创建部署者帐户并使用 sudo 安装 postgres、apache 和 Passenger,甚至可能不使用 sudo?

有什么建议吗?关于生产服务器设置/配置的优秀教程不多。知道一个吗?

巴西雷亚尔

答案1

检查你的 config/database.yml,开发和生产环境可能有不同的 DB 设置。

记得在生产环境(RailsEnv)中创建数据库,或者只需将开发部分下的凭据复制到 config/database.yml 中的生产部分

以 root 身份安装 PG 和 Apache 没有错,这是保护这些程序的正确方法。

RoR 和 rvm 可以以非 root 用户身份安装,为 Apache 和 Passenger 创建另一个用户,使用“sudo”启动 Apache。

确保您为 Apache 设置的用户有权访问日志和上传目录。

答案2

我将 postgres 日志设置为登录信息,但浏览页面时什么都看不到。在 PGAdmin 中操作时,我在日志中看到了一些东西。我意识到 httpd 是以 root 身份运行的,但 postgres 是以用户 postgres 身份运行的。Rails 是以用户 rutger 身份安装的,该用户仅属于 rutger 组。

netstat -an|grep LISTEN

tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN
tcp        0      0 0.0.0.0:10000           0.0.0.0:*               LISTEN
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN
tcp        0      0 0.0.0.0:5432            0.0.0.0:*               LISTEN
tcp        0      0 127.0.0.1:34533         0.0.0.0:*               LISTEN
tcp6       0      0 :::22                   :::*                    LISTEN
tcp6       0      0 :::5432                 :::*                    LISTEN
unix  2      [ ACC ]     STREAM     LISTENING     239555   /tmp/.s.PGSQL.5432
unix  2      [ ACC ]     STREAM     LISTENING     6067     /tmp/passenger.1.0.863/generation-0/spawn-server/socket.876.74943570
unix  2      [ ACC ]     STREAM     LISTENING     6079     /tmp/passenger.1.0.863/generation-0/backends/ruby.<Rutger edited: long key>
unix  2      [ ACC ]     STREAM     LISTENING     6002     /tmp/passenger.1.0.863/generation-0/socket
unix  2      [ ACC ]     STREAM     LISTENING     6006     /tmp/passenger.1.0.863/generation-0/spawn-server/socket.874.163492224
unix  2      [ ACC ]     STREAM     LISTENING     6034     /tmp/passenger.1.0.863/generation-0/logging.socket
unix  2      [ ACC ]     STREAM     LISTENING     5164     /var/run/dbus/system_bus_socket
unix  2      [ ACC ]     STREAM     LISTENING     5934     /var/run/apache2/cgisock.863
unix  2      [ ACC ]     STREAM     LISTENING     3960     @/com/ubuntu/upstart

>ps -Af|grep postgres
postgres  4946     1  0 16:11 pts/0    00:00:00 /opt/postgres/9.0/bin/postgres -D /opt/postgres/9.0/data
postgres  4947  4946  0 16:11 ?        00:00:00 postgres: logger process        
postgres  4949  4946  0 16:11 ?        00:00:00 postgres: writer process        
postgres  4950  4946  0 16:11 ?        00:00:00 postgres: wal writer process    
postgres  4951  4946  0 16:11 ?        00:00:00 postgres: autovacuum launcher process
postgres  4952  4946  0 16:11 ?        00:00:00 postgres: stats collector process
postgres  5012  4946  0 16:13 ?        00:00:00 postgres: postgres postgres 127.0.0.1(58641) idle
postgres  5013  4946  0 16:14 ?        00:00:00 postgres: postgres rktest_production 127.0.0.1(58642) idle
postgres  5023  4946  0 16:14 ?        00:00:00 postgres: postgres rktest_production 127.0.0.1(58643) idle
postgres  5038  4946  0 16:15 ?        00:00:00 postgres: postgres rktest_production 127.0.0.1(58644) idle
root      5274 31100  0 16:22 pts/0    00:00:00 grep --color=auto postgres

>ps -Af|grep httpd
root      5423 31100  0 16:27 pts/0    00:00:00 grep --color=auto httpd

答案3

就是这样!!!

这 ”http://www.openscg.org/se/postgresql/packages.jsp“在 ubuntu 和 debian 上,安装 Postgresql 9.0.4 会将 .s.PGSQL.5432 文件放在 /tmp 中,而不是 /var/run/postgresql 中。

快速而肮脏的解决方案是:

ln -s /tmp postgresql

有人知道到底应该如何修复它吗?

相关内容