nginx四层负载均衡配置,Nginx服务器配置

By admin in 美高梅手机版4858 on 2019年3月25日

nginx四层负载均衡布局代理Mysql集群

nginx四层负载均衡布局,nginx四层负载均衡

美高梅手机版4858 1

nginx四层负载均衡配置代理Mysql集群

Nginx服务器配置首要参数

环境如下:

  1. ip 192.168.6.203 Nginx
  2. ip 192.168.6.*(多台) Mysql

nginx四层负载均衡布局代理Mysql集群

环境如下:

  1. ip 192.168.6.203 Nginx
  2. ip 192.168.6.*(多台) Mysql

 

步骤一


翻开Nginx是或不是安装stream模块

美高梅手机版4858 2

没安装则实行安装 操作步骤如下

pkill nginx

美高梅手机版4858 3

美高梅手机版4858 4

美高梅手机版4858 5

至此 已成功添加stream模块

环境如下:

步骤一


翻开Nginx是或不是安装stream模块

美高梅手机版4858 6

没安装则展开安装 操作步骤如下

pkill nginx

美高梅手机版4858 7

美高梅手机版4858 8

美高梅手机版4858 9

至此 已成功添加stream模块

worker_processes  16;

步骤二


铺排 mysql负载均衡案例

修改Nginx配置文件nginx.conf 内容如下图

美高梅手机版4858 10

测试步骤如下


  1. 后端Mysql需做好读写分离
  2. 创设好相应权限的用户
  3. 到客户端连接Nginx创立wuguiyunwei库举办测试

在客户端连接 创立测试库

美高梅手机版4858 11

美高梅手机版4858 12

连续3307读库查看 成功如下

美高梅手机版4858 13

美高梅手机版4858 14

步骤一

查看Nginx是不是安装stream模块

美高梅手机版4858 15

没安装则展开安装 操作步骤如下

美高梅手机版4858 16

美高梅手机版4858 17

美高梅手机版4858 18

至此 已保障在没中断服务的境况下成功添加stream模块

步骤二


布局 mysql负载均衡案例

修改Nginx配置文件nginx.conf 内容如下图

美高梅手机版4858 19

测试步骤如下


  1. 后端Mysql需做好读写分离
  2. 成立好相应权限的用户
  3. 到客户端连接Nginx创制wuguiyunwei库实行测试

在客户端连接 成立测试库

美高梅手机版4858 20

美高梅手机版4858 21

连日来3307读库查看 成功如下

美高梅手机版4858 22

美高梅手机版4858 23

 

理所当然为了高可用以下才是我们想要的效率

美高梅手机版4858 24

步骤二

配置 mysql负载均衡案例

修改Nginx配置文件nginx.conf 内容如下图

美高梅手机版4858 25

测试步骤如下

在客户端连接 创造测试库

美高梅手机版4858 26

美高梅手机版4858 27

接连3307读库查看 成功如下

美高梅手机版4858 28

美高梅手机版4858 29

当然为了高可用以下才是大家想要的意义

美高梅手机版4858 30

worker_cpu_affinity 0000000000000001 0000000000000010 0000000000000100
0000000000001000 0000000000010000 0000000000100000 0000000001000000
0000000010000000 0000000100000000 0000001000000000 0000010000000000
0000100000000000 0001000000000000 0010000000000000 0100000000000000
1000000000000000; 

以上配置只是为了让大家精通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;
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 on;
gzip_buffers 16 8k;
gzip_comp_level 6;
gzip_http_version 1.1;
gzip_min_length 256;
gzip_proxied any;
gzip_vary on;
gzip_nginx四层负载均衡配置,Nginx服务器配置。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

理所当然为了高可用以下才是大家想要的效益

美高梅手机版4858 31

以上配置只是为着让我们探听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;
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 on;
gzip_buffers 16 8k;
gzip_comp_level 6;
gzip_http_version 1.1;
gzip_min_length 256;
gzip_proxied any;
gzip_vary 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;
}

 

 

 

此文章 来自水龟运转wuguiyunwei.com

  www.2cto.com  

大家的微信公共号

美高梅手机版4858 32

上述配置只是为了让大家了然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;
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 on;
gzip_buffers 16 8k;
gzip_comp_level 6;
gzip_http_version 1.1;
gzip_min_length 256;
gzip_proxied any;
gzip_vary 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;
}

此小说 来自海龟运转 wuguiyunwei.com

咱俩的微信公共号

美高梅手机版4858 33

worker_rlimit_nofile 1024000; 

QQ群:602183872

 

我们的微信公共号

美高梅手机版4858 34

QQ群:602183872

 

 

QQ群:602183872

nginx四层负载均衡配置代理Mysql集群 环境如下: 步骤一
查看Nginx是不是安装stream模块 没安装则展开…

pid        logs/nginx.pid; 

 

events { 

    use epoll; 

    worker_connections  1024000; 

 

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 8m;

    sendfile on;  www.2cto.com  

    tcp_nopush     on;

    keepalive_timeout 60;

    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;

    open_file_cache max=1024000 inactive=60s;

    open_file_cache_min_uses 1;

    open_file_cache_valid 30s;

 

 ##cache##

  proxy_connect_timeout 5;

  proxy_read_timeout 60;

  proxy_send_timeout 5;

  proxy_buffer_size 16k;

  proxy_buffers 4 64k;

  proxy_busy_buffers_size 128k;

  proxy_temp_file_write_size 128k;

  proxy_temp_path tmp/temp_dir;

  proxy_cache_path tmp/cache levels=1:2 keys_zone=cache_one:200m
inactive=1d max_size=30g;

  ##end## 

 #gzip  on;

    gzip on;

    gzip_min_length 1k;

    gzip_buffers     4 16k;

    gzip_http_version 1.0;

    gzip_comp_level 2;

    gzip_types       text/plain application/x-javascript text/css
application/xml;

    gzip_vary on;  www.2cto.com  

 

upstream in_pool

    {

    #ip_hash;

    server 192.168.0.3:8080;

    server 192.168.0.6:8080 backup;

    server 192.168.0.9:8080 backup;

    }

 

 server {

        listen       80;

        server_name 192.168.60.30;

 

        #charset koi8-r;

        location ~ .*\美高梅手机版4858,.(gif|jpg|png|htm|html|css|js|flv|ico|swf)(.*)
{

              proxy_pass ;

              proxy_redirect off;

              proxy_set_header Host $host;

              proxy_cache cache_one;

              proxy_cache_valid 200 302 1h;

              proxy_cache_valid 301 1d;

              proxy_cache_valid any 1m;

              expires 30d;

        }  www.2cto.com  

        location ~ .*\.(php)(.*){

             proxy_pass ;

             proxy_set_header        Host $host;

             proxy_set_header        X-Real-IP $remote_addr;

             proxy_set_header        X-Forwarded-For
$proxy_add_x_forwarded_for;

        }

        location ~ .*\.(jsp)(.*){

             proxy_pass ;

             proxy_set_header        Host $host;

             proxy_set_header        X-Real-IP $remote_addr;

             proxy_set_header        X-Forwarded-For
$proxy_add_x_forwarded_for;

        }

 

 

作者 xiaoxin

worker_processes 16;
worker_cpu_affinity 0000000000000001 0000000000000010 0000000000000100
0000000000001000 0000000000010000 0000000000100000 0000…

发表评论

电子邮件地址不会被公开。 必填项已用*标注

网站地图xml地图
Copyright @ 2010-2019 美高梅手机版4858 版权所有