二进制编译安装nginx(完整版)(二进制包安装)
环境描述
Linux服务器系统版本:
cat /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)
服务器无法连接外网,且为最小化安装 意味着没有gcc,openssl等等基础依赖包,需要从其他地方下载(
https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/)并且上传到目标服务器
安装包准备
下载地址
http://nginx.org/en/download.html
解压
[admin@app ~]$ ll
-rw-rw-r-- 1 admin admin 1015384 Dec 29 13:51 nginx-1.14.2.tar.gz
[admin@app ~]$ sudo tar xf nginx-1.14.2.tar.gz
[admin@app ~]$ ls
nginx-1.14.2 nginx-1.14.2.tar.gz
[admin@app ~]$ cd nginx-1.14.2
[admin@app nginx-1.14.2]$ ls
auto CHANGES CHANGES.ru conf configure contrib html LICENSE man README src
安装依赖
yum install -y cpp-4.8.5-44.el7.x86_64.rpm keyutils-libs-devel-1.5.8-3.el7.x86_64.rpm libsepol-devel-2.5-10.el7.x86_64.rpm zlib-1.2.7-18.el7.x86_64.rpm
gcc-4.8.5-44.el7.x86_64.rpm krb5-devel-1.15.1-50.el7.x86_64.rpm libstdc++-devel-4.8.5-44.el7.x86_64.rpm zlib-devel-1.2.7-18.el7.x86_64.rpm
gcc-c++-4.8.5-44.el7.x86_64.rpm libcom_err-devel-1.42.9-19.el7.x86_64.rpm libverto-devel-0.2.5-4.el7.x86_64.rpm openssl-devel-1.0.2k-19.el7.x86_64.rpm
glibc-devel-2.17-317.el7.x86_64.rpm libkadm5-1.15.1-50.el7.x86_64.rpm mpfr-3.1.1-4.el7.x86_64.rpm pcre-8.32-17.el7.x86_64.rpm
glibc-headers-2.17-317.el7.x86_64.rpm libmpc-1.0.1-3.el7.x86_64.rpm pcre-devel-8.32-17.el7.x86_64.rpm
kernel-headers-3.10.0-1160.el7.x86_64.rpm libselinux-devel-2.5-15.el7.x86_64.rpm pkgconfig-0.27.1-4.el7.x86_64.rpm
以上所有依赖包均可在
https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/中找到
配置构建
使用 configure 命令配置构建。它定义了系统的各个方面,包括允许 nginx 用于连接处理的方法。最后它会创建一个 Makefile。
命令解析
./configure --prefix=/data/nginx --with-http_stub_status_module --with-stream --with-http_ssl_module
--prefix=path 定义将保存服务器文件的目录。这个相同的目录也将用于 configure 设置的所有相对路径(除了库源的路径)和 nginx.conf 配置文件中。它默认设置为 /usr/local/nginx 目录。
--with-http_stub_status_module 提供访问基本状态信息的途径。
/basic_status--with-stream 启用四层代理--with-http_ssl_module 可以构建一个模块,将 HTTPS 协议支持添加到 HTTP 服务器。默认情况下不构建此模块。构建和运行此模块需要 OpenSSL 库。
[admin@app nginx-1.14.2]$ sudo ./configure --prefix=/data/nginx --with-http_stub_status_module --with-stream --with-http_ssl_module
checking for OS
+ Linux 3.10.0-1160.el7.x86_64 x86_64
checking for C compiler ... found
+ using GNU C compiler
+ gcc version: 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC)
checking for gcc -pipe switch ... found
checking for -Wl,-E switch ... found
...
...
...
checking for OpenSSL library ... found
creating objs/Makefile
Configuration summary
+ using system PCRE library
+ using system OpenSSL library
+ zlib library is not used
nginx path prefix: "/data/nginx"
nginx binary file: "/data/nginx/sbin/nginx"
nginx modules path: "/data/nginx/modules"
nginx configuration prefix: "/data/nginx/conf"
nginx configuration file: "/data/nginx/conf/nginx.conf"
nginx pid file: "/data/nginx/logs/nginx.pid"
nginx error log file: "/data/nginx/logs/error.log"
nginx http access log file: "/data/nginx/logs/access.log"
nginx http client request body temporary files: "client_body_temp"
nginx http proxy temporary files: "proxy_temp"
nginx http fastcgi temporary files: "fastcgi_temp"
nginx http uwsgi temporary files: "uwsgi_temp"
nginx http scgi temporary files: "scgi_temp"
编译安装
make && make install
编译报错解决(完整的安装了上述依赖下面可不用看,主要给那些没有安装上述依赖包导致安装报错的人看)
报错1
[admin@app nginx-1.14.2]$ ./configure --prefix=/data/nginx --with-http_stub_status_module --with-stream --with-http_ssl_module
checking for OS
+ Linux 3.10.0-1160.el7.x86_64 x86_64
checking for C compiler ... not found
./configure: error: C compiler cc is not found
解决:安装gcc gcc-c++
报错2
[admin@app ~]$ rpm -ivh gcc-4.8.5-44.el7.x86_64.rpm gcc-c++-4.8.5-44.el7.x86_64.rpm
error: Failed dependencies:
cpp = 4.8.5-44.el7 is needed by gcc-4.8.5-44.el7.x86_64
glibc-devel >= 2.2.90-12 is needed by gcc-4.8.5-44.el7.x86_64
libmpc.so.3()(64bit) is needed by gcc-4.8.5-44.el7.x86_64
libmpfr.so.4()(64bit) is needed by gcc-4.8.5-44.el7.x86_64
libmpc.so.3()(64bit) is needed by gcc-c++-4.8.5-44.el7.x86_64
libmpfr.so.4()(64bit) is needed by gcc-c++-4.8.5-44.el7.x86_64
libstdc++-devel = 4.8.5-44.el7 is needed by gcc-c++-4.8.5-44.el7.x86_64
解决: 报错中需要安装cpp glibc-devel libmpc mpfr libstdc++-devel 并且glibc-devel依赖glibc-headers glibc-headers 依赖 kernel-headers libmpc.so.3所依赖的安装包为libmpc ,libmpfr.so.4依赖的安装包为 mpfr 最终如下:
[admin@app ~]$ sudo rpm -ivh gcc-4.8.5-44.el7.x86_64.rpm gcc-c++-4.8.5-44.el7.x86_64.rpm glibc-devel-2.17-317.el7.x86_64.rpm cpp-4.8.5-44.el7.x86_64.rpm glibc-headers-2.17-317.el7.x86_64.rpm libmpc-1.0.1-3.el7.x86_64.rpm mpfr-3.1.1-4.el7.x86_64.rpm kernel-headers-3.10.0-1160.el7.x86_64.rpm
Preparing... ################################# [100%]
Updating / installing...
1:mpfr-3.1.1-4.el7 ################################# [ 13%]
2:libmpc-1.0.1-3.el7 ################################# [ 25%]
3:cpp-4.8.5-44.el7 ################################# [ 38%]
4:kernel-headers-3.10.0-1160.el7 ################################# [ 50%]
5:glibc-headers-2.17-317.el7 ################################# [ 63%]
6:glibc-devel-2.17-317.el7 ################################# [ 75%]
7:gcc-4.8.5-44.el7 ################################# [ 88%]
8:gcc-c++-4.8.5-44.el7 ################################# [100%]
报错3
./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= option.
原因:ngx_http_rewrite_module模块依赖pcre 解决: 安装pcre pcre-devel
另外 ngx_http_gzip_module 依赖zlib安装包,需要提前安装zlib-devel
我采取的是使用rpm方式安装,否则需要在http://zlib.net/和http://www.pcre.org/下载响应二进制包并使用--with-pcre=path --with-zlib=path 指定路径安装
报错4
./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= option.
解决; 需要安装openssl-devel
[admin@app ~]$ rpm -ivh openssl-devel-1.0.2k-19.el7.x86_64.rpm
error: Failed dependencies:
krb5-devel(x86-64) is needed by openssl-devel-1:1.0.2k-19.el7.x86_64
openssl-devel 依赖 krb5-devel
error: Failed dependencies:
keyutils-libs-devel is needed by krb5-devel-1.15.1-50.el7.x86_64
libcom_err-devel is needed by krb5-devel-1.15.1-50.el7.x86_64
libkadm5(x86-64) = 1.15.1-50.el7 is needed by krb5-devel-1.15.1-50.el7.x86_64
libselinux-devel is needed by krb5-devel-1.15.1-50.el7.x86_64
libverto-devel is needed by krb5-devel-1.15.1-50.el7.x86_64
krb5-devel 依赖 keyutils-libs-devel libcom_err-devel libkadm5 libselinux-devel libverto-devel
[admin@app ~]$ rpm -ivh openssl-devel-1.0.2k-19.el7.x86_64.rpm krb5-devel-1.15.1-50.el7.x86_64.rpm keyutils-libs-devel-1.5.8-3.el7.x86_64.rpm libcom_err-devel-1.42.9-19.el7.x86_64.rpm libkadm5-1.15.1-50.el7.x86_64.rpm libselinux-devel-2.5-15.el7.x86_64.rpm libverto-devel-0.2.5-4.el7.x86_64.rpm
error: Failed dependencies:
libsepol-devel(x86-64) >= 2.5-10 is needed by libselinux-devel-2.5-15.el7.x86_64
pkgconfig(libsepol) is needed by libselinux-devel-2.5-15.el7.x86_64
libselinux-devel 依赖 libsepol-devel pkgconfig
[admin@app ~]$ sudo rpm -ivh openssl-devel-1.0.2k-19.el7.x86_64.rpm krb5-devel-1.15.1-50.el7.x86_64.rpm keyutils-libs-devel-1.5.8-3.el7.x86_64.rpm libcom_err-devel-1.42.9-19.el7.x86_64.rpm libkadm5-1.15.1-50.el7.x86_64.rpm libselinux-devel-2.5-15.el7.x86_64.rpm libverto-devel-0.2.5-4.el7.x86_64.rpm libsepol-devel-2.5-10.el7.x86_64.rpm pkgconfig-0.27.1-4.el7.x86_64.rpm
Preparing... ################################# [100%]
package pkgconfig-1:0.27.1-4.el7.x86_64 is already installed
pkgconfig已安装去掉这个包
[admin@app ~]$ sudo rpm -ivh openssl-devel-1.0.2k-19.el7.x86_64.rpm krb5-devel-1.15.1-50.el7.x86_64.rpm keyutils-libs-devel-1.5.8-3.el7.x86_64.rpm libcom_err-devel-1.42.9-19.el7.x86_64.rpm libkadm5-1.15.1-50.el7.x86_64.rpm libselinux-devel-2.5-15.el7.x86_64.rpm libverto-devel-0.2.5-4.el7.x86_64.rpm libsepol-devel-2.5-10.el7.x86_64.rpm
Preparing... ################################# [100%]
Updating / installing...
1:libsepol-devel-2.5-10.el7 ################################# [ 13%]
2:libselinux-devel-2.5-15.el7 ################################# [ 25%]
3:libverto-devel-0.2.5-4.el7 ################################# [ 38%]
4:libkadm5-1.15.1-50.el7 ################################# [ 50%]
5:libcom_err-devel-1.42.9-19.el7 ################################# [ 63%]
6:keyutils-libs-devel-1.5.8-3.el7 ################################# [ 75%]
7:krb5-devel-1.15.1-50.el7 ################################# [ 88%]
8:openssl-devel-1:1.0.2k-19.el7 ################################# [100%]
依赖太特么多了,总算解决完了 希望你不要遇到无外网安装,无外网安装遇到最小化安装什么包都没有的这种情况,如果你遇到了希望你直接使用我的依赖包安装,如果你没有用希望你能学习到我解决依赖报错的思路
参考
http://nginx.org/en/docs/configure.html