[关闭]
@yulongsun 2018-07-26T02:45:04.000000Z 字数 1818 阅读 948

网关技术调研 - Nginx介绍&安装&升级

网关技术调研


介绍

安装

安装步骤:

1、下载:
https://nginx.org/en/download.html

下载

2.解压

  1. tar -xvzf nginx-1.14.0.tar.gz

3.编译

  1. ./configure --prefix=/opt/nginx

--prefix 用于指定nginx编译后的安装目录
--add-module 为添加的第三方模块
--with..._module 表示启用的nginx模块

遇到的问题


  1. 问题:No package nginx available.
    Nothing to do
    原因:nginx位于第三方源里面,不在centos的官方源里面。所以需要安装epel(Extra Packages For Enterprise Linux)
    解决:
    • yum install epel-release
    • yum install nginx

  2. 问题:./configure: error: C compiler cc is not found
    解决:yum install gcc
    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.
    解决:yum -y install pcre-devel
    4.
    问题:./configure: error: the HTTP gzip module requires the zlib library.
    You can either disable the module by using --without-http_gzip_module
    option, or install the zlib library into the system, or build the zlib library
    statically from the source with nginx by using --with-zlib= option.
    解决:
    yum install -y zlib-devel

升级

以扩展nginx_upstream_check_module为例。

  1. nginx源码位置:/root/nginx-1.14.0
  2. nginx_upstream_check_module位置:/root/nginx-1.14.0/nginx_upstream_check_module-master

1、下载补丁包https://github.com/yaoweibin/nginx_upstream_check_module
2、在nginx目录下执行

  1. [root@node4 /]# patch -p1 </root/nginx-1.14.0/nginx_upstream_check_module-master/check_1.12.1+.patch

3、带上新模块重新编译

  1. ./configure --prefix=/opt/nginx --add-module=/root/nginx-1.14.0/nginx_upstream_check_module-master
  1. make

注意是make,不是make install,否则会覆盖安装

4、平滑重启
编译完成后会在objs目录下生成新的nginx二进制文件。
image_1cj2peevf1thlsmo1b4b12tv1evn13.png-18.2kB

5、替换脚本

  1. cp /root/nginx-1.14.0/objs/nginx /opt/nginx/sbin/nginx

nginx -s reload

遇到的问题:
image_1cj2ng9m71sn5kkcnr4g17lh9.png-19.9kB
-p0 选项要从当前目录查找目的文件(夹)
-p1 选项要忽略掉第一层目录,从当前目录开始查找。

在这里以实例说明:
old/modules/pcitable
如果使用参数-p0,那就表示从当前目录找一个叫做old的文件夹,在它下面寻找modules下的pcitable文件来执行patch操作。
如果使用参数-p1,那就表示忽略第一层目录(即不管old),从当前目录寻找modules的文件夹,在它下面找pcitable。这样的前提是当前目录必须为modules所在的目录。

插件

image_1cj7ncditqb5opi1bn81ub71imd1p.png-151.2kB

参考资料:
1. https://zhangge.net/4856.html

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注