0
点赞
收藏
分享

微信扫一扫

nginx第三方负载均衡模块安装


背景

使用 nginx 时,有时候内置模块不能满足自己需求时,可以通过集成第三方插件的方式来实现,例如 下面的负载均衡策略,再例如缓存的主动清理插件等等,都可以通过一下步骤来添加。

备份 Nginx

建议

# 源码路径
cp -r /usr/local/soft/nginx-1.18.0 /usr/local/soft/nginx-1.18.0_back
# 安装编译后的路径
cp -r /usr/local/soft/nginx /usr/local/soft/nginx_back

下载解压

mkdir -p /usr/local/soft/nginx/modules && cd /usr/local/soft/nginx/modules
wget https://files.cngs.com/files/ztlsir/nginx-upstream-fair-master.zip
unzip nginx-upstream-fair-master.zip

备份 Nginx 启动文件

cp -r /usr/local/soft/nginx/sbin/nginx /usr/local/soft/nginx/sbin/nginx_back

在 Nginx 原解压根目录下add module

也就是 Nginx 源码位置

注意,如果之前已经启用了、添加了其他的模块,需要把–add-module的参数加在最后面。
先查看之前的启动参数:

# 查看之前启动参数
cd /usr/local/soft/nginx/sbin && ./nginx -V
# 添加新模块
cd /usr/local/soft/nginx-1.18.0 &&
./configure --prefix=/usr/local/soft/nginx --with-http_stub_status_module --with-http_ssl_module --add-module=/usr/local/soft/nginx/modules/nginx-upstream-fair-master

在nginx原解压根目录下 make,确保没有错误

cd /usr/local/soft/nginx-1.18.0 && make

检查是否安装成功

cd /usr/local/soft/nginx-1.18.0/objs/ && ./nginx -V

复制objs目录下的nginx文件到sbin目录,覆盖原文件

cd /usr/local/soft/nginx-1.18.0/objs/ && cp -rf nginx /usr/local/soft/nginx/sbin/

重启

# 先停止
cd /usr/local/soft/nginx/sbin && ./nginx -s stop
# 启动
cd /usr/local/soft/nginx/sbin && ./nginx -c /usr/local/soft/nginx/conf/nginx.conf
# 检查启动参数
./nginx -V


举报

相关推荐

0 条评论