将 LD_PRELOAD 传递给 apache 2.4 以用于 mod_wsgi

将 LD_PRELOAD 传递给 apache 2.4 以用于 mod_wsgi

我无法适应这个问题以适应 mod_wsgi

我有一个使用 gdal 的 python flask 应用程序。我按以下方式启动它:

LD_PRELOAD=/opt/gdal-custom/lib/libgdal.so.1 PYTHONPATH=../somemodules/ scl enable python27 "source ../python27/bin/activate; python flaskapp.py"

但是,我想将其托管在 mod_wsgi 中。这样做LD_PRELOAD=/opt/gdal-custom/lib/libgdal.so.1 service httpd24-httpd restart似乎不起作用。在我的 apache 配置中设置以下内容也不行:

SetEnv LD_PRELOAD /opt/gdal-custom/lib/libgdal.so.1

LoadModule wsgi_module modules/mod_wsgi.so

WSGIPythonHome /opt/rh/httpd24/root/var/www/wsgi-virtualenv

WSGIPythonPath /opt/rh/httpd24/root/var/www/AppFolder:/opt/rh/httpd24/root/var/www/SomeModules

WSGIScriptAlias /AppFolder /opt/rh/httpd24/root/var/www/AppFolder/app.wsgi

<Directory /var/www/AppFolder>
AllowOverride none
Require all granted
</Directory>

以下是 ldd 的输出:

(wsgi-virtualenv)ldd /opt/rh/httpd24/root/var/www/wsgi-virtualenv/lib/python2.7/site-packages/GDAL-1.11.2-py2.7-linux-x86_64.egg/osgeo/_gdal.so
    linux-vdso.so.1 =>  (0x00007fffac9ff000)
    libpython2.7.so.1.0 => /opt/rh/python27/root/usr/lib64/libpython2.7.so.1.0 (0x00007fce43438000)
    libgdal.so.1 => /opt/gdal-custom/lib/libgdal.so.1 (0x00007fce42490000)
    libstdc++.so.6 => /usr/lib64/libstdc++.so.6 (0x00007fce42176000)
    libm.so.6 => /lib64/libm.so.6 (0x00007fce41ef2000)
    libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007fce41cdb000)
    libpthread.so.0 => /lib64/libpthread.so.0 (0x00007fce41abe000)
    libc.so.6 => /lib64/libc.so.6 (0x00007fce4172a000)
    libdl.so.2 => /lib64/libdl.so.2 (0x00007fce41525000)
    libutil.so.1 => /lib64/libutil.so.1 (0x00007fce41322000)
    libfreexl.so.1 => /usr/lib64/libfreexl.so.1 (0x00007fce41119000)
    libgeos_c.so.1 => /usr/lib64/libgeos_c.so.1 (0x00007fce40ef2000)
    libsqlite3.so.0 => /usr/lib64/libsqlite3.so.0 (0x00007fce40c63000)
    libodbc.so.2 => /usr/lib64/libodbc.so.2 (0x00007fce409fc000)
    libodbcinst.so.2 => /usr/lib64/libodbcinst.so.2 (0x00007fce407ea000)
    libexpat.so.1 => /lib64/libexpat.so.1 (0x00007fce405c2000)
    libxerces-c-3.0.so => /usr/lib64/libxerces-c-3.0.so (0x00007fce40021000)
    libjasper.so.1 => /usr/lib64/libjasper.so.1 (0x00007fce3fdc7000)
    libnetcdf.so.6 => /usr/lib64/libnetcdf.so.6 (0x00007fce3fa82000)
    libhdf5.so.6 => /usr/lib64/libhdf5.so.6 (0x00007fce3f49a000)
    libogdi.so.3 => /usr/lib64/libogdi.so.3 (0x00007fce3f278000)
    libgif.so.4 => /usr/lib64/libgif.so.4 (0x00007fce3f06f000)
    libjpeg.so.62 => /usr/lib64/libjpeg.so.62 (0x00007fce3ee1f000)
    libgta.so.0 => /usr/lib64/libgta.so.0 (0x00007fce3ec14000)
    libpng12.so.0 => /usr/lib64/libpng12.so.0 (0x00007fce3e9ee000)
    libcfitsio.so.0 => /usr/lib64/libcfitsio.so.0 (0x00007fce3e63a000)
    libpq.so.5 => /usr/lib64/libpq.so.5 (0x00007fce3e411000)
    librt.so.1 => /lib64/librt.so.1 (0x00007fce3e209000)
    libpcre.so.0 => /lib64/libpcre.so.0 (0x00007fce3dfdd000)
    libcurl.so.4 => /usr/lib64/libcurl.so.4 (0x00007fce3dd88000)
    libxml2.so.2 => /usr/lib64/libxml2.so.2 (0x00007fce3da35000)
    libz.so.1 => /lib64/libz.so.1 (0x00007fce3d81f000)
    /lib64/ld-linux-x86-64.so.2 (0x0000003e73a00000)
    libgeos-3.4.2.so => /usr/lib64/libgeos-3.4.2.so (0x00007fce3d479000)
    libltdl.so.7 => /usr/lib64/libltdl.so.7 (0x00007fce3d270000)
    libnsl.so.1 => /lib64/libnsl.so.1 (0x00007fce3d056000)
    libhdf5_hl.so.6 => /usr/lib64/libhdf5_hl.so.6 (0x00007fce3ce24000)
    libproj.so.0 => /usr/lib64/libproj.so.0 (0x00007fce3cbd7000)
    libSM.so.6 => /usr/lib64/libSM.so.6 (0x00007fce3c9ce000)
    libICE.so.6 => /usr/lib64/libICE.so.6 (0x00007fce3c7b2000)
    libX11.so.6 => /usr/lib64/libX11.so.6 (0x00007fce3c475000)
    liblzma.so.0 => /usr/lib64/liblzma.so.0 (0x00007fce3c253000)
    libbz2.so.1 => /lib64/libbz2.so.1 (0x00007fce3c042000)
    libssl.so.10 => /usr/lib64/libssl.so.10 (0x00007fce3bdd6000)
    libcrypto.so.10 => /usr/lib64/libcrypto.so.10 (0x00007fce3b9f2000)
    libgssapi_krb5.so.2 => /lib64/libgssapi_krb5.so.2 (0x00007fce3b7ae000)
    libcrypt.so.1 => /lib64/libcrypt.so.1 (0x00007fce3b577000)
    libldap_r-2.4.so.2 => /lib64/libldap_r-2.4.so.2 (0x00007fce3b31e000)
    libidn.so.11 => /lib64/libidn.so.11 (0x00007fce3b0ec000)
    libldap-2.4.so.2 => /lib64/libldap-2.4.so.2 (0x00007fce3ae9c000)
    libkrb5.so.3 => /lib64/libkrb5.so.3 (0x00007fce3abb5000)
    libk5crypto.so.3 => /lib64/libk5crypto.so.3 (0x00007fce3a989000)
    libcom_err.so.2 => /lib64/libcom_err.so.2 (0x00007fce3a785000)
    libssl3.so => /usr/lib64/libssl3.so (0x00007fce3a545000)
    libsmime3.so => /usr/lib64/libsmime3.so (0x00007fce3a319000)
    libnss3.so => /usr/lib64/libnss3.so (0x00007fce39fda000)
    libnssutil3.so => /usr/lib64/libnssutil3.so (0x00007fce39dad000)
    libplds4.so => /lib64/libplds4.so (0x00007fce39ba9000)
    libplc4.so => /lib64/libplc4.so (0x00007fce399a4000)
    libnspr4.so => /lib64/libnspr4.so (0x00007fce39765000)
    libssh2.so.1 => /usr/lib64/libssh2.so.1 (0x00007fce3953d000)
    libuuid.so.1 => /lib64/libuuid.so.1 (0x00007fce39338000)
    libxcb.so.1 => /usr/lib64/libxcb.so.1 (0x00007fce3911a000)
    libkrb5support.so.0 => /lib64/libkrb5support.so.0 (0x00007fce38f0e000)
    libkeyutils.so.1 => /lib64/libkeyutils.so.1 (0x00007fce38d0b000)
    libresolv.so.2 => /lib64/libresolv.so.2 (0x00007fce38af1000)
    libfreebl3.so => /lib64/libfreebl3.so (0x00007fce388ed000)
    liblber-2.4.so.2 => /lib64/liblber-2.4.so.2 (0x00007fce386de000)
    libsasl2.so.2 => /usr/lib64/libsasl2.so.2 (0x00007fce384c4000)
    libXau.so.6 => /usr/lib64/libXau.so.6 (0x00007fce382c0000)
    libselinux.so.1 => /lib64/libselinux.so.1 (0x00007fce380a1000)

答案1

您为何要LD_PRELOAD特别使用?

通常如果您有一个 Python 模块或应用程序,它链接一个共享库,而该共享库不在系统库搜索路径上的标准目录中,则您可以使用LD_LIBRARY_PATH

使用LD_LIBRARY_PATH仍然不会帮助您完成此操作,因为在启动应用程序进程之前必须在环境中进行设置。目录SetEnv不会对 mod_wsgi 执行此操作。

解决此问题的方法通常是再次设置一个不同的环境变量,称为LD_RUN_PATH,但在编译需要它的 Python 模块、应用程序或库时设置它。

因此,在安装需要它的 Python 模块时,请执行以下操作:

LD_RUN_PATH=/opt/gdal-custom/lib pip install somemodule

相关内容