【問題解決】源碼安裝Nginx提示找不到openssl library

問題背景

最近測試同事說有一臺服務器執行源碼安裝Nginx腳本出現openssl not found的錯誤解決不了讓我幫忙看看,ssh連接上去後發現這臺服務器安裝了 CentOS7.9操作系統,並且已經安裝了 openssl-devel 庫,理論上不會有問題。

然而,就在重裝多次 openssl相關軟件包後,感覺問題不大正常,於是再次仔細查看報錯信息:

checking for OpenSSL library ... not found
checking for OpenSSL library in /usr/local/ ... not found
checking for OpenSSL library in /usr/pkg/ ... not found
checking for OpenSSL library in /opt/local/ ... not found

./configure: error: SSL modules require the OpenSSL library.
You can either do not enable the modules, or install the OpenSSL library
into the system, or build the OpenSSL library statically from the source
with nginx by using --with-openssl=<path> option.

大意是沒找到OpenSSL庫,而Nginx的SSL模塊需要OpenSSL庫,要麼禁用這個模塊,要麼安裝OpenSSL庫;也可以通過指定OpenSSL源碼位置來靜態編譯OpenSSL供Nginx使用。

檢查openssl-devel安裝情況 yum list installed |grep openssl-devel,發現的確安裝了

[root@cfs-ctp nginx]# yum list installed |grep openssl-devel
openssl-devel.x86_64                       1:1.0.2k-25.el7_9           @updates

嘗試執行了下 openssl version 查看openssl的版本

[root@cfs-ctp nginx]# openssl version
openssl: relocation error: openssl: symbol OPENSSL_init_ssl, version OPENSSL_1_1_0 not defined in file libssl.so.1.1 with link time reference

yum安裝的版本是1.0.2k,而提示卻是OPENSSL_1_1_0,我懷疑 openssl 安裝有問題。

解決方法

由於在網上百度到OpenSSL library in /usr/local/ ... not found這種標題的帖子解決辦法都非常離譜——指定OpenSSL源碼靜態編譯 或 手動編譯OpenSSL後複製到某個位置,再有懷疑OpenSSL安裝有問題,直接去查OpenSSL的報錯信息,發現了全網(截至2022/09/08)唯一一篇情況大致相同的貼子,來自ArchLinux論壇 https://archlinuxarm.org/forum/viewtopic.php?t=11679&p=55714

於是全局搜索下 openssl 目錄,看看有沒有源碼安裝目錄

[root@cfs-ctp ~]# find / -name openssl
find: ‘/proc/42458’: 沒有那個文件或目錄
/etc/pki/ca-trust/extracted/openssl
/root/nginx/nginx-1.22.0/auto/lib/openssl
/usr/bin/openssl
/usr/lib64/openssl
/usr/include/openssl
/data/jq/rpms/openssl-1.1.1a/test/ossl_shim/include/openssl
/data/jq/rpms/openssl-1.1.1a/apps/openssl
/data/jq/rpms/openssl-1.1.1a/include/openssl
/data/jq/rpms/tengine-2.3.0/auto/lib/openssl

的確發現1.1.1版本的源碼目錄,進入後執行卸載操作

cd /data/jq/rpms/openssl-1.1.1a
make uninstall

再次執行源碼安裝nginx的腳本,一切正常。

提示:源碼安裝系統組件一定要保留編譯安裝目錄,不然出現這種情況基本就得重裝系統了。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章