nginx默认是没有编译这个模块的,要使用stream模块,编译的时候记得加上--with-stream这个参数即可。
./configure --user=www --group=www --prefix=/nginx/ --with-http_stub_status_module --with-http_ssl_module --with-pcre -with-stream
make
make install
下面是4层转发配置文件
worker_processes 1;
events {
worker_connections 1024;
}
stream {
### 定义多个上游服务器
upstream k8s{
### 定义TCP模块上游服务器
server 192.168.3.18:6444;
server 192.168.3.17:6444 backup;
}
log_format proxy '$remote_addr - [$time_local] $status $protocol'
' "$upstream_addr" "$upstream_bytes_sent" "$upstream_connect_time"';
server {
listen 6443;
proxy_pass k8s;
access_log /nginx/tcp_access.log proxy;
}
}