Home  >  Article  >  Operation and Maintenance  >  nginx four-layer load balancing configuration

nginx four-layer load balancing configuration

巴扎黑
巴扎黑Original
2017-06-23 14:18:143098browse

nginx four-layer load balancing configuration proxy Mysql cluster

The environment is as follows:

  1. ip 192.168.6.203 Nginx

  2. ip 192.168.6.* (multiple) Mysql

Step 1


Check whether Nginx has the stream module installed

If not installed, the installation steps are as follows

pkill nginx

##The stream module has been successfully added so far

Step 2


Configuring mysql load balancing case

Modify the Nginx configuration file nginx.conf as shown below

The test steps are as follows


  1. The back-end Mysql needs to be separated from reading and writing

  2. Create a user with corresponding permissions

  3. Connect to Nginx on the client to create the wuguiyunwei library for testing

Connect to the client to create a test library

The successful connection to 3307 reading library is as follows

Of course, for high availability, the following is the effect we want

The above configuration is just to let everyone understand the stream module. Of course, it can also be used in the production environment, but it still needs to be improved, such as node down elimination and some improved monitoring work. . .


The following is the nginx main configuration file of the experimental environment

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;
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 32k;
large_client_header_buffers 4 32k;
client_max_body_size 1024m;
client_body_buffer_size 10m;
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 64k;
fastcgi_buffers 4 64k;
fastcgi_busy_buffers_size 128k;
fastcgi_temp_file_write_size 128k;
fastcgi_intercept_errors on;
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;
}

This article comes from Wuguiyunwei.com

Our WeChat public account

######### QQ group: 602183872############ ###

The above is the detailed content of nginx four-layer load balancing configuration. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn