nginx的stream模块实现mysql负载均衡

目的是利用nginx中的stream模块实现mysql数据库的负载均衡

查看是否安装了stream模块 用./nginx -V


 

/usr/local/nginx/conf/nginx.conf 配置stream模块

其中stream模块与http模块级别相同

stream {

    upstream mysql_3306 {

        server 140.143.11.169:3306 weight=10;

     server 182.61.55.179:3306  weight=10;

    }

    server {

        listen 3307;   # 外部访问我的3007

        proxy_connect_timeout 20s;

        proxy_pass mysql_3306;  # 从这里转发到 upstream

    }

}

backend 表示当其他的不能用的时候我才能用

down   表示不能用

先进入 /usr/local/nginx/sbin 目录

停止 ./nginx -s stop

重启 ./nginx -s reload

启动 ./nginx

原文地址:https://www.cnblogs.com/huanglei2010/p/10272134.html