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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM