Kylin v10 编译安装Tengine
编译安装 Tengine 3.1.0
安装依赖
编译
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30./configure \ --prefix=/usr/local/tengine \ --conf-path=/etc/nginx/nginx.conf \ --error-log-path=/var/log/nginx/error.log \ --http-log-path=/var/log/nginx/access.log \ --pid-path=/run/nginx.pid \ --user=nginx \ --group=nginx \ --with-http_ssl_module \ --with-pcre-jit \ --with-pcre \ --with-http_v2_module \ --with-http_realip_module \ --with-http_stub_status_module \ --with-stream \ --with-stream_ssl_module \ --with-stream_ssl_preread_module \ --with-stream_sni \ --with-jemalloc \ --with-file-aio \ --with-threads \ --with-compat \ --with-ipv6 \ --with-http_auth_request_module \ --with-http_dav_module \ --add-module=./modules/ngx_http_upstream_dynamic_module \ --add-module=./modules/ngx_http_upstream_dyups_module \ --add-module=./modules/ngx_http_upstream_check_module make && make install
动态管理 upstream
ngx_http_upstream_dynamic_module
运行期动态探活/权重/下线 upstreab节点(自动)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21# 配置示例 upstream backend { server 10.0.0.1:8080 weight=5 max_fails=3 fail_timeout=10s; server 10.0.0.2:8080 weight=5 max_fails=3 fail_timeout=10s; server 10.0.0.3:8080 backup; } server { listen 80; location / { proxy_pass http://backend; proxy_connect_timeout 3s; proxy_read_timeout 10s; } } max_fails=3 # 连续失败3次 fail_timeout=10s # 10秒内失败就下线 timeout 过后 # 自动重试上线ngx_http_upstream_dyups_module
通过 http 接口,动态新增 / 修改 upstream 配置
支持:新增 upstream、修改 server 列表、删除 upstream、查询 upstream
必须配置共享内存,否则不能使用,如果没有 zone,dyups 直接失效
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17# 示例配置 upstream test_backend { zone backend 64k; server 127.0.0.1:8080 weight=5 max_fails=3 fail_timeout=10s; server 127.0.0.1:8081 weight=5 max_fails=3 fail_timeout=10s; } server { listen 127.0.0.1:9999; location /upstream { dyups_interface; allow 127.0.0.1; deny all; } }查看当前 upstream
curl http://127.0.0.1:9999/upstream/test_backend
新增/修改 upstream(新增upstream时,在执行命令时,一定要添加上旧的节点,否则就是修改节点)
curl -X POST http://127.0.0.1:9999/upstream/test_backend -d 'server 127.0.0.1:8080; server 127.0.0.1:8081; server 127.0.0.1:8082 weight=10; server 127.0.0.1:8083 weight=10;'
删除 upstream
curl -X DELETE http://127.0.0.1:9999/upstream/test_backend
健康检查模块
ngx_http_upstream_check_module
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18# 示例配置 upstream test_backend { server 127.0.0.1:8080 max_fails=3 fail_timeout=10s; server 127.0.0.1:8081 max_fails=3 fail_timeout=10s; check interval=5000 rise=2 fall=3 timeout=1000 type=http; check_http_send "GET /health HTTP/1.0\r\n\r\n"; check_http_expect_alive http_2xx http_3xx; } interval # 健康检查间隔,单位 ms rise # 节点连续健康检查成功次数达到该值后标记为 UP fall # 节点连续健康检查失败次数达到该值后标记为 DOWN timeout # 每次健康检查的超时时间,单位 ms type # 检测类型,可以是 tcp 或 http check_http_send # 健康检查发送的 HTTP 请求 check_http_expect_alive # 判断节点健康的 HTTP 返回码,支持 http_2xx、http_3xxhttp://localhost:8080/status?format=json
http://localhost:8080/status?format=csv
QUIC/HTTP 3
HTTP/3 必须 TLS 1.3,OpenSSL 版本 >= 1.1.1
提前下载并编译 XQUIC
编译完成后,记住库文件 include 和头文件 lib 路径
编译
| |
Brotli 压缩
获取 Brotli 模块
编译 tengine
启用模块
load_module 必须在最前面
http 块开启 brotli
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24http { brotli on; brotli_comp_level 6; # 推荐 4~6,生产平衡点 brotli_buffers 16 8k; brotli_types text/plain text/css application/json application/javascript text/javascript text/xml application/xml application/xml+rss image/svg+xml font/ttf font/otf application/vnd.ms-fontobject; # gzip 兜底 gzip on; gzip_comp_level 5; gzip_types text/plain text/css application/json application/javascript; }验证

