nginxの4つの負荷分散

nginxの4ロードバランシングの概要

4つのロードバランシングとは何ですか

(TCP / IPなど)、及び我々の過去7の使用が彼の4上の層、四層かどうかに基づいて組み立てられた、アプリケーション層を指すことを負荷分散は、4つのトランスポート層プロトコルパケットがカプセル化されているに基づいています7は、OSIネットワークモデルを参照してください。


四、ロードバランシングのシナリオ

1、4 + 7は、4つの7の高可用性、負荷分散を確保することができ、負荷分散を行う;など:nginxのは、彼らのサービスの可用性を保証することができませんでした、LVSまたはキープアライブに依存する必要があります。

例えば、2:負荷がTCP契約のバランスをとるには、いくつかの要求は、TCPプロトコル(mysqlのは、ssh)であるか、あるいはこれらの要求をのみ転送され、その上に4つのポートを使用する必要があるので、4つの負荷分散を使用していること。


クラスタアーキテクチャのシーンの+ 4階建ての建物7大規模な使用

IMG


四つの負荷分散の概要

1は、4つのロードバランサのような、一般に使用されるTCP / IPプロトコル、UDPプロトコル、ポートフォワーディングを転送することができる:TCP / 22は、UDP / 53であり、
図2は、負荷分散をバランシング4つの荷重は、7ポート制限を解決するために使用することができます(7つの最大負荷分散ポート番号65535を使用して)
3は、4つの負荷分散が7をバランス高可用性負荷の問題を解決することができ、(複数のバックエンド負荷分散七人の同僚を使用することができる)
4、4層の転送効率7よりもはるかに高いが、TCP / IPプロトコルのみをサポートしてHTTPとHTTPSプロトコルをサポートしていません;
5、通常、大規模な同時実行シナリオは、多くの場合、フロント7の4つのロード・バランシング負荷の使用を増加することを選択しました。


nginxの負荷4つのシナリオ練習のバランスをとります

nginxの4つの負荷分散を構成する方法

1は、5555アクセスポートの負荷分散により、ポート22は、実際にサービスの提供におけるWEB01のバックエンドです。

アクセスポートの負荷分散による2、6666、mysqlのポート3306は、実際にサービスの後端部です。

二ポンドのconfigureのロードバランシング

[root@lb02 ~]# cat /etc/yum.repos.d/nginx.repo 
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=0
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key

#在lb02上安装nginx
[root@lb02 yum.repos.d]# yum install -y nginx

#在lb02上同步lb01的所有nginx相关配置
[root@lb02 ~]# scp -r [email protected]:/etc/nginx /etc/


#启动nginx
[root@lb02 conf.d]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@lb02 conf.d]# systemctl enable nginx
Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.
[root@lb02 conf.d]# nginx

1. 4ロードバランシングコンフィギュレーションファイルを格納するディレクトリを作成します。

[root@lb03 ~]# vim /etc/nginx/nginx.conf
events {
        ....
}
include /etc/nginx/conf.c/*.conf;
http {
        .....
}

[root@lb03 ~]# mkdir /etc/nginx/conf.c

4のロードバランシングの設定

[root@lb03 conf.c]# cat lb_domain.conf 
stream {
    upstream lb {
            server 172.16.1.5:80 weight=5 max_fails=3 fail_timeout=30s;
            server 172.16.1.6:80 weight=5 max_fails=3 fail_timeout=30s;
    }

    server {
            listen 80;
            proxy_connect_timeout 3s;
            proxy_timeout 3s;
            proxy_pass lb;
    }
}
[root@lb03 conf.c]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@lb03 conf.c]# nginx -s reload

#配置本机hosts解析后浏览器访问并查看nginx日志

4つのオープンログのバランスをとる3.ロード

#四层负载均衡是没有access的日志的,因为在nginx.conf的配置中,access的日志格式是配置在http下的,而四层复杂均衡配置实在http以外的;

#如果需要日志则需要配置在stream下面
[root@web03 conf.c]# cat lb_domain.conf 
stream {
    log_format  proxy '$remote_addr $remote_port - [$time_local] $status $protocol '
                  '"$upstream_addr" "$upstream_bytes_sent" "$upstream_connect_time"' ;
    access_log /var/log/nginx/proxy.log proxy;
    upstream lb {
            server 172.16.1.5:80 weight=5 max_fails=3 fail_timeout=30s;
            server 172.16.1.6:80 weight=5 max_fails=3 fail_timeout=30s;
    }

    server {
            listen 80;
            proxy_connect_timeout 3s;
            proxy_timeout 3s;
            proxy_pass lb;
    }
}

lb03のDNSは、再度ログインします

ログの表示:

[root@lb03 ~]# tail -f /var/log/nginx/proxy.log

541055 - lb03 - TCP - 10.0.0.1 - 1656 - 80 - 75.856 - 200 - 28/Aug/2019:03:22:50 +0800
344557 - lb03 - TCP - 10.0.0.1 - 1658 - 80 - 75.850 - 200 - 28/Aug/2019:03:22:50 +0800
284545 - lb03 - TCP - 10.0.0.1 - 1654 - 80 - 75.957 - 200 - 28/Aug/2019:03:22:50 +0800
225560 - lb03 - TCP - 10.0.0.1 - 1659 - 80 - 75.858 - 200 - 28/Aug/2019:03:22:50 +0800

nginxのロードバランシングは、4転送し、TCPを使用して達成しました

请求负载均衡 5555    --->     172.16.1.7:22;
请求负载均衡 6666    --->     172.16.1.51:3306;

転送TCPの4を達成するためにバランスをとるの設定nginxの負荷

[root@lb4-01 ~]# cat /etc/nginx/conf.c/lb_domain.conf 
stream {
    log_format  proxy '$remote_addr $remote_port - [$time_local] $status $protocol '
                      '"$upstream_addr" "$upstream_bytes_sent" "$upstream_connect_time"' ;
    access_log /var/log/nginx/proxy.log proxy;

#定义转发ssh的22端口
    upstream ssh_7 {
            server 10.0.0.7:22;
    }
#定义转发mysql的3306端口
    upstream mysql_51 {
            server 10.0.0.51:3306;
    }
    server {
            listen 5555;
            proxy_connect_timeout 3s;
            proxy_timeout 300s;
            proxy_pass ssh_7;
    }

    server {
            listen 6666;
            proxy_connect_timeout 3s;
            proxy_timeout 3s;
            proxy_pass mysql_51;
    }
}

ローカル接続を使用します

ssh [email protected] 5555
会自动跳转到端口所指定的服务器上

パスワードを入力します。

自動的にWEB01にジャンプし、指定されたサーバーのポート5555に接続します

おすすめ

転載: www.cnblogs.com/gongjingyun123--/p/11424424.html