在 CentOS 5.7 上运行金字塔应用程序时,modwsgi 出现分段错误(11)

在 CentOS 5.7 上运行金字塔应用程序时,modwsgi 出现分段错误(11)

尝试访问“Hello World”金字塔应用程序时,我收到分段错误。此错误仅在针对 CentOS 5.7 设置运行时发生,但在针对 OSX 和 Arch Linux 测试时没有任何问题。这可能是 CentOS 特有的问题吗?

[error] [client 10.211.55.2] Premature end of script headers: pyramid.wsgi
[notice] child pid 31212 exit signal Segmentation fault (11)

我尝试按照此处发布的故障排除指南进行操作 http://code.google.com/p/modwsgi/wiki/InstallationIssues 这表明这可能是由于缺少共享库引起的。快速检查发现共享库不是问题所在。

[centos57@localhost modules]$ ldd mod_wsgi.so 
    linux-gate.so.1 =>  (0x00e6a000)
    libpython2.7.so.1.0 => /home/python/lib/libpython2.7.so.1.0 (0x0024c000)
    libpthread.so.0 => /lib/libpthread.so.0 (0x00da8000)
    libdl.so.2 => /lib/libdl.so.2 (0x00cd6000)
    libutil.so.1 => /lib/libutil.so.1 (0x00110000)
    libm.so.6 => /lib/libm.so.6 (0x0085c000)
    libc.so.6 => /lib/libc.so.6 (0x00682000)
    /lib/ld-linux.so.2 (0x0012b000)

然后我找到了另一个可能能够解决我的问题的线索。不幸的是,libexpat 不是问题的根源。 http://code.google.com/p/modwsgi/wiki/IssuesWithExpatLibrary

[centos57@localhost bin]$ ldd ~/httpd/bin/httpd | grep expat
libexpat.so.1 => /usr/local/lib/libexpat.so.1 (0x00b00000)

[centos57@localhost bin]$ strings /usr/local/lib/libexpat.so.1 | grep expat
   libexpat.so.1
   expat_2.0.1

[centos57@localhost bin]$ python
  Python 2.7.2 (default, Nov 26 2011, 08:08:44) 
  [GCC 4.1.2 20080704 (Red Hat 4.1.2-51)] on linux2
  Type "help", "copyright", "credits" or "license" for more information.
  >>> import pyexpat
  >>> pyexpat.version_info
  (2, 0, 0)
  >>> 

我一直苦苦思索,想弄清楚我的设置中缺少了什么。为什么问题只发生在 CentOS 上?

以下是详细设置:

Apache 2.2.19
Python 2.7.2
mod_wsgi-3.3

/home/httpd/conf/extra/pyramid.wsgi

from pyramid.paster import get_app
application = get_app('/home/homecamera/hcadmin/root/production.ini', 'main')

/home/httpd/conf/extra/modwsgi.conf

LoadModule wsgi_module modules/mod_wsgi.so
WSGIScriptAlias /myapp /home/root/test.wsgi
<Directory /home/root>
  WSGIProcessGroup pyramid
  Order allow,deny
  Allow from all
</Directory>

# Use only 1 Python sub-interpreter.  Multiple sub-interpreters
# play badly with C extensions.

WSGIApplicationGroup %{GLOBAL}
WSGIPassAuthorization On
WSGIDaemonProcess pyramid user=daemon group=daemon processes=1 \
  threads=4 \
  python-path=/home/python/lib/python2.7/site-packages
WSGIScriptAlias /hello /home/httpd/conf/extra/pyramid.wsgi

<Directory /home/httpd/conf/extra>
  WSGIProcessGroup pyramid
  Order allow,deny
  Allow from all
</Directory>

同样,此设置适用于 OSX 和 Arch Linux,但不适用于 CentOS 5.7。有人能给我指出正确的方向吗,以免我手忙脚乱。

====================================================================================

当 apache 使用 gdb 启动时,我收到了几个警告

Reading symbols from /home/httpd/bin/httpd...done.
Attaching to program: /home/httpd/bin/httpd, process 1821

warning: .dynamic section for "/lib/libcrypt.so.1" is not at the expected address

warning: difference appears to be caused by prelink, adjusting expectations

warning: .dynamic section for "/lib/libutil.so.1" is not at the expected address

warning: difference appears to be caused by prelink, adjusting expectations

gdb 输出。点击刷新按钮后,加载金字塔。

(gdb) cont
Continuing.
warning: .dynamic section for "/usr/lib/libgssapi_krb5.so.2" is not at the expected address
warning: difference appears to be caused by prelink, adjusting expectations
warning: .dynamic section for "/usr/lib/libkrb5.so.3" is not at the expected address
warning: difference appears to be caused by prelink, adjusting expectations
warning: .dynamic section for "/lib/libresolv.so.2" is not at the expected address
warning: difference appears to be caused by prelink, adjusting expectations

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x8edbb90 (LWP 1824)]
0x0814c120 in EVP_PKEY_CTX_dup ()

apache_error_log

[info] mod_wsgi (pid=1821): Starting process 'pyramid' with threads=1.
[info] mod_wsgi (pid=1821): Initializing Python.
[info] mod_wsgi (pid=1821): Attach interpreter ''.
[info] mod_wsgi (pid=1821): Create interpreter 'web.domain.com:20000|/hcadmin'.
[info] [client 10.211.55.2] mod_wsgi (pid=1821, process='pyramid', application='web.domain.com:20000|/hcadmin'): Loading WSGI script '/home/httpd/conf/extra/pyramid.wsgi'.
[error] hello 1

答案1

由于您使用的是守护进程模式,请将 gdb 附加到守护进程并发出请求,然后查看从 gdb 获得的堆栈跟踪。

http://code.google.com/p/modwsgi/wiki/DebuggingTechniques#Debugging_Crashes_With_GDB

相关内容