【问题标题】:Passenger/mod_rails fails to initialize in Fedora 12 when starting Apache启动 Apache 时,Passenger/mod_rails 无法在 Fedora 12 中初始化
【发布时间】:2012-09-21 01:40:36
【问题描述】:

我正在使用Passenger设置服务器以在Fedora 12上运行Ruby on Rails应用程序。

我处于安装Passenger的阶段,按照规定进行设置,但是当我重新启动Apache时出现以下错误:

[Wed Jan 13 15:41:38 2010] [notice] caught SIGTERM, shutting down
[Wed Jan 13 15:41:40 2010] [notice] SELinux policy enabled; httpd running as context unconfined_u:system_r:httpd_t:s0
[Wed Jan 13 15:41:40 2010] [notice] suEXEC mechanism enabled (wrapper: /usr/sbin/suexec)
[Wed Jan 13 15:41:40 2010] [error] *** Passenger could not be initialized because of this error: Cannot create FIFO file /tmp/passenger.25235/.guard: Permission denied (13)
[Wed Jan 13 15:41:40 2010] [notice] Digest: generating secret for digest authentication ...
[Wed Jan 13 15:41:40 2010] [notice] Digest: done
[Wed Jan 13 15:41:40 2010] [error] *** Passenger could not be initialized because of this error: Cannot create FIFO file /tmp/passenger.25235/.guard: Permission denied (13)
[Wed Jan 13 15:41:40 2010] [error] python_init: Python version mismatch, expected '2.6', found '2.6.2'.
[Wed Jan 13 15:41:40 2010] [error] python_init: Python executable found '/usr/bin/python'.
[Wed Jan 13 15:41:40 2010] [error] python_init: Python path being used '/usr/lib/python26.zip:/usr/lib/python2.6/:/usr/lib/python2.6/plat-linux2:/usr/lib/python2.6/lib-tk:/usr/lib/python2.6/lib-old:/usr/lib/python2.6/lib-dynload'.
[Wed Jan 13 15:41:40 2010] [notice] mod_python: Creating 4 session mutexes based on 256 max processes and 0 max threads.
[Wed Jan 13 15:41:40 2010] [notice] mod_python: using mutex_directory /tmp 
[Wed Jan 13 15:41:40 2010] [notice] Apache/2.2.14 (Unix) DAV/2 Phusion_Passenger/2.2.9 PHP/5.3.0 mod_python/3.3.1 Python/2.6.2 mod_ssl/2.2.14 OpenSSL/1.0.0-fips-beta3 mod_perl/2.0.4 Perl/v5.10.0 configured -- resuming normal operations

如您所见,Passenger 尝试初始化时出现权限问题:

[Wed Jan 13 15:41:40 2010] [error] *** Passenger could not be initialized because of this error: Cannot create FIFO file /tmp/passenger.25235/.guard: Permission denied (13)

当 Apache 启动时,它会在 /tmp 中创建一个文件:

d-ws--x--x. 2 root  root  4096 2010-01-13 16:04 passenger.26117

如果我通过直接使用 mongrel_rails start -e production 启动 mongrel 来运行应用程序,我会看到以下内容:

ActiveRecord::StatementInvalid (Mysql::Error: Can't create/write to file '/tmp/#sql_5d3_0.MYI' (Errcode: 13): SHOW FIELDS FROM `users`):

错误再次指向 /tmp 目录的权限问题。

我不知道解决方案是什么。我不确定这是否与目录权限或 Fedora 的 SELinux 安全性有关。

任何帮助将不胜感激。谢谢。

【问题讨论】:

    标签: ruby-on-rails passenger fedora mod-rails


    【解决方案1】:

    我和 Fred 做了同样的事情,只是没有一次只做一个错误:

    1. 通过运行setenforce 0 进入许可模式
    2. 重新启动 apache,然后访问您的站点并正常使用一段时间
    3. 运行grep httpd /var/log/audit/audit.log | audit2allow -M passenger
    4. semodule -i passenger.pp
    5. 运行setenforce 1返回强制模式
    6. 重新启动 apache 并测试您的网站 - 希望它应该像以前一样工作!

    请注意,这基本上是Centos SELinux 帮助中过程的具体示例 - 请查看。

    【讨论】:

      【解决方案2】:

      我在 CentOS 5.4 中遇到了同样的问题,SELinux 妨碍了Passenger。

      将 PassengerTempDir 设置为 /var/run/passenger 只会在新目录而不是 /tmp 中为您提供相同的权限错误:

      [Mon Feb 22 11:42:40 2010] [error] *** Passenger could not be initialized because of this error: Cannot create directory '/var/run/passenger/passenger.3686'
      

      然后我可以更改 /var/run/passenger 的安全上下文以克服此错误:

      chcon -R -h -t httpd_sys_content_t /var/run/passenger/
      

      ...这让Passenger可以创建临时目录,但不能创建该目录中的文件:

      [Mon Feb 22 12:07:06 2010] [error] *** Passenger could not be initialized because of this error: Cannot create FIFO file /var/run/passenger/passenger.3686/.guard: Permission denied (13)
      

      奇怪的是,再次重新运行递归 chcon 并没有解决这个错误,它一直死在这一点上,这就是我的 SELinux 知识变得模糊的地方。

      Phusion Passenger guide 6.3.5 和 6.3.7 部分有一些有用的想法,但它们似乎并没有完全解决问题。

      【讨论】:

      • Ert:这基本上也是我所在的地方。最后,我关闭了 SELinux 以使其正常工作。不理想,但现在可以了。
      • 我得出了完全相同的结论。
      【解决方案3】:

      您需要的不仅仅是 httpd_sys_content_t 权限。我使用以下技术来开始:

      • 在审计日志上开始跟踪:tail -f /var/log/audit/audit.log
      • 重新加载 apache:apachectl restart
      • 转到/tmp/目录:cd /tmp
      • 如果只添加 1 行,请使用命令:tail -1 /var/log/audit/audit.log | audit2allow -M httpdfifo
      • 请注意,名称“httpdfifo”只是为了反映已观察到的错误类型而选择的名称。
      • 这将创建一个名为“httpdfifo.pp”的文件。要允许 apache 在您必须发出命令后从此处创建 FIFO:semodule -i httpdfifo.pp
      • 继续执行此操作,直到解决所有审核错误(在运行 Centos 5.4 的系统上需要 4 种不同的权限)

      【讨论】:

        【解决方案4】:

        在开始之前运行setenforce 0 可以让您测试它是否是 SELinux。之后别忘了运行setenforce 1

        【讨论】:

        • 谢谢。它看起来像是 SELinux。在重新启动 Apache 之前运行 setenforce 0 会导致应用程序运行。有什么我可以不禁用 SELinux 的方法吗?
        • audit2whyaudit2allow 可以帮助您制定 SELinux 策略以允许访问,但我会考虑将文件放在其他地方,例如/var/run/passenger 也是如此。
        • 您的建议可能是在 Apache conf 应用程序的 VirtualHost 中将 PassengerTempDir 设置为 /var/run/passenger
        • 我想。我实际上不认识乘客:P
        【解决方案5】:

        我尝试了 Dan Sketcher 和 Fred Appleman 的建议,即重复以下操作:

        yum install setroubleshoot
        echo > /var/log/audit/audit.log # clear irrelevant errors
        cd ~
        service httpd restart # try booting passenger -- audit.log now shows the relevant permission errors
        tail -f /var/log/httpd/error_log # check that passenger is still failing due to permission errors
        sealert -a /var/log/audit/audit.log > selinux-diag.txt # translate the permission errors
        # read and check that you are happy with selinux-diag.txt 
        # and either follow its specific advice, or if it just wants you to grep into audit2allow, then:
        cat /var/log/audit/audit.log | audit2allow -M mypol  # grant everything just denied
        semodule -i mypol.p # commit new permissions
        

        但是在这样做 5 或 6 次之后,我不断遇到新的错误,并且即使在我尝试使用“audit2allow”允许它们之后,也出现了一些相同的错误。 p>

        最后我只是关闭了SELinux,用:

        echo 0 >/selinux/enforce
        

        【讨论】:

          猜你喜欢
          • 2012-02-08
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2014-11-17
          • 2012-11-11
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多