sponsored links

nginx TCP 负载均衡配置

stream{
    upstream backend {
        hash $remote_addr consistent;
        server 192.168.0.129:3306 weight=5 max_fails=3 fail_timeout=30s;
        server 192.168.0.129:3307 weight=4 max_fails=3 fail_timeout=30s;
    }
    
    server {
        listen 12345 so_keepalive=on; #so_keepalive=on  保持长连接
        proxy_connect_timeout 3s;
        #proxy_timeout 3s;  3秒内没有数据交互就断开连接
        proxy_pass backend;
    }
}

Tags: