目的是利用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
