澳门新萄京官方网站-www.8455.com-澳门新萄京赌场网址

澳门新萄京官方网站:nginx四层负载均衡配置,

2019-10-05 作者:澳门新萄京官方网站   |   浏览(123)

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

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

澳门新萄京官方网站 1

Nginx服务器配置主要参数

Nginx四个host配置文件:

条件如下:

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

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

 

  1. user  daemon daemon;  
  2.   
  3. worker_processes 4;  
  4.   
  5. error_log  /opt/modules/nginx/logs/nginx_error.log  crit;  
  6.   
  7. pid        /opt/modules/nginx/logs/nginx.pid;  
  8.   
  9. #Specifies the value for maximum file descriptors that can be opened by this process.  
  10. worker_rlimit_nofile 51200;  
  11.   
  12. events  
  13.     {  
  14.         use epoll;  
  15.         worker_connections 1500;  
  16.     }  
  17.   
  18. http  
  19.     {  
  20.         include       mime.types;  
  21.         default_type  application/octet-stream;  
  22.   
  23.         server_names_hash_bucket_size 128;  
  24.         client_header_buffer_size 32k;  
  25.         large_client_header_buffers 4 32k;  
  26.         client_max_body_size 8m;  
  27.   
  28.         sendfile on;  
  29.         tcp_nopush     on;  
  30.   
  31.         keepalive_timeout 120;  
  32.   
  33.         tcp_nodelay on;       
  34.   
  35.         #fix_502_error  
  36.                 proxy_buffer_size  64k;  
  37.                 proxy_buffers 4 64k;  
  38.         fastcgi_connect_timeout 300;  
  39.         fastcgi_send_timeout 300;  
  40.         fastcgi_read_timeout 300;  
  41.         fastcgi_buffer_size 64k;  
  42.         fastcgi_buffers 4 64k;  
  43.         fastcgi_busy_buffers_size 128k;  
  44.         fastcgi_temp_file_write_size 256k;  
  45.   
  46.         gzip on;  
  47.         gzip_min_length  1k;  
  48.         gzip_buffers     4 16k;  
  49.         gzip_http_version 1.0;  
  50.         gzip_comp_level 2;  
  51.         gzip_types       text/plain application/x-javascript text/css application/xml;  
  52.         gzip_vary on;  
  53.   
  54.         limit_zone  crawler  $binary_remote_addr  10m;  
  55.   
  56. server  
  57.         {  
  58.                 listen       80;  
  59.                 server_name gaoqingyue.mk.com newcms.mk;  
  60.                 index index.html index.htm;  
  61.                 root  /opt/c/public;  
  62.           
  63.         location /  
  64.                 {  
  65.                         if (!-f $request_filename ){  
  66.                                 rewrite ^/(.*) /index.php?$1;  
  67.                         }  
  68.                 }  
  69.   
  70.                 location ~ .*.(php|php5)?$  
  71.                         {  
  72.                                 fastcgi_pass  127.0.0.1:9100;  
  73.                                 fastcgi_index index.php;  
  74. 澳门新萄京官方网站:nginx四层负载均衡配置,Nginx多个host配置文件。                                include fcgi.conf;  
  75.                         }  
  76.   
  77.                 location ~ .*.(gif|jpg|jpeg|png|bmp|swf)$  
  78.                         {  
  79.                                 expires      30d;  
  80.                         }  
  81.   
  82.                 location ~ .*.(js|css)?$  
  83.                         {  
  84.                                 expires      1h;  
  85.                         }  
  86.   
  87.                 log_format access_gaoqingyue '$remote_addr - $remote_user [$time_local] "$request" '  
  88.                                    '$status $body_bytes_sent "$http_referer" '  
  89.                                     '"$http_user_agent" $http_x_forwarded_for';  
  90.                 access_log  /opt/data/logs/nginx/access_gaoqingyue.log  access_gaoqingyue;  
  91.   
  92.         }  
  93.   
  94. server  
  95.         {  
  96.                 listen       80;  
  97.                 server_name neiyijie.mk.xxxxxx.com;  
  98.                 index index.html index.htm index.php;  
  99.                 root  /opt/hd/neiyijie;  
  100.   
  101.                 location ~ .*.(php|php5)?$  
  102.                         {  
  103.                                 proxy_pass ;  
  104.                                 fastcgi_index index.php;  
  105.                                 #include fcgi.conf;  
  106.                 #limit_conn  crawler 5;  
  107.                                 #proxy_set_header Host $host;  
  108.                                 #proxy_set_header X-Real-IP $remote_addr;  
  109.                                  proxy_set_header Host $host;  
  110.                                  proxy_set_header X-Real-IP $remote_addr;  
  111.                                  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;  
  112.                         }  
  113.   
  114.                 location /status {  
  115.                         stub_status on;  
  116.                         access_log   off;  
  117.                 }  
  118.   
  119.         location ~ .*.(php)$  
  120.                         {  
  121.                                 expires      300s;  
  122.                         }  
  123.   
  124.                 location ~ .*.(gif|jpg|jpeg|png|bmp|swf)$  
  125.                         {  
  126.                                 expires      30d;  
  127.                         }  
  128.   
  129.                 location ~ .*.(js|css)?$  
  130.                         {  
  131.                                 expires      12h;  
  132.                         }  
  133.         }   
  134.   
  135. include vhost/*.conf;  
  136. }  

步骤一


查看Nginx是还是不是安装stream模块

澳门新萄京官方网站 2

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

pkill nginx

澳门新萄京官方网站 3

澳门新萄京官方网站 4

澳门新萄京官方网站 5

至此 已成功增添stream模块

条件如下:

worker_processes  16;

澳门新萄京官方网站 6

步骤二


布置 mysql负载均衡案例

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

澳门新萄京官方网站 7

测验步骤如下


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

在客商端连接 创立测量试验库

澳门新萄京官方网站 8

澳门新萄京官方网站 9

老是3307读库查看 成功如下

澳门新萄京官方网站 10

澳门新萄京官方网站 11

步骤一

翻看Nginx是还是不是安装stream模块

澳门新萄京官方网站 12

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

澳门新萄京官方网站 13

澳门新萄京官方网站 14

澳门新萄京官方网站 15

至此 已确定保证在没中断服务的事态下成功增添stream模块

 

自然为了高可用以下才是大家想要的效应

澳门新萄京官方网站 16

步骤二

配备 mysql负载均衡案例

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

澳门新萄京官方网站 17

测量试验步骤如下

在顾客端连接 创制测验库

澳门新萄京官方网站 18

澳门新萄京官方网站 19

连年3307读库查看 成功如下

澳门新萄京官方网站 20

澳门新萄京官方网站 21

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_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

自然为了高可用以下才是大家想要的功力

澳门新萄京官方网站 22

  www.2cto.com  

小编们的微信公共号

澳门新萄京官方网站 23

上述配置只是为着让我们探听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

 

大家的微信公共号

澳门新萄京官方网站 24

 

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 ~ .*.(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...

本文由澳门新萄京官方网站发布于澳门新萄京官方网站,转载请注明出处:澳门新萄京官方网站:nginx四层负载均衡配置,

关键词: