將 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

相關內容