美文网首页CentOS
CentOS 安装 openssl 最新版本

CentOS 安装 openssl 最新版本

作者: Rinaloving | 来源:发表于2023-02-01 15:52 被阅读0次

    1. 安装

    • 查看当前openssl版本:
    openssl version
    显示为1.0版本
    
    • 编译安装Python3.10时需要openssl1.1.1,所以这里手动删除openssl1.0
    yum remove openssl
    
    • 下载 openssl 安装包
    • 官网地址
      QQ截图20230202163827.png
    • 解压并进入openssl3.0.7路径下:
     tar -zxvf openssl-3.0.7.tar.gz 
     cd openssl-3.0.7/
     ./config --prefix=/usr/local/openssl
     make -j 2
     make install
    

    Can't locate IPC/Cmd.pm in @INC

    2. 错误

    • 编译OpenSSL 3.0.7 时报错,错误信息如下
    [root@VM-0-7-centos openssl-3.0.7]# ./config --prefix=/usr/local/openssl
    Can't locate IPC/Cmd.pm in @INC (@INC contains: /usr/local/openssl-3.0.7/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 . /usr/local/openssl-3.0.7/external/perl/Text-Template-1.56/lib) at /usr/local/openssl-3.0.7/util/perl/OpenSSL/config.pm line 19.
    BEGIN failed--compilation aborted at /usr/local/openssl-3.0.7/util/perl/OpenSSL/config.pm line 19.
    Compilation failed in require at /usr/local/openssl-3.0.7/Configure line 23.
    BEGIN failed--compilation aborted at /usr/local/openssl-3.0.7/Configure line 23.
    

    3. 解决

    • 安装perl-CPAN
    yum install -y perl-CPAN
    
    • 进入CPAN的shell模式,首次进入需要配置shell,按照提示操作即可(本人perl小白,全部选择默认配置,高手请根据提示自行选择)
    [root@VM-0-7-centos openssl-3.0.7]# perl -MCPAN -e shell
    
    CPAN.pm requires configuration, but most of it can be done automatically.
    If you answer 'no' below, you will enter an interactive dialog for each
    configuration option instead.
    
    Would you like to configure as much as possible automatically? [yes] y
    
     <install_help>
    
    Warning: You do not have write permission for Perl library directories.
    
    To install modules, you need to configure a local Perl library directory or
    escalate your privileges.  CPAN can help you by bootstrapping the local::lib
    module or by configuring itself to use 'sudo' (if available).  You may also
    resolve this problem manually if you need to customize your setup.
    
    What approach do you want?  (Choose 'local::lib', 'sudo' or 'manual')
     [local::lib] 
    
    • 到这边根据提示,直接默认 yes 一路下去


      QQ截图20230202154248.png
    • cpan[1]> install IPC/Cmd.pm 安装,这边结束了,直接Ctrl + D 退出去


      QQ截图20230202154621.png
    • 再次输入命令 ./config --prefix=/usr/local/openssl


      QQ截图20230202154830.png
    • 继续安装 openssl

    make -j 2
    make install
    
    • 创建链接
    ln -sf /usr/local/openssl/bin/openssl /usr/bin/openssl
    
    • 修改 ld.so.conf
    vim /etc/ld.so.conf
    在文件末尾添加一行代码:
    /usr/local/openssl/lib
    
    • 使配置生效:
    ldconfig -v
    
    • 然后在任意路径下输入命令:
    openssl version
    

    可以看到版本为openssl 3.0.7

    按照上面的方法肯定没问题,问题就是你安装的 openssl 地址可能不一样,那就会报下面的错误

    4. 运行报错

    • openssl version
    [root@VM-0-7-centos lib64]# openssl version
    openssl: error while loading shared libraries: libssl.so.3: cannot open shared object file: No such file or directory
    
    • 因为创建软链接的时候路径错了,我们需要创建链接
    ln -s /usr/local/openssl/lib64/libssl.so.3 /usr/lib/libssl.so.3
    ln -s /usr/local/openssl/lib64/libcrypto.so.3 /usr/lib/libcrypto.so.3
    
    • 注意我这个路径 ln -s /usr/local/openssl/lib64/libssl.so.3 , 因为我安装 openssl 目录就在这里


      QQ截图20230202162653.png
    • 执行 ldconfig -v 使配置生效,重新输入 openssl version , 成功!


      QQ截图20230202163316.png

    5. 总结

    • 参考别人的文档不要按部就班,要根据自己的实际情况灵活变通。
    • 要记录过程并总结,方便自己就是方便他人。

    相关文章

      网友评论

        本文标题:CentOS 安装 openssl 最新版本

        本文链接:https://www.haomeiwen.com/subject/hkpihdtx.html