Nginx layer-4 load balancing configuration, nginx layer-4 load balancing
Configure the proxy Mysql Cluster Environment for nginx layer-4 Server Load balancer as follows: Step 1
Check whether the stream module is installed in Nginx.
The installation procedure is as follows:
This ensures that the stream module is successfully added without service interruption.
Step 2
Case study of configuring mysql Server Load balancer
Modify the Nginx configuration file nginx. conf as shown in Figure
The test procedure is as follows:
Create a test database through a client connection
The following figure shows the successful connection to the 3307 read database:
Of course, for high availability, the following is what we want.
The above configuration is only for your understanding of the stream module. Of course, it can also be used in the production environment, but it also needs to improve the work, such as removing node down and improving some monitoring work...
The following is the nginx master configuration file of the experiment environment:
User 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;
Multi_accept on;
}
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 = 10;
Server 192.168.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.177: 3306 weight = 10;
}
}
Http {
Include mime. types;
Default_type application/octet-stream;
Server_names_hash_bucket_size 128;
Client_header_buffer_size 32 k;
Large_client_header_buffers 4 32 k;
Client_max_body_size 1024 m;
Client_body_buffer_size 10 m;
Sendfile on;
Tcp_nopush on;
Keepalive_timeout 120;
Server_tokens off;
Tcp_nodelay on;
Fastcgi_connect_timeout 300;
Fastcgi_send_timeout 300;
Fastcgi_read_timeout 300;
Fastcgi_buffer_size 64 k;
Fastcgi_buffers 4 64 k;
Fastcgi_busy_buffers_size 128 k;
Fastcgi_temp_file_write_size 128 k;
Fastcgi_intercept_errors on;
Gzip on;
Gzip_buffers 16 8 k;
Gzip_comp_level 6;
Gzip_http_version 1.1;
Gzip_min_length 256;
Gzip_proxied any;
Gzip_vary on;
Gzip_types
Text/xml application/atom + xml application/rss + xml application/xhtml + xml image/svg + xml
Text/javascript application/x-javascript
Text/x-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 = 20 s;
Open_file_cache_valid 30 s;
Open_file_cache_min_uses 2;
Open_file_cache_errors on;
########################## Vhost
Include vhost/*. conf;
}
This article is from tortoise O & M wuguiyunwei.com
Our public account
QQ: 602183872