1、目标需求:

因为要解决安全漏洞,需要将nginx由1.10.0版本升级到1.6.1版本,由于环境所限需要离线安装。

2、环境描述:

操作系统是Linux centOS 6.8 release Final版本,gcc环境已经存在的,但是gcc-c++环境没有。gcc和gcc-c++相关依赖包镜像地址 。nginx安装包需要到nginx官网下载,其他都可以在镜像地址下载到。

3、问题描述:

安装nginx新版本过程中发现gcc环境是存在的,但是安装nginx 1.16.1版本时提示缺少gcc-c++环境;在安装gcc-c++环境时下载的是gcc-c++-4.4.7-23.el6.x86_64.rpm版本,而gcc环境是gcc-c++-4.4.7-17.el6.x86_64.rpm版本,这样在安装过程中导致各种依赖冲突,有些包选择升级安装也解决不了有关问题。

4、解决问题的重点:

这里主要是描述一种思路,也许每个人遇到的新版本和旧版本不一样,但是解决方式没差别。思路如下:

4.1、先尝试使用命令  rpm -ivh XXXX-4.4.7-23.el6.x86_64.rpm 安装缺少的各类环境依赖包

4.2、如果报包冲突,则尝试使用 rpm -Uvh XXXX-4.4.7-23.el6.x86_64.rpm 升级安装

4.3、如果还是安装失败,则卸载原来老版本及其依赖 rpm -e --allmatches --nodeps XXX-4.4.7-17.el6.x86_64 ,这里一定需要卸载相关依赖,如果只执行  rpm -e  XXX-4.4.7-17.el6.x86_64 ,多数情况都会卸载失败。

4.4、老版本卸载成功后,重新安装包的新版本 rpm -ivh XXXX-4.4.7-23.el6.x86_64.rpm

4.5、如果因为yum源问题,报错如下:warning: gcc-c++-4.4.7-23.el6.x86_64.rpm: Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY,则可以加上"--force --nodeps"参数执行强制安装:

rpm -ivh --force --nodeps  gcc-c++-4.4.7-23.el6.x86_64.rpm, 成功解决。

 

5、解决问题的详细过程(过程呈现有点繁琐,如果前面已经get到思路,解决了问题,下面的详细过程就可以不用看了)

 

5.1、本次问题解决过程涉及的包如下:

gcc和gcc-c++相关依赖包可以到镜像地址下载,gcc和gcc-c++相关依赖包镜像地址。 nginx安装包需要到nginx官网下载,其他都可以在镜像地址下载到。

nginx-1.16.1.tar.gz

pcre-8.40.tar.gz

gcc-4.4.7-23.el6.x86_64.rpm

gcc-c++-4.4.7-23.el6.x86_64.rpm

cpp-4.4.7-23.el6.x86_64.rpm

libgcc-4.4.7-23.el6.x86_64.rpm

libgomp-4.4.7-23.el6.x86_64.rpm

libstdc++-4.4.7-23.el6.x86_64.rpm

libstdc++-devel-4.4.7-23.el6.x86_64.rpm

openssl-1.0.2s.tar.gz

zlib-1.2.11.tar.gz

5.2、安装新版本nignx

执行命令  tar -zxvf nginx-1.16.1.tar.gz

再执行 cd nginx-1.16.1

然后执行 ./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module

报错缺少PCRE环境错误如下:

./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre=<path> option.

5.3、安装PCRE环境

执行命令 tar -zxvf pcre-8.40.tar.gz

在执行 cd pcre-8.40

在执行 ./configure && make && make install

 

报缺少C++编译环境依赖错误:

configure: error: You need a C++ compiler for C++ support.

安装gcc-c++  rpm -ivh gcc-c++-4.4.7-23.el6.x86_64.rpm

报缺少gcc、libstdc++、libstdc++-devel环境错误:

error: Failed dependencies:
 gcc = 4.4.7-23.el6 is needed by gcc-c++-4.4.7-23.el6.x86_64
 libstdc++ = 4.4.7-23.el6 is needed by gcc-c++-4.4.7-23.el6.x86_64
 libstdc++-devel = 4.4.7-23.el6 is needed by gcc-c++-4.4.7-23.el6.x86_64

 

执行 gcc -v 查看gcc环境是存在的但是旧版本为 gcc-4.4.7-17.el6.x86_64

升级安装gcc  rpm -Uvh gcc-4.4.7-23.el6.x86_64.rpm

报缺少cpp、libgcc、libgomp环境错误

error: Failed dependencies:
 cpp = 4.4.7-23.el6 is needed by gcc-4.4.7-23.el6.x86_64
 libgcc >= 4.4.7-23.el6 is needed by gcc-4.4.7-23.el6.x86_64
 libgomp = 4.4.7-23.el6 is needed by gcc-4.4.7-23.el6.x86_64

 

安装cpp rpm -ivh cpp-4.4.7-23.el6.x86_64.rpm

报版本冲突:

Preparing...                ########################################### [100%]
 file /usr/bin/cpp from install of cpp-4.4.7-23.el6.x86_64 conflicts with file from package cpp-4.4.7-17.el6.x86_64
 file /usr/libexec/gcc/x86_64-redhat-linux/4.4.4/cc1 from install of cpp-4.4.7-23.el6.x86_64 conflicts with file from package cpp-4.4.7-17.el6.x86_64

说明已经有了,但是原来老版本是cpp-4.4.7-17.el6.x86_64
升级安装cpp:
rpm -Uvh cpp-4.4.7-23.el6.x86_64.rpm
还是报依赖错误:
error: Failed dependencies:
 cpp = 4.4.7-17.el6 is needed by (installed) gcc-4.4.7-17.el6.x86_64
卸载老版本:
rpm -e cpp-4.4.7-17.el6.x86_64
报依赖错误
error: Failed dependencies:
 cpp = 4.4.7-17.el6 is needed by (installed) gcc-4.4.7-17.el6.x86_64 
再来,卸载包及关联依赖包:
rpm -e --allmatches --nodeps cpp-4.4.7-17.el6.x86_64
成功
重新安装新版本cpp:
rpm -ivh cpp-4.4.7-23.el6.x86_64.rpm
成功
 
安装libgcc:
rpm -ivh libgcc-4.4.7-23.el6.x86_64.rpm
报版本冲突:
Preparing...                ########################################### [100%]
 file /lib64/libgcc_s-4.4.7-20120601.so.1 from install of libgcc-4.4.7-23.el6.x86_64 conflicts with file from package libgcc-4.4.7-17.el6.x86_64
再来升级安装:
rpm -Uvh libgcc-4.4.7-23.el6.x86_64.rpm
成功
 
安装libgomp:
rpm -ivh libgomp-4.4.7-23.el6.x86_64.rpm
报冲突:
Preparing...                ########################################### [100%]
 file /usr/lib64/libgomp.so.1.0.0 from install of libgomp-4.4.7-23.el6.x86_64 conflicts with file from package libgomp-4.4.7-17.el6.x86_64
再来升级安装:
rpm -Uvh libgomp-4.4.7-23.el6.x86_64.rpm
报依赖错误:
error: Failed dependencies:
 libgomp = 4.4.7-17.el6 is needed by (installed) gcc-4.4.7-17.el6.x86_64
已经有了老版本,但是升级安装不上
再来先卸载老版本及其依赖包
rpm -e --allmatches --nodeps libgomp-4.4.7-17.el6.x86_64
成功
重新安装新版本
rpm -ivh libgomp-4.4.7-23.el6.x86_64.rpm
成功
回到前面步骤,重新升级gcc:
rpm -Uvh gcc-4.4.7-23.el6.x86_64.rpm
成功了
 
安装libstdc:
rpm -ivh libstdc++-4.4.7-23.el6.x86_64.rpm
报版本冲突:
Preparing...                ########################################### [100%]
 file /usr/lib64/libstdc++.so.6.0.13 from install of libstdc++-4.4.7-23.el6.x86_64 conflicts with file from package libstdc++-4.4.7-17.el6.x86_64
升级安装libstdc:
rpm -Uvh libstdc++-4.4.7-23.el6.x86_64.rpm
成功
 
安装libstdc++-devel
rpm -ivh libstdc++-devel-4.4.7-23.el6.x86_64.rpm
成功

回到前面步骤,在重新安装新版本的gcc-c++
rpm -ivh gcc-c++-4.4.7-23.el6.x86_64.rpm
成功
回到前面步骤 ,执行
cd pcre-8.40
./configure && make && make install
成功
 
 
5.4、回到前面步骤执行,重新安装新版本nginx
cd nginx-1.16.1
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
报缺少OpenSSL:
./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:
tar -zxvf openssl-1.0.2s.tar.gz
cd openssl-1.0.2s
查看openssl解压目录
pwd
/opt/openssl-1.0.2s
指定openssl路径,这个目录是安装文件源目录,不是安装目录,然后重新安装:
cd nginx-1.16.1
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-openssl=/opt/openssl-1.0.2s
缺少zlib错误
 
解压和安装zlib
tar -zxvf  zlib-1.2.11.tar.gz
cd zlib-1.2.11
./configure && make && make install
成功
 
5.5、再次执行安装新版本nginx
cd nginx-1.16.1
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-openssl=/opt/openssl-1.0.2s
make && make install
安装成功
 
 5.6、 nginx新版本安装确认与启动
执行 cd /usr/local/nginx/sbin
 ./nginx -v
 报错:
./nginx: error while loading shared libraries: libpcre.so.1: cannot open shared object file: No such file or directory
 
查找libpcre.so 
find / -type f -name *libpcre.so.*
找到 *libpcre.so.* 的路径,在做软链接:
ln -s /lib64/libpcre.so.0.0.1 /lib64/libpcre.so.1
执行
cd nginx-1.16.1
./nginx -v
成功返回:
nginx version: nginx/1.16.1
 
执行 nginx -v
返回老版本
nginx version: nginx/1.10.0
whereis nginx
返回信息
nginx: /usr/sbin/nginx /etc/nginx /usr/lib64/nginx /usr/local/nginx /usr/share/nginx
 
将老的启动文件备份并复制新的启动文件到指定位置:
cd /usr/sbin
mv nginx nginx.old
cp /usr/local/nginx/sbin/nginx .
nginx -v
正常返回
nginx version: nginx/1.16.1
 
启动nginx
nginx -c /usr/local/nginx/conf/nginx.conf
ps -ef|grep nginx
返回正常:
root     29270     1  0 22:44 ?        00:00:00 nginx: master process nginx -c /usr/local/nginx/conf/nginx.conf
nobody   29271 29270  0 22:44 ?        00:00:00 nginx: worker process                   
root     29286 12345  0 22:46 pts/1    00:00:00 grep nginx
打开浏览器正常(nginx默认80端口,可以修改)
http://ip:80/
正常访问
ok,呈现过程很繁杂曲折,但是问题完美解决。