Nginx之RPM安装后添加第三方skicky模块

Nginx之RPM安装后添加第三方skicky模块

1. 场景简述

实际的生产环境或测试环境中,大家可能图简便会直接yum安装Nginx,来达到快速部署及上线的目的,但这样会带来一个问题,如果业务量增大,并且Nginx此时的配置无法满足性能上的要求,需要添加第三方模块来升级Nginx。但是yum方式安装的Nginx是无法直接添加第三方模块的,安装路径也是默认的。必须使用编译方式安装。

我们使用nginx -V命令可以查看yum方式安装的Nginx默认使用了哪些模块及功能,然后直接将如下图红框部分的命令copy出来,因为我们需要使用其重新编译Nginx。
在这里插入图片描述

注意:需要从Nginx官方站点下载一个同版本的可编译安装的包;我这里是Nginx/1.12.2。

2. 前期准备

  • 安装编译必备组件及解决依赖关系
[root@lbserver ~]# yum -y install gcc pcre-devel openssl-devel libxslt-devel libxml2 gd-devel geoip-devel perl-ExtUtils-Embed
  • 备份nginx配置文件及nginx程序等
[root@lbserver ~]# cp -r /etc/nginx{,_$(date +%F)bak}
[root@lbserver ~]# cp /usr/sbin/nginx{,_$(date +%F)bak}
  • 下载sticky和nginx-1.12.2的编译安装包
## 下载sticky包
[root@lbserver ~]# wget https://bitbucket.org/nginx-goodies/nginx-sticky-module-ng/get/master.tar.gz

## 下载nginx包
[root@lbserver ~]# wget http://nginx.org/download/nginx-1.12.2.tar.gz
[root@lbserver ~]# ll nginx-*
-rw-r--r-- 1 root root 981687 Jan  5 22:41 nginx-1.12.2.tar.gz
-rw-r--r-- 1 root root 120603 Jan  5 22:31 nginx-goodies-nginx-sticky-module-ng-08a395c66e42.tar.gz

3. 编译安装nginx

添加第三方模块只能通过编译安装的方式,我们按照1中所描述的,将nginx -V等到的configure结果复制出来。

## 解压
[root@lbserver ~]# tar xf nginx-goodies-nginx-sticky-module-ng-08a395c66e42.tar.gz 
[root@lbserver ~]# tar xf nginx-1.12.2.tar.gz 
[root@lbserver ~]# mv nginx-goodies-nginx-sticky-module-ng-08a395c66e42 nginx-sticky

## 查看不支持--with-sticky
[root@lbserver ~]# cd nginx-1.12.2
[root@lbserver nginx-1.12.2]# ./configure --help|grep sticky

## 编译升级安装,注意,这里去掉了--with-google_perftools_module
[root@lbserver nginx-1.12.2]# ./configure --add-module=/root/nginx-sticky/ --prefix=/usr/share/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/var/lib/nginx/tmp/client_body --http-proxy-temp-path=/var/lib/nginx/tmp/proxy --http-fastcgi-temp-path=/var/lib/nginx/tmp/fastcgi --http-uwsgi-temp-path=/var/lib/nginx/tmp/uwsgi --http-scgi-temp-path=/var/lib/nginx/tmp/scgi --pid-path=/run/nginx.pid --lock-path=/run/lock/subsys/nginx --user=nginx --group=nginx --with-file-aio --with-ipv6 --with-http_auth_request_module --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module=dynamic --with-http_image_filter_module=dynamic --with-http_geoip_module=dynamic --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_slice_module --with-http_stub_status_module --with-http_perl_module=dynamic --with-mail=dynamic --with-mail_ssl_module --with-pcre --with-pcre-jit --with-stream=dynamic --with-stream_ssl_module --with-debug --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -m64 -mtune=generic' --with-ld-opt='-Wl,-z,relro -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -Wl,-E'

.....

Configuration summary
  + using system PCRE library
  + using system OpenSSL library
  + using system zlib library

  nginx path prefix: "/usr/share/nginx"
  nginx binary file: "/usr/sbin/nginx"
  nginx modules path: "/usr/lib64/nginx/modules"
  nginx configuration prefix: "/etc/nginx"
  nginx configuration file: "/etc/nginx/nginx.conf"
  nginx pid file: "/run/nginx.pid"
  nginx error log file: "/var/log/nginx/error.log"
  nginx http access log file: "/var/log/nginx/access.log"
  nginx http client request body temporary files: "/var/lib/nginx/tmp/client_body"
  nginx http proxy temporary files: "/var/lib/nginx/tmp/proxy"
  nginx http fastcgi temporary files: "/var/lib/nginx/tmp/fastcgi"
  nginx http uwsgi temporary files: "/var/lib/nginx/tmp/uwsgi"
  nginx http scgi temporary files: "/var/lib/nginx/tmp/scgi"

./configure: warning: the "--with-ipv6" option is deprecated

## 注意,这里不要make install,不然会覆盖原来的安装,直接make即可;
[root@lbserver nginx-1.12.2]# make -j2

## 编译完成后,会在objs目录中生成一个nginx文件,先验证
[root@lbserver nginx-1.12.2]# objs/nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@lbserver nginx-1.12.2]# objs/nginx -V

## 停止nginx
[root@lbserver nginx-1.12.2]# systemctl stop nginx.service
## 替换nginx
[root@lbserver nginx-1.12.2]# cp objs/nginx /usr/sbin/nginx
cp: overwrite ‘/usr/sbin/nginx’? y

## 替换完成后重新启动nginx
[root@lbserver nginx-1.12.2]# systemctl start nginx.service
[root@lbserver nginx-1.12.2]# systemctl status nginx.service
● nginx.service - The nginx HTTP and reverse proxy server
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)
   Active: active (running) since Sat 2019-01-05 23:44:03 CST; 3s ago
  Process: 13990 ExecStart=/usr/sbin/nginx (code=exited, status=0/SUCCESS)
  Process: 13986 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=0/SUCCESS)
  Process: 13984 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/SUCCESS)
 Main PID: 13992 (nginx)
   CGroup: /system.slice/nginx.service
           ├─13992 nginx: master process /usr/sbin/nginx
           ├─13993 nginx: worker process
           ├─13994 nginx: cache manager process
           └─13995 nginx: cache loader process

Jan 05 23:44:03 lbserver systemd[1]: Starting The nginx HTTP and reverse proxy server...
Jan 05 23:44:03 lbserver nginx[13986]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
Jan 05 23:44:03 lbserver nginx[13986]: nginx: configuration file /etc/nginx/nginx.conf test is successful
Jan 05 23:44:03 lbserver systemd[1]: Started The nginx HTTP and reverse proxy server.


由此,即使是yum方式安装nginx,我们也可以通过编译的方式添加第三方模块。

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
在 macOS 上安装 nginx第三方模块可以使用 Homebrew 包管理器来简化过程。以下是安装第三方模块的步骤: 1. 首先,确保您已经安装了 Homebrew。如果您还没有安装,可以在终端中运行以下命令来安装 Homebrew: ``` /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" ``` 2. 安装 nginx。在终端中运行以下命令来使用 Homebrew 安装 nginx: ``` brew install nginx ``` 3. 找到您想要安装第三方 nginx 模块。您可以通过在搜索引擎上搜索或访问模块的官方网站来找到合适的模块。 4. 下载并解压第三方模块的源代码。将源代码解压到一个您可以方便访问的位置。 5. 进入解压后的模块源代码目录,并使用 `./configure` 命令配置编译选项。在这个命令中,您可以通过添加 `--add-dynamic-module=/path/to/module` 来指定要安装模块。例如: ``` ./configure --add-dynamic-module=/path/to/module ``` 请将 `/path/to/module` 替换为您要安装模块的实际路径。 6. 完成配置后,运行 `make` 命令编译 nginx。 7. 编译完成后,在终端中运行以下命令将编译好的模块复制到 nginx模块目录: ``` cp objs/*.so /usr/local/Cellar/nginx/{version}/libexec/modules/ ``` 请将 `{version}` 替换为您当前安装nginx 版本号。 8. 在终端中运行以下命令启动 nginx: ``` brew services start nginx ``` 现在,您已经成功安装第三方模块,并且可以在 nginx 的配置文件中启用和配置它们。 请注意,安装第三方模块可能需要一些编译工具和依赖项。如果出现任何错误或依赖项缺失,您可能需要安装相应的工具和库。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值