zoukankan      html  css  js  c++  java
  • Openssl 升级操作

    转自:http://www.cnblogs.com/lzcys8868/p/9235538.html

     首先我觉得没事就用绿盟扫漏洞的公司,就是闲的蛋疼,傻逼!不少服务器使用nginx,如果openssl 是静态编译的,直接将openssl 编译到nginx里面去了,这就意味着,单纯升级openssl 是没有任何效果的,nginx不会加载外部的openssl动态链接库的,必须将nginx重新编译才可以根治。所以我说那些没事就扫漏洞的公司是傻逼。。。

    一.判断nginx 是否是静态编译的

    [root@bogon ~]# /usr/local/nginx/sbin/nginx –V

    如果编译参数中含有 –with-openssl= path ,或者有 –with-http_ssl_module ,则表明nginx 是静态编译的,那么恭喜你在升级完openssl 之后还有重新编译nginx,指定openssl 的目录。

    查看当前openssl版本

    > openssl version -a
    OpenSSL 1.0.1e-fips 11 Feb 2013
    built on: Wed Mar 22 21:43:28 UTC 2017
    platform: linux-x86_64
    options:  bn(64,64) md2(int) rc4(16x,int) des(idx,cisc,16,int) idea(int) blowfish(idx) 
    compiler: gcc -fPIC -DOPENSSL_PIC -DZLIB -DOPENSSL_THREADS -D_REENTRANT -DDSO_DLFCN -DHAVE_DLFCN_H -DKRB5_MIT -m64 -DL_ENDIAN -DTERMIO -Wall -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -Wa,--noexecstack -DPURIFY -DOPENSSL_IA32_SSE2 -DOPENSSL_BN_ASM_MONT -DOPENSSL_BN_ASM_MONT5 -DOPENSSL_BN_ASM_GF2m -DSHA1_ASM -DSHA256_ASM -DSHA512_ASM -DMD5_ASM -DAES_ASM -DVPAES_ASM -DBSAES_ASM -DWHIRLPOOL_ASM -DGHASH_ASM
    OPENSSLDIR: "/etc/pki/tls"
    engines:  rdrand dynamic 
    

      二. 升级openssl(后续需要重新编译nginx,建议采用此方法升级openssl)

    > cd /opt/
    > wget https://www.openssl.org/source/openssl-1.1.0j.tar.gz
    > tar xvf openssl-1.1.0j.tar.gz
    > cd /opt/openssl-1.1.0j/
    > ./config --prefix=/usr/local/openssl
    > echo $?
    0
    > make && make install
    > echo $?
    0

    将新编译的openssl 替换老版本的

    > mv /usr/bin/openssl /usr/bin/openssl.bak
    > mv /usr/include/openssl /usr/include/openssl.bak
    > ln -s /usr/local/openssl/bin/openssl /usr/bin/openssl
    > ln -s /usr/local/openssl/include/openssl  /usr/include/openssl
    

     

    > cd /usr/local/openssl/lib/
    > cp libssl.so.1.1 /usr/lib64/libssl.so.1.1
    > cp libcrypto.so.1.1 /usr/lib64/libcrypto.so.1.1
    

      

    > ldconfig -v | grep ssl
    ldconfig: /etc/ld.so.conf.d/kernel-2.6.32-696.13.2.el6.x86_64.conf:6: duplicate hwcap 1 nosegneg
    ldconfig: /etc/ld.so.conf.d/kernel-2.6.32-696.16.1.el6.x86_64.conf:6: duplicate hwcap 1 nosegneg
    ldconfig: /etc/ld.so.conf.d/kernel-ml-aufs-3.10.5-3.el6.x86_64.conf:6: duplicate hwcap 1 nosegneg
    	libssl.so.1.1 -> libssl.so.1.1
    	libssl.so.10 -> libssl.so.1.0.1e
    	libssl3.so -> libssl3.so
    
    > openssl version -a
    OpenSSL 1.1.0j  20 Nov 2018
    built on: reproducible build, date unspecified
    platform: linux-x86_64
    options:  bn(64,64) rc4(16x,int) des(int) idea(int) blowfish(ptr) 
    compiler: gcc -DDSO_DLFCN -DHAVE_DLFCN_H -DNDEBUG -DOPENSSL_THREADS -DOPENSSL_NO_STATIC_ENGINE -DOPENSSL_PIC -DOPENSSL_IA32_SSE2 -DOPENSSL_BN_ASM_MONT -DOPENSSL_BN_ASM_MONT5 -DOPENSSL_BN_ASM_GF2m -DSHA1_ASM -DSHA256_ASM -DSHA512_ASM -DRC4_ASM -DMD5_ASM -DAES_ASM -DVPAES_ASM -DBSAES_ASM -DGHASH_ASM -DECP_NISTZ256_ASM -DPADLOCK_ASM -DPOLY1305_ASM -DOPENSSLDIR=""/usr/local/openssl/ssl"" -DENGINESDIR=""/usr/local/openssl/lib/engines-1.1""  -Wa,--noexecstack
    OPENSSLDIR: "/usr/local/openssl/ssl"
    ENGINESDIR: "/usr/local/openssl/lib/engines-1.1"
    

      

    三.重新编译nginx

    查看nginx 中openssl 的版本

    > ./nginx -V
    nginx version: nginx/1.12.2
    built by gcc 4.4.7 20120313 (Red Hat 4.4.7-23) (GCC) 
    built with OpenSSL 1.0.1e-fips 11 Feb 2013
    TLS SNI support enabled
    configure arguments: --with-debug --with-pcre-jit --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-http_auth_request_module --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_perl_module --with-http_random_index_module --with-http_secure_link_module --with-http_v2_module --with-http_sub_module --with-http_xslt_module --with-mail --with-mail_ssl_module --with-stream --with-stream_ssl_module --with-threads --add-module=modules/nginx-rtmp-module
    

      

    重新编译nginx,并制定openssl 新版本的目录。重新编译nginx时,之前nginx 的配置参数要保证一样

    > cd /opt
    > git clone https://github.com/nginx/nginx.git
    > cd /opt/nginx
    

      如果有添加的额外模块,要将其模块代码也拉下来

      下载 nginx-rtmp-module 模块,并切换到稳定版本

    > mkdir modules
    > cd modules
    > git clone https://github.com/arut/nginx-rtmp-module
    > cd nginx-rtmp-module
    > git checkout v1.2.0
    > cd ..
    

      

    > cp /opt/nginx/auto/configure ./
    > ./configure --prefix=/usr/local/nginx --with-debug --with-pcre-jit --with-openssl=/usr/local/openssl --with-http_ssl_module --with-openssl=/usr/local/openssl --with-http_stub_status_module --with-http_realip_module --with-http_auth_request_module --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_perl_module --with-http_random_index_module --with-http_secure_link_module --with-http_v2_module --with-http_sub_module --with-http_xslt_module --with-mail --with-mail_ssl_module --with-stream --with-stream_ssl_module --with-threads --add-module=modules/nginx-rtmp-module
    

      

     make 报错

    [root@localhost nginx]# make
    make -f objs/Makefile
    make[1]: Entering directory `/opt/nginx'
    cd /usr/local/openssl 
    	&& if [ -f Makefile ]; then make clean; fi 
    	&& ./config --prefix=/usr/local/openssl/.openssl no-shared  
    	&& make 
    	&& make install_sw LIBDIR=lib
    /bin/sh: line 2: ./config: No such file or directory
    make[1]: *** [/usr/local/openssl/.openssl/include/openssl/ssl.h] Error 127
    make[1]: Leaving directory `/opt/nginx'
    make: *** [build] Error 2
    

    解决方法如下:

    修改nginx 源文件下的 /opt/nginx/auto/lib/openssl/conf

    找到这么一段代码:

                CORE_INCS="$CORE_INCS $OPENSSL/.openssl/include"
                CORE_DEPS="$CORE_DEPS $OPENSSL/.openssl/include/openssl/ssl.h"
                CORE_LIBS="$CORE_LIBS $OPENSSL/.openssl/lib/libssl.a"
                CORE_LIBS="$CORE_LIBS $OPENSSL/.openssl/lib/libcrypto.a"
    

     修改成

                CORE_INCS="$CORE_INCS $OPENSSL/include"
                CORE_DEPS="$CORE_DEPS $OPENSSL/include/openssl/ssl.h"
                CORE_LIBS="$CORE_LIBS $OPENSSL/lib/libssl.a"
                CORE_LIBS="$CORE_LIBS $OPENSSL/lib/libcrypto.a"
    

     然后重新编译安装nginx

     

    > ./configure --prefix=/usr/local/nginx --with-debug --with-pcre-jit --with-openssl=/usr/local/openssl --with-http_ssl_module --with-openssl=/usr/local/openssl --with-http_stub_status_module --with-http_realip_module --with-http_auth_request_module --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_perl_module --with-http_random_index_module --with-http_secure_link_module --with-http_v2_module --with-http_sub_module --with-http_xslt_module --with-mail --with-mail_ssl_module --with-stream --with-stream_ssl_module --with-threads --add-module=modules/nginx-rtmp-module
    > make
    

      注:此处千万不要 执行make install,否则会覆盖nginx 之前的配置文件

    拷贝nginx的二进制目录到nginx的安装目录下

    > ps -ef|grep nginx
    root      4261     1  0 09:16 ?        00:00:00 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
    nobody    4267  4261  0 09:16 ?        00:00:00 nginx: worker process                                          
    root     24701  5987  0 16:09 pts/3    00:00:00 grep nginx
    
    > kill -9 4261    
    > kill -9 4267  
    > cp /opt/nginx/objs/nginx /usr/local/nginx/sbin/
    

     

    # 重启nginx 查看nginx中的openssl 版本

    > cd /usr/local/nginx/sbin
    > ./nginx -c /usr/local/nginx/conf/nginx.conf
    >./nginx -V

    nginx version: nginx/1.12.2
    built by gcc 4.4.7 20120313 (Red Hat 4.4.7-23) (GCC)
    built with OpenSSL 1.1.0j 20 Nov 2018
    TLS SNI support enabled
    configure arguments: --prefix=/usr/local/nginx --with-debug --with-pcre-jit --with-openssl=/usr/local/openssl --with-http_ssl_module --with-openssl=/usr/local/openssl --with-http_stub_status_module --with-http_realip_module --with-http_auth_request_module --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_perl_module --with-http_random_index_module --with-http_secure_link_module --with-http_v2_module --with-http_sub_module --with-http_xslt_module --with-mail --with-mail_ssl_module --with-stream --with-stream_ssl_module --with-threads --add-module=modules/nginx-rtmp-module

    如果你将nginx的版本做了升级,直接替换可执行文件,启动时会报错:

    > /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

      nginx: [alert] version 1.14.2 of nginx.pm is required, but 1.12.2 was found

      原因:perl文件,在make install的时候,也会安装,如果不指定安装目录,这个文件会默认安装到/usr/local/lib64/perl5/nginx.pm

      而nginx.pm里面记录了nginx的版本号。所以,如果启动nginx的时候,运行的nginx与nginx.pm版本号不一致就有问题,特别是升级nginx,或者一台机器上部署了多个nginx

      解决办法:

        1. --with-perl_modules_path=/home/webserver/nginx3/perl 把相关perl程序/模块 安装到指定目录里

        2. 将旧版本的安装目录进行备份,然后切换到新版本的编译目录 , 执行 make install 

        再执行  ./nginx -c /usr/local/nginx/conf/nginx.conf 进行启动

    至此,openssl 升级结束。在此过程中,遇到很多坑,以此文档帮助需要没事就升级openssl的小伙伴

     

     

     

      

     

      

  • 相关阅读:
    maven管理jar,pom.xml导入spring依赖
    三分钟明白 Activiti工作流 -- java运用
    Java框架之spring—jdbcTemplate
    Activiti BPMN 2.0 designer eclipse插件安装
    eclipse离线安装Activiti Designer插件
    eclipse oxygen离线安装activiti
    使用spring注解——定义bean和自动注入
    web.config中配置数据库连接的两种方式
    Java的三种代理模式
    03 Spring框架 bean的属性以及bean前处理和bean后处理
  • 原文地址:https://www.cnblogs.com/yorkyang/p/10132167.html
Copyright © 2011-2022 走看看