nginx離線升級安裝,解決gcc和gcc-c++編譯環境依賴的安裝包沖突


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,呈現過程很繁雜曲折,但是問題完美解決。
 
 
 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM