20240923 tkxiong 选择openssl 3.3.2 版本进行编译
这次编译参考官方文档,并使用了ChatGPT,通过对话解决了部分问题。
参考文档:(但不完全参考)
https://curl.se/docs/http3.html
第一步、查看了自己的CentOS版本:
1 2 |
# cat /etc/redhat-release CentOS Linux release 7.8.2003 (Core) |
第二步、下载、配置、编译、安装
1 2 3 4 5 6 7 |
wget https://github.com/openssl/openssl/releases/download/openssl-3.3.2/openssl-3.3.2.tar.gz tar -zxf openssl-3.3.2.tar.gz && cd openssl-3.3.2 ./config enable-tls1_3 --prefix=/usr/local/openssl-3.3.2 --libdir=lib make sudo make install |
配置碰上的问题:
1 2 3 4 5 6 7 8 9 10 11 |
# ./config --prefix=/usr/local/openssl Can't locate IPC/Cmd.pm in @INC (@INC contains: /root/openssl-3.3.2/util/perl /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 . /root/openssl-3.3.2/external/perl/Text-Template-1.56/lib) at /root/openssl-3.3.2/util/perl/OpenSSL/config.pm line 19. BEGIN failed--compilation aborted at /root/openssl-3.3.2/util/perl/OpenSSL/config.pm line 19. Compilation failed in require at /root/openssl-3.3.2/Configure line 23. BEGIN failed--compilation aborted at /root/openssl-3.3.2/Configure line 23. |
这个错误表明缺少 Perl 模块 IPC::Cmd
。您需要安装该模块才能继续配置 OpenSSL。
1 2 3 |
sudo yum install perl perl-CPAN sudo cpan IPC::Cmd |
编译碰上了新的问题:
1 2 3 4 5 6 |
# make /usr/bin/perl util/mkinstallvars.pl PREFIX=. BINDIR=apps APPLINKDIR=ms LIBDIR= INCLUDEDIR=include "INCLUDEDIR=./include" ENGINESDIR=engines MODULESDIR=providers "VERSION=3.3.2" "LDLIBS=-ldl -pthread " > builddata.pm "pairs" is not exported by the List::Util module Can't continue after import errors at util/mkinstallvars.pl line 14. BEGIN failed--compilation aborted at util/mkinstallvars.pl line 14. make: *** [Makefile:5200: builddata.pm] Error 255 |
这个错误表明 List::Util
模块的版本不满足要求,导致无法继续编译。您需要升级 List::Util
模块。以下是解决步骤:
1 |
sudo cpan List::Util |
继续解决编译问题:
1 2 3 4 5 |
# make /usr/bin/perl "-I." "-Mconfigdata" "-Mbuilddata" "util/dofile.pl" "-oMakefile" exporters/cmake/OpenSSLConfig.cmake.in > OpenSSLConfig.cmake builddata.pm did not return a true value. BEGIN failed--compilation aborted. make: *** [Makefile:5198: OpenSSLConfig.cmake] Error 255 |
这个错误表明 builddata.pm
文件没有返回一个真值,通常是由于之前的配置失败。请尝试以下步骤解决问题:
1 2 3 4 5 6 7 8 9 10 11 12 |
make clean sudo cpan IPC::Cmd sudo cpan List::Util sudo cpan Exporter cd /root/openssl-3.3.2 ./config enable-tls1_3 --prefix=/usr/local/openssl --libdir=lib make sudo make install |
至此,我安装完成了,看起来没有什么报错信息。
添加软链接,将openssl指向openssl-3.3.2
1 2 |
cd /usr/local/ ln -s openssl-3.3.2 openssl |
修改环境变量,将以下内容添加到 ~/.bashrc
或 /etc/profile
中:
1 2 3 4 |
# openssl export LD_LIBRARY_PATH=/usr/local/openssl/lib:$LD_LIBRARY_PATH export PKG_CONFIG_PATH=/usr/local/openssl/lib/pkgconfig:$PKG_CONFIG_PATH export PATH=/usr/local/openssl/bin:$PATH |
重新打开终端,查看 openssl 版本。若出现错误:
1 2 |
# openssl version openssl: error while loading shared libraries: libssl.so.3: cannot open shared object file: No such file or directory |
ChatGPT建议 查看openssl 文件:
1 2 |
# ls /usr/local/openssl/lib ls: cannot access /usr/local/openssl/lib: No such file or directory |
如果找到在 lib64 这个目录下。
1 2 |
# ls /usr/local/openssl/lib64/ cmake engines-3 libcrypto.a libcrypto.so libcrypto.so.3 libssl.a libssl.so libssl.so.3 ossl-modules pkgconfig |
ChatGPT建议创建一个链接
1 |
sudo ln -s /usr/local/openssl/lib64 /usr/local/openssl/lib |
实际上可能是编译时缺了 –libdir=lib 这个选项
更新动态缓存库
1 |
sudo ldconfig /usr/local/openssl/lib64 |
再次重新打开终端
1 2 |
# openssl version OpenSSL 3.3.2 3 Sep 2024 (Library: OpenSSL 3.3.2 3 Sep 2024) |
更新完成。
20240926 tkxiong 另外的注意事项:
grpc 查找 openssl 需要配置 PKG_CONFIG_PATH。
【编译】openssl 3.3.2