[英]How to install libcurl with nss backend in aws ec2? (Python 3.6 64bit Amazon Linux)
I have an ec2 instance in AWS running Python3.6 (Amazon Linux/2.8.3) where I need to install pycurl with NSS ssl backend .我在 AWS 中有一个运行 Python3.6 (Amazon Linux/2.8.3) 的 ec2 实例,我需要在其中安装 pycurl 和 NSS ssl 后端。
First I tried it by adding pycurl==7.43.0 --global-option="--with-nss"
to my requirement.txt
file but I was getting errors installation errors.首先,我通过将
pycurl==7.43.0 --global-option="--with-nss"
到我的requirement.txt
文件来尝试它,但我遇到了错误安装错误。 So I ended up doing it by adding a .config
file in .ebextensions
(that runs during deployment):所以我最终通过在
.ebextensions
(在部署期间运行)中添加一个.config
文件来.ebextensions
它:
container_commands:
09_pycurl_reinstall:
# the upgrade option is because it will run after PIP installs the requirements.txt file.
# and it needs to be done with the virtual-env activated
command: 'source /opt/python/run/venv/bin/activate && PYCURL_SSL_LIBRARY=nss pip3 install pycurl --global-option="--with-nss" --upgrade --no-cache-dir --compile --ignore-installed'
Pycurl seems to be correctly installed, but the celery worker is not running. Pycurl 似乎已正确安装,但 celery worker 没有运行。 The celery worker logs show:
芹菜工人日志显示:
__main__.ConfigurationError: Could not run curl-config: [Errno 2] No such file or directory
If I ssh connect to the instance and run python 3.6 -c 'import pycurl'
I get a more detailed error:如果我 ssh 连接到实例并运行
python 3.6 -c 'import pycurl'
我会得到一个更详细的错误:
ImportError: pycurl: libcurl link-time ssl backend (openssl) is different from compile-time ssl backend (nss)
So I guess that my problem is that I had previously installed libcurl with openSSL instead of NSS, and hence the mismatch between libcurl and pycurl.所以我想我的问题是我之前用 openSSL 而不是 NSS 安装了 libcurl,因此 libcurl 和 pycurl 之间不匹配。
According to another stackoverflow question, for libcurl to be installed with NSS backend I should have installed it with:根据另一个 stackoverflow 问题,对于要与 NSS 后端一起安装的 libcurl,我应该安装它:
sudo apt libcurl4-nss-dev
But since the server is running Amazon Linux I can't use the apt
command.但是由于服务器运行的是 Amazon Linux,我无法使用
apt
命令。 So I did instead:所以我做了:
yum install libcurl-devel
And I guess this is the problem: this installs libcurl with OpenSSL support when I need it with NSS support.我想这就是问题所在:当我需要 NSS 支持时,它会安装支持 OpenSSL 的 libcurl。
How can I install libcurl with NSS in Amazon Linux??如何在 Amazon Linux 中使用 NSS 安装 libcurl? (I need NSS because I'm running a Django app with celery using SQS as the broker, and SQS requires NSS).
(我需要 NSS,因为我正在使用 SQS 作为代理运行带有 celery 的 Django 应用程序,而 SQS 需要 NSS)。
Thank you very much!非常感谢!
I just ran into the same issue and did manage to fix it :)我刚刚遇到了同样的问题,并设法解决了它:)
libcurl
:libcurl
Amazon Linux 配置选项:curl-config --configure
All options referring to paths can be ignored, but other must be kept if you want the same features than system libcurl
.可以忽略所有引用路径的选项,但如果您想要与系统
libcurl
相同的功能,则必须保留其他选项。 Of course, --with-ssl
will be replaced with --without-ssl --with-nss
.当然,
--with-ssl
将被替换为--without-ssl --with-nss
。
1.1 Install prerequisites: 1.1 安装先决条件:
sudo yum install libssh2-devel nss-devel
(of course you should rather add then to the packages
> yum
section of your ebextensions) (当然,您应该将然后添加到您的 ebextensions 的
packages
> yum
部分)
libcurl
from source (i chose 7.61.1 to match the one used by Amazon Linux 2018.03):libcurl
(我选择了 7.61.1 来匹配 Amazon Linux 2018.03 使用的那个):wget https://curl.haxx.se/download/curl-7.61.1.tar.gz
tar xf curl-7.61.1.tar.gz
cd curl-7.61.1
./configure '--build=x86_64-redhat-linux-gnu' '--host=x86_64-redhat-linux-gnu' '--target=x86_64-amazon-linux-gnu' '--program-prefix=' '--cache-file=../config.cache' '--disable-static' '--enable-symbol-hiding' '--enable-ipv6' '--enable-threaded-resolver' '--with-gssapi' '--with-nghttp2' '--without-ssl' '--with-nss' '--with-ca-bundle=/etc/pki/tls/certs/ca-bundle.crt' '--enable-ldap' '--enable-ldaps' '--enable-manual' '--with-libidn2' '--with-libpsl' '--with-libssh2' 'build_alias=x86_64-redhat-linux-gnu' 'host_alias=x86_64-redhat-linux-gnu' 'target_alias=x86_64-amazon-linux-gnu' 'CFLAGS=-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic'
make
sudo make install
(of course this should be deployed properly as a Shell script through the files
section of your ebextensions). (当然,这应该通过 ebextensions 的
files
部分正确部署为 Shell 脚本)。
Now you should see libcurl.so.4
created in /usr/local/lib
.现在您应该看到在
/usr/local/lib
创建的libcurl.so.4
。
pycurl
to be compiled using your custom libcurl
:libcurl
编译的pycurl
定义以下环境pycurl
:LD_LIBRARY_PATH=/usr/local/lib
PYCURL_CURL_CONFIG=/usr/local/bin/curl-config
PYCURL_SSL_LIBRARY=nss
pip install
pip install
You can check pycurl
linked to the right libcurl
:您可以检查链接到正确
libcurl
pycurl
:
ldd /opt/python/run/venv/local/lib64/python3.6/site-packages/pycurl.cpython-36m-x86_64-linux-gnu.so
should show you libcurl.so.4 => /usr/local/lib64/libcurl.so.4
应该显示你
libcurl.so.4 => /usr/local/lib64/libcurl.so.4
And of course python 3.6 -c 'import pycurl'
should work.当然
python 3.6 -c 'import pycurl'
应该可以工作。
That's it!就是这样! You should be able to run Celery with SQS.
您应该能够使用 SQS 运行 Celery。
had loads of issues getting pycurl installed on my python ec2 instance - first up, pip wouldn't install pycurl at all.在我的 python ec2 实例上安装 pycurl 有很多问题 - 首先,pip 根本不会安装 pycurl。 had to ssh and run
必须 ssh 并运行
yum install libcurl-devel
after this i updated my requirement.txt file to include the relevant ssl option (--with-openssl) as an install option;在此之后,我更新了我的requirement.txt 文件以包含相关的 ssl 选项(--with-openssl)作为安装选项;
pycurl==7.43.0.5 --install-option="--with-openssl"
once i deployed a new version with this change in requirement.txt pycurl worked fine which i tested with;一旦我部署了一个新版本并在requirements.txt pycurl中进行了这个更改,我测试过它就可以正常工作;
python 'import pycurl'
i knew i needed to use openssl from the error message我知道我需要从错误消息中使用 openssl
libcurl link-time ssl backend (openssl)
libcurl 链接时 ssl 后端 (openssl)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.