首頁  >  文章  >  運維  >  nginx四層負載平衡配置

nginx四層負載平衡配置

巴扎黑
巴扎黑原創
2017-06-23 14:18:143039瀏覽

nginx四層負載平衡配置代理Mysql集群

環境如下:

  1. ip 192.168.6.203 Nginx


ip 192.168.6.*(多台) Mysql

#步驟一

檢視Nginx是否安裝stream模組

#沒安裝則進行安裝操作步驟如下

pkill nginx


至此已成功新增stream模組
    步驟二
  1. 設定mysql負載平衡案例
  2. 修改Nginx設定檔nginx.conf 內容如下圖

  3. 測試步驟如下

#後端Mysql需要做好讀取與寫入分離

##建立好對應權限的使用者

到客戶端連線Nginx建立wuguiyunwei函式庫進行測試

在客戶端連線建立測試庫



連接3307讀取庫查看成功如下





當然為了高可用以下才是我們想要的效果


以上設定只是為了讓大家了解stream模組。當然也可以用於生產環境,但還需完善工作如節點down剔除,完善的一些監控工作。 。 。

以下是實驗環境的nginx主配檔


user www www;
worker_processes auto;

error_log /usr/local/nginx/logs/ error_nginx.log crit;

pid /var/run/nginx.pid;
worker_rlimit_nofile 51200;

events {
use epoll;
worker_connections 51200;
multiaccept;
}

stream {

server {
listen 3306;
proxy_pass Mysql_write;
}
##server {
listen 3307;
proxy_pass Mysql_read;
}

upstream Mysql_write {
server 192.168.6.19:3306 weight=10;
server 192.168.6.20:3306 weight=102168219.#16820:3306 weight=102.#68215; .6.18:3306 weight=10;
}
upstream Mysql_read {

server 192.168.6.175:3306 weight=10;

server 192.168.6.176:3306 weight=10#server 192.168.6.176:3306 weight=10#server 192.168.6.176:3306 weight=10#server 192.168.6.176:3306 weight=10#server 192.168.6.176:3306 weight=10#server. 6.177:3306 weight=10;
}

}
http {
include mime.types;
default_type application/octet-stream;
server_names_hash_bucket_size 128;

client_header_buffer_size 32k;

large_client_header_buffers 4 32k;
client_max_body_size 1024m;
client_body_buffer_size 10m;
sendfileon;##sendfile on;##sendfile on;##sendfile on;
##tcp_nodelay on;

fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
fastcgi_buffer_size 64k;
fast_buffers 4 64_bufferd _write_size 128k;
fastcgi_intercept_errors on;

gzip on;
gzip_buffers 16 8k;

gzip_comp_level 6;###gzip_http_version 1.1;###gzip_min_length 256;#p ###gzip_types###text/xml application/xml application/atom+xml application/rss+xml application/xhtml+xml image/svg+xml###text/javascript application/javascript application/x-javascript### text/x-json application/json application/x-web-app-manifest+json###text/css text/plain text/x-component###font/opentype application/x-font-ttf application/vnd. ms-fontobject###image/x-icon;###gzip_disable “MSIE [1-6]\.(?!.*SV1)”;###

open_file_cache max=1000 inactive=20s;
open_file_cache_valid 30s;
open_file_cache_min_uses 2;
open_file_cache_errors on;


## vhost
include vhost/*.conf;
}

 

 

####### ###這篇文章來自烏龜運維wuguiyunwei.com############我們的微信公共號碼##################### QQ群:602183872############ ####

以上是nginx四層負載平衡配置的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn