【美高梅手机版4858】nginx四层负载均衡,Nginx服务器配置

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

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

nginx四层负载均衡配置,nginx肆层负载均衡

美高梅手机版4858 1

Nginx服务器配置重要参数

意况如下:

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

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

 

【美高梅手机版4858】nginx四层负载均衡,Nginx服务器配置。步骤一


翻开Nginx是不是安装stream模块

美高梅手机版4858 2

没设置则开始展览安装 操作步骤如下

pkill nginx

美高梅手机版4858 3

美高梅手机版4858 4

美高梅手机版4858 5

至此 已成功增添stream模块

景况如下:

worker_processes  16;

步骤二


安插 mysql负载均衡案例

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

美高梅手机版4858 6

测试步骤如下


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

在客户端连接 创立测试库

美高梅手机版4858 7

美高梅手机版4858 8

连接3307读库查看 成功如下

美高梅手机版4858 9

美高梅手机版4858 10

步骤一

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

美高梅手机版4858 11

没设置则开始展览安装 操作步骤如下

美高梅手机版4858 12

美高梅手机版4858 13

美高梅手机版4858 14

至此 已确认保障在没中断服务的事态下成功增加stream模块

 

本来为了高可用以下才是咱们想要的功力

美高梅手机版4858 15

步骤二

配置 mysql负载均衡案例

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

美高梅手机版4858 16

测试步骤如下

在客户端连接 制造测试库

美高梅手机版4858 17

美高梅手机版4858 18

连天3307读库查看 成功如下

美高梅手机版4858 19

美高梅手机版4858 20

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_美高梅手机版4858 ,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 21

  www.2cto.com  

作者们的微信公共号

美高梅手机版4858 22

如上配置只是为了让大家明白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

worker_rlimit_nofile 1024000; 

QQ群:602183872

 

咱俩的微信公共号

美高梅手机版4858 23

 

QQ群:602183872

nginx四层负载均衡布局代理Mysql集群 碰着如下: 步骤1查看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 ~ .*\.(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 版权所有