离线部署Nginx的安装详细教程+遇到的问题和解决方法

这篇文章主要就是针对内网部署,不能通过上网的方式下载某些安装软件的依赖包,全程全是通过下载Nginx相关的包,上传到服务器上,最终在服务器上进行解压安装操作。

一、下载Nginx的依赖

nginx:http://nginx.org/en/download.html (版本:nginx-1.20.1 tar.gz)
pcre:https://sourceforge.net/projects/pcre/files/pcre/8.45/(版本:pcre-8.45.tar.gz)
zlib:http://www.zlib.net/(版本:zlib-1.2.13.tar.gz)
oppenssl:https://www.openssl.org/source/(版本:openssl-1.1.0h.tar.gz)

可自行根据个人需要下载适合的依赖包

Pcre:是一个正则表达式库。(必须)

Zlib:是一个开源的数据压缩库,提供了对数据的无损压缩和解压功能。(必须)

Openssl:是一个开源的加密库,提供了各种加密算法和安全协议的实现。(必须)

下载好文件后,nginx包上传到服务器的root/data目录下(没有该目录则新建),上传的目录都不影响随意,但是要记得openssl、pcre、zlib的解压路径方便后续编译Nginx的时候指定目录。

注意事项:

在安装Nginx的时候,一定要根据你要安装Nginx的版本,查阅一下对应的openssl、pcre、zlib版本不然,你在执行make的时候就会报错。以下是我在升级Nginx为最新的时候,还是用的之前它相关依赖包的版本时报错的信息。

bjs/src/event/ngx_event_openssl.o: In function `ngx_ssl_error':

/data/nginx-1.24.0/src/event/ngx_event_openssl.c:3632: undefined reference to `ERR_peek_error_data'

objs/src/event/ngx_event_openssl.o: In function `ngx_ssl_sendfile':

/data/nginx-1.24.0/src/event/ngx_event_openssl.c:3025: undefined reference to `SSL_sendfile'

objs/src/event/ngx_event_openssl.o: In function `ngx_ssl_ticket_key_callback':

/data/nginx-1.24.0/src/event/ngx_event_openssl.c:4565: undefined reference to `EVP_CIPHER_get_iv_length'

objs/src/event/ngx_event_openssl.o: In function `ngx_ssl_check_host':

/data/nginx-1.24.0/src/event/ngx_event_openssl.c:4831: undefined reference to `SSL_get1_peer_certificate'

objs/src/event/ngx_event_openssl.o: In function `ngx_ssl_get_raw_certificate':

/data/nginx-1.24.0/src/event/ngx_event_openssl.c:5337: undefined reference to `SSL_get1_peer_certificate'

objs/src/event/ngx_event_openssl.o: In function `ngx_ssl_get_subject_dn':

/data/nginx-1.24.0/src/event/ngx_event_openssl.c:5461: undefined reference to `SSL_get1_peer_certificate'

objs/src/event/ngx_event_openssl.o: In function `ngx_ssl_get_issuer_dn':

/data/nginx-1.24.0/src/event/ngx_event_openssl.c:5515: undefined reference to `SSL_get1_peer_certificate'

objs/src/event/ngx_event_openssl.o: In function `ngx_ssl_get_subject_dn_legacy':

/data/nginx-1.24.0/src/event/ngx_event_openssl.c:5571: undefined reference to `SSL_get1_peer_certificate'

objs/src/event/ngx_event_openssl.o:/data/nginx-1.24.0/src/event/ngx_event_openssl.c:5619: more undefined references to `SSL_get1_peer_certificate' follow

collect2: error: ld returned 1 exit status

make[1]: *** [objs/Makefile:242: objs/nginx] Error 1

make[1]: Leaving directory '/data/nginx-1.24.0'

make: *** [Makefile:10: build] Error 2

正式开始前需要确认gcc、g++开发库已经预先安装好。为什么呢?是因为亲身经历,如果没有提前安装好gcc、g++的话在进行后续编译Nginx的时候就行出现这个问题

./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.

然后这个大概意思就是你没有PCRE的库需要安装,去网上查找安装PCRE的教程,但是在安装PCRE的时候又会出现大概这个问题configure: error: C++ compiler missing or inoperational 就是你没有c++的环境,即需要安装gcc相关包,然后又一步一步的找,发现安装gcc的时候又需要3个依赖包(gmp、mpc、mprf)然后又去找包解压编译安装,但到时候就真的安装成功吗?不一定,因此我这里换了一种思路,就是先把c++的相关环境配置好,再进行相关Nginx的操作。具体步骤如下:

二、检查GCC、G++是否安装

检查gcc是否安装

gcc --version

检查g++是否安装

g++ --version

离线安装

阿里云盘下载地址:https://www.aliyundrive.com/s/VpQ3g4L6oub

提取码: sj94

离线安装环境:离线安装包:gcc环境安装包

gcc安装包内容

g++安装包内容

下载后,把安装包解压到服务器上,先安装gcc,再安装g++。分别执行两个文件夹下的install.sh

执行命令 sh install.sh 它其实就是去执行rpm -ivh 等全部需要安装命令,这样就可以不用手动去执行了如果执行上述命令出现了问题(一般都是版本问题) 有问题可以手动执行下列图片中所有的rpm。

例:rpm -ivh gcc-4.8.5-4.el7.x86_64.rpm

同一个目录下批量安装rpm文件:rpm -ivh *rpm

在执行上述命令的时候,如遇版本冲突问题,请在命令上追加 --replacefiles 参数。

例:rpm -ivh gcc-4.8.5-4.el7.x86_64.rpm --replacefiles

如果在执行上述加了参数的命令执行的时候仍然报错:类似于下面这种错误:

error: Failed dependencies: 
cpp = 4.8.5-4.el7 is needed by gcc-4.8.5-4.el7.x86_64 libgomp = 4.8.5-4.el7 is needed by gcc-4.8.5-4.el7.x86_64 gcc < 8 conflicts with (installed) UnionTech-rpm-config-129-1.uelc20.03.x86_64

这个意思大概就是依赖错误;出现这种的原因是依赖关系非常复杂,当你试图先安装任何一个包时都会出现这样的依赖关系错误,这时候你就应该强制安装了,我认为只要你把服务或软件需要的包都装上,强制安装也不会出问题的,不会有什么影响。

解决方法:强制安装需要安装的rpm文件 参数 --force(强制) --nodeps(不查找依赖关系)

例:rpm -ivh gcc-4.8.5-4.el7.x86_64.rpm --force --nodeps

三、安装pcre

tar -zxvf pcre-8.45.tar.gz

cd pcre-8.45/

./configure

make

make install

可根据实际需要进行选择相关安装路径

四、安装zlib

tar -zxvf zlib-1.2.13.tar.gz

cd zlib-1.2.13/

./configure

make

make install

可根据实际需要进行选择相关安装路径

五、安装openssl

tar -zxvf openssl-1.1.0h.tar.gz

cd openssl-1.1.0h/

./config

make

make install

可根据实际需求进行选择相关路径安装

六、安装Nginx

tar -zxvf nginx-1.20.1.tar.gz

cd nginx-1.20.1/

./configure --prefix=/data/nginx --with-http_stub_status_module --with-http_ssl_module

--prefix=/data/nginx:指定安装目录为/data/nginx。在编译和安装完成后,软件将被安装到该目录下.

--with-http_stub_status_module:启用 HTTP Stub Status 模块。该模块是 Nginx 的一个内置模块,用于获取 Nginx 服务器的状态信息。

--with-http_ssl_module:启用 HTTP SSL 模块。该模块使得 Nginx 支持通过 HTTPS 提供安全的加密传输。

单独执行(./configure --prefix=/data/nginx

)上述命令可能会出现这样的问题:没有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.

解决方法;在执行./configure 后面添加pcre、zlib、openssl的解压路径 如下:

./configure --prefix=/data/nginx --with-http_stub_status_module --with-http_ssl_module --with-pcre=/data/pcre/pcre-8.45 --with-zlib=/data/zlib/zlib-1.2.13 

--with-openssl=/data/openssl/openssl-1.1.0h

make

make install

在安装nginx的时候执行:make命令 如果出现类似下列这样的问题,大概是警告也算错,因此make命令执行不下。

src/event/ngx_event_openssl.c:5354:5: error: ‘ENGINE_free’ is deprecated (declared at /usr/local/include/openssl/engine.h:493): Since OpenSSL 3.0 [-Werror=deprecated-declarations]
     ENGINE_free(engine);
     ^
cc1: all warnings being treated as errors

解决方法;方法有很多,可自行百度,我选择的是重新换个低版本的,由于之前使用的openssl-3.0.9版本,现在换成了openssl-1.1.0。重新执行上面的命令 ./config .. 再去编译make,就成功了。

七、测试nginx是否安装成功

nginx启动

cd /data/nginx/sbin

./nginx

或者

/data/nginx/sbin/nginx

nginx关闭

ps –ef | grep nginx 列出Nginx的相关进程

kill pid 杀死Nginx相关进程,也相当于停止Nginx

/data/nginx/sbin/nginx -s stop 停止Nginx

参考博客:

Linux环境下离线安装和配置nginx_linux 离线安装_半山惊竹的博客-CSDN博客

(173条消息) 当安装、卸载件包时,出现依赖问题 error: Failed dependencies_failed dependencies kernel-headers is obsoleted_cherish1forever的博客-CSDN博客

上述涉及到的安装包,可私我

以上也是本人在实际内网部署Nginx操作的步骤以及遇到的问题及相关解决方法,仅代表个人意见

猜你喜欢

转载自blog.csdn.net/m0_52985087/article/details/131581663
今日推荐