Nginx TCP代理及负载均衡stream模块简介

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/wangjianno2/article/details/75200952
Nginx从1.9.0开始发布ngx_stream_*_module模块,该模块支持tcp代理及负载均衡。注意和HTTP七层代理和负载均衡区别开来,stream模块是在四层上做的负载均衡哦。举个使用stream模块的nginx的配置:
worker_processes auto;
events {
    worker_connections  1024;
}
error_log /var/log/nginx_error.log info;

stream {
    upstream mysqld {
        hash $remote_addr consistent;
        server 192.168.1.42:3306 weight=5 max_fails=1 fail_timeout=10s;
        server 192.168.1.43:3306 weight=5 max_fails=1 fail_timeout=10s;
    }

    server {
        listen 3306;
        proxy_connect_timeout 1s;
        proxy_timeout 3s;
        proxy_pass mysqld;
    }
}
备注:如上是用nginx对后端的MySQL服务进行四层代理和负载均衡。


学习资料参考于:

猜你喜欢

转载自blog.csdn.net/wangjianno2/article/details/75200952