?? 共享优质资源 ??
学习路线指南(点击解锁) | 知识定位 | 人群定位 |
---|---|---|
?? Python实战微信订餐小程序 ?? | 进阶级 | 本课程是python flask 从项目建设到腾讯云部署上线,微信小程序的完美结合,打造了全栈订餐系统。 |
??Python量化交易实战 | 入门级 | 手把手带你打造一个易扩展、更安全、效率更高的量化交易系统 |
layout: post title: [DEBUG] QAT Nginx for docker 部署时"–with-ld-opt"出错 subtitle: 记一次debug经历 tags: [debug, linux] comments: true
[DEBUG] QAT Nginx for docker 部署时"–with-ld-opt"出错
在将 Openssl QAT async-mode-nginx 部署至docker的container中时执行async-mode-nginx的./configure
当时出现以下报错:
checking for OS Linux 4.18.0-305.el8.x86_64 x86_64 checking for C compiler ... found using GNU C compiler gcc version: 8.5.0 20210514 (Red Hat 8.5.0-4) (GCC) checking for gcc -pipe switch ... found checking for --with-ld-opt="-Wl,-rpath=/root/openssl/lib -L/root/openssl/lib -lz" ... not found ./configure: error: the invalid value in --with-ld-opt="-Wl,-rpath=/root/openssl/lib -L/root/openssl/lib -lz"
“not found” , 找不到/root/openssl/lib这个目录。但实际上这个目录是存在的。一开始我以为是docker container不支持环境本身"–with-ld-opt", 在bing在百度上搜索,一些类似的问题,解决方案是屏蔽参数。的确,屏蔽后nginx但是,nginx就无法与openssl交叉编译。
于是查找了async-mode-nginx中与“–with-ld-opt这里有相关代码source目录下的auto/lib/openssl/conf
文件中,有三段相似代码,第一段是这样:
if [ $ngx\_found = no ]; then # FreeBSD port ngx_feature="OpenSSL library in /usr/local/" ngx_feature_path="/usr/local/include" if [ $NGX\_RPATH = YES ]; then ngx_feature_libs="-R/usr/local/lib -L/usr/local/lib -lssl -lcrypto" else ngx_feature_libs="-L/usr/local/lib -lssl -lcrypto" fi ngx_feature_libs="$ngx\_feature\_libs $NGX\_LIBDL $NGX\_LIBPTHREAD" . auto/feature fi
nginx的./configure会执行 check OS 在这个过程中,如果发现某些库缺失,就会报错退出,ngx_found如果变量为0,则进入以下判断,configure依次搜索程序/usr/local/lib, /usr/pkg/lib和/opt/local/lib, 如果找不到三条路径,如果找不到openssl/lib, 则configure会报错退出。
我echo了ngx_found一般来说,发现值为0host下面,没有0,所以我们不会采取这三个判断。
所以我决定试试container中的nginx/auto/lib/openssl/conf修改文件,修改/usr/local/改为本地openssl地址:
if [ $ngx\_found = no ]; then # FreeBSD port openssl_path=/root/openssl ngx_feature="OpenSSL library in $openssl\_path" ngx_feature_path="$openssl\_path/include" if [ $NGX\_RPATH = YES ]; then ngx_feature_libs="-R$openssl\_path/lib -L$openssl\_path/lib -lssl -lcrypto" else ngx_feature_libs="-L$openssl\_path/lib -lssl -lcrypto" fi ngx_feature_libs="$ngx\_feature\_libs $NGX\_LIBDL $NGX\_LIBPTHREAD" . auto/feature fi
再次编译,nginx通过了,openssl和nginx顺利交叉编译。
这说明,async mode nginx在container它可以正常安装。编译过程中一定缺少了什么?–with-ld-opt出错。
于是我搜索nginx的–with-ld-opt参数, 发现它和–with-cc-opt同样的参数,都和PCRE库密切相关。PCRE是Perl5的软件库,Perl5.它在文本处理、编译和安装、系统操作和维护中起着重要作用。它是许多软件的辅助工具python出现之前Perl使用范围如此之大,以至于今天Linux系统自带语言。PCRE库不是所有Linux需要手动安装系统本身。
于是在container(该container基于redhat8.4 ubi:213制作)先更新repo再执行:
yum install pcre2-tools.x86_64 pcre-devel.x86_64 zlib-static.x86_64 zlib
保守起见,conf文件中了文件zlib,所以一起安装。
这次nginx的configure执行加上–with-ld-opt之后编译顺利,没有再报错。所以是时候BUG顺利解决!唯一不明白的是,为什么当时执行的时候找不到报告?PCRE但是库找不到openssl文件目录。
这次debug, 感觉就是要定位错误的来源,尽量直接看执行编译。conf如何写文件,找出编译逻辑,知道错误从何而来,大胆尝试修改代码check问题,才可能快速寻找到解决办法。