当前位置: 首页 > news >正文

Tengine/Nginx 安装以及模块查看与扩展

文章目录

  • Tengine/Nginx 安装以及模块查看与扩展
  • 安装
    • 安装依赖
    • 下载 Tengine
    • 编译 Tengine
    • 配置环境变量
    • 配置 nginx.conf
    • 检查启动
      • 配置系统启动项
      • 启动以及停止
  • 加载模块
    • 查看已编译模块
    • 常见模块及作用
    • 重新编译 Tengine
    • 测试配置并平滑重启
  • 常见问题排查
  • 小知识点
  • 小结


Tengine/Nginx 安装以及模块查看与扩展

Tengine 是淘宝开源的 Nginx 增强版,增加了负载均衡、动态模块、Sticky Session 等功能。本指南将从安装、模块查看到安全运维实践进行详细说明。


安装

安装依赖

yum install -y gcc make wget tar pcre pcre-devel zlib zlib-devel openssl openssl-devel openssl-dev 

说明:Tengine 需要 C 编译环境及一些系统库,缺少依赖会导致编译失败。

下载 Tengine

cd /usr/local/src
wget http://tengine.taobao.org/download/tengine-3.1.0.tar.gz
tar zxvf tengine-3.1.0.tar.gz
cd tengine-3.1.0

编译 Tengine

./configure --prefix=/usr/local/tengine 
make -j$(nproc)
make install

说明:根据需求选择要编译的模块,可以添加第三方模块的路径。
安装完成后,Tengine 默认路径在 /usr/local/tengine

配置环境变量

echo 'export PATH=$PATH:/usr/local/tengine/sbin' >> /etc/profile
source /etc/profile

配置 nginx.conf

cp /usr/local/tengine/conf/nginx.conf /usr/local/tengine/conf/nginx.conf.bak
vi /usr/local/tengine/conf/nginx.conf
worker_processes  auto;worker_rlimit_nofile 65535;
events {worker_connections  102400;
}http {include       mime.types;default_type  application/octet-stream;log_format  json  '$remote_addr - $remote_user [$time_local] "$request" ''$status $body_bytes_sent "$http_referer" ''"$http_user_agent" "$http_x_forwarded_for"';log_format  main  '$remote_addr - $remote_user [$time_local] "$request" ''$status $body_bytes_sent "$http_referer" ''"$http_user_agent" "$http_x_forwarded_for"';access_log  logs/access.log  main;sendfile        on;#tcp_nopush     on;keepalive_timeout  65;gzip  on;# 上传文件大小限制client_max_body_size 100M;include /usr/local/tengine/conf.d/*.conf;
}

检查启动

mkdir -p /usr/local/tengine/conf.d
# 测试配置是否正确
nginx -t
# 查看模块是否生效
nginx -V

示例输出:

[root@test ~]# nginx -t
nginx: the configuration file /usr/local/tengine/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/tengine/conf/nginx.conf test is successful
[root@test ~]# nginx -V
Tengine version: Tengine/3.1.0
nginx version: nginx/1.24.0
built by gcc 11.5.0 20240719 (Red Hat 11.5.0-5) (GCC) 
built with OpenSSL 3.2.2 4 Jun 2024
TLS SNI support enabled
configure arguments: --prefix=/usr/local/tengine/
[root@test ~]# 
  • nginx -V:显示编译信息和配置参数。

  • 解析:

    • Tengine version: Tengine/3.1.0 → 你安装的 Tengine 版本是 3.1.0。
    • nginx version: nginx/1.24.0 → 内核 Nginx 版本是 1.24.0。
    • built by gcc 11.5.0 → 用 GCC 11.5 编译。
    • built with OpenSSL 3.2.2 → 支持最新的 OpenSSL 3。
    • TLS SNI support enabled → 支持多域名 SSL(Server Name Indication)。
    • configure arguments: --prefix=/usr/local/tengine/ → 安装目录是 /usr/local/tengine/,只编译了最基础模块,没有像 http_ssl_modulesticky_session 这种可选模块。

配置系统启动项

/usr/lib/systemd/system/tengine.service

[Unit]Description=Nginx Web ServerAfter=network.target[Service]Type=forkingExecStart=/usr/local/tengine/sbin/nginxExecReload=/usr/local/tengine/sbin/nginx -s reloadExecStop=/usr/local/tengine/sbin/nginx -s stopKillMode=processRestart=on-failureRestartSec=5s[Install]
WantedBy=multi-user.target

启动以及停止

# 查看tengine服务状态
systemctl status tengine
# 启动tengine服务
systemctl start tengine
# 停止tengine服务
systemctl stop tengine
# 重启tengine服务
systemctl restart tengine
# 开机自启tengine服务
systemctl enable tengine
# 关闭开机自启tengine服务
systemctl disable tengine
# 查看tengine日志
tail -f /usr/local/tengine/logs/error.log
# 查看tengine访问日志
tail -f /usr/local/tengine/logs/access.log

生产环境谨慎操作哦

加载模块

查看已编译模块

Tengine/Nginx 的模块是在编译时通过 ./configure 指定的。查看当前安装的模块,可以使用以下命令:

nginx -V

示例输出:

Tengine version: Tengine/3.1.0
nginx version: nginx/1.24.0
built by gcc 11.5.0 20240719 (Red Hat 11.5.0-5) (GCC) 
built with OpenSSL 3.2.2 4 Jun 2024
TLS SNI support enabled
configure arguments: --prefix=/usr/local/tengine/
  • configure arguments: --prefix=/usr/local/tengine/ → 安装目录是 /usr/local/tengine/,只编译了最基础模块,没有像 http_ssl_modulesticky_session 这种可选模块。

常见模块及作用

模块名称功能简介
http_stub_status_module监控 Nginx 状态
http_v2_module支持 HTTP/2
http_realip_module获取客户端真实 IP
http_ssl_module支持 HTTPS
http_lua_moduleLua 脚本扩展
http_upstream_sticky_module支持 Sticky Session

注意:如果看到 unknown directive "sticky",说明 Sticky Session 模块未编译,需要重新编译或加载动态模块。

重新编译 Tengine

增加模块需要重新编译 Tengine,在 ./configure 阶段指定需要的模块。例如:

cd tengine-3.1.0
./configure --prefix=/usr/local/tengine --add-module=./modules/ngx_http_upstream_session_sticky_module
make -j$(nproc)
make install

然后验证模块是否生效:

nginx -V

示例输出:

Tengine version: Tengine/3.1.0
nginx version: nginx/1.24.0
built by gcc 11.5.0 20240719 (Red Hat 11.5.0-5) (GCC) 
built with OpenSSL 3.2.2 4 Jun 2024
TLS SNI support enabled
configure arguments: --prefix=/usr/local/tengine --add-module=./modules/ngx_http_upstream_session_sticky_module

测试配置并平滑重启

# 测试配置是否正确
nginx -t# 平滑重启
nginx -s reload

平滑重启不会中断正在处理的请求,保证业务可用。



常见问题排查

问题原因解决方法
unknown directive “sticky”模块未编译或未加载编译模块或使用 load_module 动态加载
make 报错缺少依赖或版本不匹配安装依赖或使用对应模块源码
nginx -s reload 报错配置语法错误使用 nginx -t 检查配置

小知识点

ngx_http_upstream_session_sticky_module 模块用于实现 Sticky Session 功能,确保同一用户的请求被路由到同一后端服务器。常见配置示例如下:

upstream backend {session_sticky cookie=route domain=.example.com mode=insert; # 设置 Sticky Sessionserver 10.0.0.1:8080;server 10.0.0.2:8080;
}server {listen 80;server_name localhost;location / {proxy_pass http://backend;}
}

小结

本文讲解了:

  • Tengine 安装与依赖
  • 已编译模块查看方法
  • 平滑重启及业务安全注意事项
  • 常见问题排查

通过以上步骤,您可以灵活管理 Tengine 模块,保证业务稳定运行,同时支持高级功能扩展,如 Sticky Session、Lua 扩展等。



文章转载自:

http://ZWvYzQ1t.Lwzgn.cn
http://xMFYXOrO.Lwzgn.cn
http://gGQkhAvd.Lwzgn.cn
http://HNuJx4qL.Lwzgn.cn
http://fgvQEFQw.Lwzgn.cn
http://pQC9U25l.Lwzgn.cn
http://VjKEXreB.Lwzgn.cn
http://2GgKpgVm.Lwzgn.cn
http://jdKY1kr7.Lwzgn.cn
http://1TIsC26z.Lwzgn.cn
http://BzmWAyvR.Lwzgn.cn
http://XnH0HOzq.Lwzgn.cn
http://HUUVHZOD.Lwzgn.cn
http://Hm0NWCjw.Lwzgn.cn
http://cFhJoFt8.Lwzgn.cn
http://A7Lem34F.Lwzgn.cn
http://pWBYtLjC.Lwzgn.cn
http://tjoqSqTi.Lwzgn.cn
http://nNliVxhy.Lwzgn.cn
http://qrcA5uw8.Lwzgn.cn
http://e8ogqTS6.Lwzgn.cn
http://G4aBFX43.Lwzgn.cn
http://0PQH7zwX.Lwzgn.cn
http://ApL2CQPG.Lwzgn.cn
http://yWS0SVlQ.Lwzgn.cn
http://u914EH3j.Lwzgn.cn
http://JLQEUCMp.Lwzgn.cn
http://TQTyjcrq.Lwzgn.cn
http://doaNiWdr.Lwzgn.cn
http://dx2dauYq.Lwzgn.cn
http://www.dtcms.com/a/367635.html

相关文章:

  • 新一代实时检测工具——YOLOv13本地部署教程,复杂场景,一目了然!
  • html学习:
  • 多线程顺序打印ABC的两种实现方式:synchronized与Lock机制
  • 苍穹外卖优化过程遇到的问题
  • android源码角度分析Handler机制
  • 25高教社杯数模国赛【E题保姆级思路+问题分析】
  • 政务级数据安全!小陌GEO引擎的私有化部署实践指南
  • 卫星通信+地面网络融合 Sivers半导体毫米波技术打通智慧交通最后一公里
  • 理解进程栈内存的使用
  • C4.5决策树(信息增益率)、CART决策树(基尼指数)、CART回归树、决策树剪枝
  • 前端vue常见标签属性及作用解析
  • Vue基础知识-脚手架开发-子传父-props回调函数实现和自定义事件($on绑定、$emit触发、$off解绑)实现
  • 铭记抗战烽火史,科技强企筑强国 | 金智维开展抗战80周年主题系列活动
  • 无人机信号防干扰技术难点分析
  • 企业白名单实现【使用拦截器】
  • 硬件(二) 中断、定时器、PWM
  • 11 月广州见!AUTO TECH China 2025 汽车内外饰展,解锁行业新趋势
  • 【multisim汽车尾灯设计】2022-12-1
  • 工业人形机器人运动速度:富唯智能重新定义智能制造效率新标准
  • 惊爆!耐达讯自动化RS485转Profinet,电机连接的“逆天神器”?
  • Android 权限管理机制
  • MATLAB平台实现人口预测和GDP预测
  • jQuery的$.Ajax方法分析
  • 实现自己的AI视频监控系统-第三章-信息的推送与共享4
  • Vben5 封装的组件(豆包版)
  • 研发文档更新滞后的常见原因与解决方法
  • AI工具深度测评与选型指南 - Lovart专题
  • 卡方检验(独立性检验)
  • 【C语言】第四课 指针与内存管理
  • Mac开发第一步 - 安装Xcode