Tengine 四层代理:

1 ) 安装tengine ( nginx1.9 以上版本 编译以后要支持stream 模块)

1.1 ) tengine(nginx) 一定要是nginx-1.9.X 以上的版本,否则不支持stream功能:
/data/nginx/sbin/nginx -V
Tengine version: Tengine/2.3.2
nginx version: nginx/1.17.3
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC)
built with OpenSSL 1.0.2k-fips 26 Jan 2017
...... 1.2 ) 编译安装tengine-2.3.2 开启的功能略有改变:
wget http://tengine.taobao.org/download/tengine-2.3.2.tar.gz && tar -zxf tengine-2.3.2.tar.gz
cd tengine-2.3.2
./configure --prefix=/data/nginx --user=fmw --group=fmw --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_stub_status_module --with-http_gzip_static_module --with-pcre --with-stream --with-stream=dynamic --with-stream_ssl_module --with-stream_realip_module # --with-http_concat_modul 这个参数可能因为是开发版本 还没有加入2.3.2版本,静待后面的正式版本.
# --with-stream --with-stream=dynamic --with-stream_ssl_module --with-stream_realip_module
# 这三个开启的就是nginx的stream 功能. make && make install

2 ) 配置 nginx 的stream 模块 来做TCP代理

2.1 ) 创建配置目录:
mkdir -p /data/nginx/{pid,temp,proxycache
mkdir -p /data/nginx/conf/tcp/
########################### 四层代理的配置 #####################################
## 注意: 1 ) nginx 版本要在1.9 以上, tengine 基于那个版本开发的 去官网查
## 注意: 2 )编译时要加入--with-stream --with-stream_ssl_module --with-stream_realip_module
## 安装好的可以通过 nginx -V 来查看具体编译的参数. 没有加入的重新编译加入即可.
## 注意: 3 )主配置文件一定要引入 nginx_stream_modele.so;
vim tcp.conf stream {
upstream redis_host {
server 10.10.116.206:6379;
} server {
listen 10.10.4.209:6379;
proxy_connect_timeout 5s;
proxy_timeout 5s;
proxy_pass redis_host;
} }
#################################################################################### 2.2 ) 主配置文件:
load_module /data/nginx/modules/ngx_stream_module.so; #这行一定要加上否则会出现stream模块找不到的错误.
user nginx nginx;
worker_processes auto;
worker_cpu_affinity 0001 0010;
pid /data/nginx/pid/nginx.pid;
events {
worker_connections 65536;
use epoll;
accept_mutex on;
multi_accept on;
}
include /data/nginx/conf/tcp/*.conf;
http {
include mime.types;
default_type application/octet-stream;
log_format access_json '{"@timestamp":"$time_iso8601",'
'"host":"$server_addr",'
'"clientip":"$remote_addr",'
'"size":$body_bytes_sent,'
'"responsetime":$request_time,'
'"upstreamtime":"$upstream_response_time",'
'"upstreamhost":"$upstream_addr",'
'"http_host":"$host",'
'"uri":"$uri",'
'"domain":"$host",'
'"xff":"$http_x_forwarded_for",'
'"referer":"$http_referer",'
'"tcp_xff":"$proxy_protocol_addr",'
'"http_user_agent":"$http_user_agent",'
'"status":"$status"}';
access_log /data/nginx/logs/access_json.log access_json;
proxy_cache_path /data/nginx/proxycache levels=1:2:2 keys_zone=proxycache:512m inactive=10m max_size=1g;
sendfile on;
directio 2m;
keepalive_timeout 65 65;
keepalive_requests 3;
client_max_body_size 10m;
client_body_buffer_size 16k;
client_body_temp_path /data/nginx/temp 1 2 2;
keepalive_disable msie6;
open_file_cache max=1000 inactive=20s;
open_file_cache_valid 30s;
open_file_cache_min_uses 2;
open_file_cache_errors on;
server_tokens off;
gzip on;
gzip_comp_level 5;
gzip_min_length 1k;
gzip_types text/plain application/javascript application/x-javascript text/cssapplication/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png;
gzip_vary on; server {
listen 80;
server_name localhost default_server;
charset utf-8;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
}
location /nginx_status {
stub_status on;
allow 192.168.0.0/16;
allow 127.0.0.1;
allow 172.18.0.0/16;
deny all;
}
error_page 500 502 503 504 404 /50x.html;
location = /50x.html {
root html;
} location ~ /\.password {
deny all;
}
}
}

官方文档:

https://nginx.org/en/docs/stream/ngx_stream_core_module.html

Tengine 四层代理:的更多相关文章

  1. Tengine 反向代理状态检测

    Tengine 反向代理状态检测 安装Tengine: 编译安装./configure --prefix=/usr/loca/nginx make && make install 配置 ...

  2. nginx 的四层代理

    需要编译四层模块 [root@python vhast]# cd ~/nginx-1.15.9/ [root@python nginx-1.15.9]# ./configure --prefix=/d ...

  3. Nginx四层代理

    Nginx支持四层代理 http://nginx.org/en/docs/stream/ngx_stream_core_module.html 该ngx_stream_core_module模块自1. ...

  4. k8s入坑之路(12)ingress-nginx安装配置四层代理

    ingress官方文档地址:http://docs.kubernetes.org.cn/  https://feisky.gitbooks.io/kubernetes/content/plugins/ ...

  5. 基于Netty的四层和七层代理性能方面的一些压力测试

    本文我们主要是想测试和研究几点: 基于Netty写的最简单的转发HTTP请求的程序,四层和七层性能的差异 三种代理线程模型性能的差异,下文会详细解释三种线程模型 池和非池化ByteBuffer性能的差 ...

  6. Nginx的四层和七层代理

    理论部分: 所谓四层负载均衡,也就是主要通过报文中的目标地址和端口,再加上负载均衡设备设置的服务器选择方式,决定最终选择的内部服务器,它一般走的是tcp,udp协议    所谓七层负载均衡,也称为“内 ...

  7. nginx 反向代理和正向代理功能 第六章

    一:Nginx作为正向代理服务器: 1.正向代理:代理(proxy)服务也可以称为是正向代理,指的是将服务器部署在公司的网关,代理公司内部员工上外网的请求,可以起到一定的安全作用和管理限制作用,正向代 ...

  8. Nginx 配置 stream SSL 第四层 代理

    场景:服务器F针对访问终端需要添加白名单操作,由到终端数量较多,所以用了一台代理服务器 P,在服务F中添加 服务器P IP地址的白名单,所有终端访问服务器P 由于我已经安装过 Nginx 所以只需要添 ...

  9. 14、Nginx四层负载均衡

    1.Nginx四层负载均衡基本概述 1.1.什么是四层负载均衡 四层负载均衡基于传输层协议包来封装的(如:TCP/IP),那我们前面使用到的七层是指的应用层,它的组装在四层基础之上,无论四层还是七层都 ...

随机推荐

  1. AcWing 276. I-区域

    题目链接 设 \(0\) 为单调伸长, \(1\) 为单调伸短. 设 \(f[i][j][l][r][x(0 / 1)][y (0 / 1)]\) 为第 \(i\) 行,已经选出\(j\)个格子,第\ ...

  2. protobuf 协议浅析

    目录 Protobuf 协议浅析 1. Protobuf 介绍 1.1 Protobuf 基本概念 1.2 Protobuf 的优点 1.3 Protobuf, JSON, XML 的区别 2. Pr ...

  3. [从源码学设计]蚂蚁金服SOFARegistry之时间轮的使用

    [从源码学设计]蚂蚁金服SOFARegistry之时间轮的使用 目录 [从源码学设计]蚂蚁金服SOFARegistry之时间轮的使用 0x00 摘要 0x01 业务领域 1.1 应用场景 0x02 定 ...

  4. json 注释

    一.背景 今天聊个小东西,Json的的的注释.Json十分常见,大家用的很多,在语法上,规范的Json要求,文件里不可以写注释.原因呢,我调查了一下: I removed comments from ...

  5. Oracle数据导入Mysql中

    一.Navicat Premium中的数据迁移工具 为了生产库释放部分资源,需要将API模块迁移到mysql中,及需要导数据. 尝试了oracle to mysql工具,迁移时报错不说,这么大的数据量 ...

  6. 算法(Java实现)—— KMP算法

    KMP算法 应用场景 字符串匹配问题 有一个字符串str1 = " hello hello llo hhello lloh helo" 一个子串str2 = "hello ...

  7. Maven笔记之面试题合集

    简介:收集整理了网上关于Maven的面试问题,准备面试使用,答案通过各种资料查证编写. 1.什么是Maven? Maven主要服务于基于java平台的项目构建,依赖管理和项目信息管理.Maven项目对 ...

  8. python SQLAlchemy反射生成models

    1.安装SQLAcodegen pip install sqlacodegen 2.使用sqlacodegen生成案列 sqlacodegen mysql://root:123456@127.0.0. ...

  9. pygal之掷骰子 - 2颗面数为6的骰子

    python之使用pygal模拟掷两颗面数为6的骰子的直方图,包含三个文件,主文件,die.py,dice_visual.py,20200527.svg.其中最后一个文件为程序运行得到的结果. 1,d ...

  10. python字符串、列表通过值找索引/键

    python透过"值"找字符串和列表中的索引和键. 1 #!usr/bin/env python3 2 #-*- coding=utf-8 -*- 3 4 ''' 5 python ...