• HAProxy基础配置-基于http的反向代理


             HAProxy基础配置-基于七层(http)的反向代理案例实战

                                       作者:尹正杰

    版权声明:原创作品,谢绝转载!否则将追究法律责任。

    一.安装apache httpd服务器

    1>.试验架构说明

    node102.yinzhengjie.org.cn:
      Haproxy服务器
    
    node105.yinzhengjie.org.cn:
      测试服务器,模拟客户端
    node106.yinzhengjie.org.cn:   Apache httpd服务器

    node107.yinzhengjie.org.cn:
      Apache httpd服务器

    2>.虚拟机配置

    [root@node106.yinzhengjie.org.cn ~]# uname -r
    3.10.0-957.el7.x86_64
    [root@node106.yinzhengjie.org.cn ~]# 
    [root@node106.yinzhengjie.org.cn ~]# uname -m
    x86_64
    [root@node106.yinzhengjie.org.cn ~]# 
    [root@node106.yinzhengjie.org.cn ~]# cat /etc/redhat-release 
    CentOS Linux release 7.6.1810 (Core) 
    [root@node106.yinzhengjie.org.cn ~]# 
    [root@node106.yinzhengjie.org.cn ~]# free -h
                  total        used        free      shared  buff/cache   available
    Mem:           1.8G         81M        1.6G        8.5M        122M        1.6G
    Swap:          2.0G          0B        2.0G
    [root@node106.yinzhengjie.org.cn ~]# 
    [root@node106.yinzhengjie.org.cn ~]# cat /etc/hosts
    127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
    ::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
    
    172.30.1.101 node101.yinzhengjie.org.cn node101.yinzhengjie.com
    172.30.1.102 node102.yinzhengjie.org.cn
    172.30.1.103 node103.yinzhengjie.org.cn
    172.30.1.104 node104.yinzhengjie.org.cn
    172.30.1.105 node105.yinzhengjie.org.cn
    172.30.1.106 node106.yinzhengjie.org.cn
    172.30.1.107 node107.yinzhengjie.org.cn
    172.30.1.108 node108.yinzhengjie.org.cn
    [root@node106.yinzhengjie.org.cn ~]# 
    [root@node106.yinzhengjie.org.cn ~]# 

    3>.安装httpd服务

    [root@node106.yinzhengjie.org.cn ~]# yum -y install httpd
    Loaded plugins: fastestmirror
    Determining fastest mirrors
     * base: mirror.bit.edu.cn
     * extras: mirror.bit.edu.cn
     * updates: mirror.bit.edu.cn
    base                                                                                | 3.6 kB  00:00:00     
    extras                                                                              | 2.9 kB  00:00:00     
    updates                                                                             | 2.9 kB  00:00:00     
    (1/4): base/7/x86_64/group_gz                                                       | 165 kB  00:00:00     
    (2/4): extras/7/x86_64/primary_db                                                   | 153 kB  00:00:00     
    (3/4): base/7/x86_64/primary_db                                                     | 6.0 MB  00:00:01     
    (4/4): updates/7/x86_64/primary_db                                                  | 5.9 MB  00:00:02     
    Resolving Dependencies
    --> Running transaction check
    ---> Package httpd.x86_64 0:2.4.6-90.el7.centos will be installed
    --> Processing Dependency: httpd-tools = 2.4.6-90.el7.centos for package: httpd-2.4.6-90.el7.centos.x86_64
    --> Processing Dependency: libaprutil-1.so.0()(64bit) for package: httpd-2.4.6-90.el7.centos.x86_64
    --> Processing Dependency: libapr-1.so.0()(64bit) for package: httpd-2.4.6-90.el7.centos.x86_64
    --> Running transaction check
    ---> Package apr.x86_64 0:1.4.8-5.el7 will be installed
    ---> Package apr-util.x86_64 0:1.5.2-6.el7 will be installed
    ---> Package httpd-tools.x86_64 0:2.4.6-90.el7.centos will be installed
    --> Finished Dependency Resolution
    
    Dependencies Resolved
    
    ===========================================================================================================
     Package                   Arch                 Version                           Repository          Size
    ===========================================================================================================
    Installing:
     httpd                     x86_64               2.4.6-90.el7.centos               base               2.7 M
    Installing for dependencies:
     apr                       x86_64               1.4.8-5.el7                       base               103 k
     apr-util                  x86_64               1.5.2-6.el7                       base                92 k
     httpd-tools               x86_64               2.4.6-90.el7.centos               base                91 k
    
    Transaction Summary
    ===========================================================================================================
    Install  1 Package (+3 Dependent packages)
    
    Total download size: 3.0 M
    Installed size: 9.9 M
    Downloading packages:
    (1/4): apr-1.4.8-5.el7.x86_64.rpm                                                   | 103 kB  00:00:00     
    (2/4): apr-util-1.5.2-6.el7.x86_64.rpm                                              |  92 kB  00:00:00     
    (3/4): httpd-tools-2.4.6-90.el7.centos.x86_64.rpm                                   |  91 kB  00:00:00     
    (4/4): httpd-2.4.6-90.el7.centos.x86_64.rpm                                         | 2.7 MB  00:00:00     
    -----------------------------------------------------------------------------------------------------------
    Total                                                                      3.7 MB/s | 3.0 MB  00:00:00     
    Running transaction check
    Running transaction test
    Transaction test succeeded
    Running transaction
      Installing : apr-1.4.8-5.el7.x86_64                                                                  1/4 
      Installing : apr-util-1.5.2-6.el7.x86_64                                                                                         2/4 
      Installing : httpd-tools-2.4.6-90.el7.centos.x86_64                                                                              3/4 
      Installing : httpd-2.4.6-90.el7.centos.x86_64                                                                                    4/4 
      Verifying  : apr-1.4.8-5.el7.x86_64                                                                                              1/4 
      Verifying  : httpd-tools-2.4.6-90.el7.centos.x86_64                                                                              2/4 
      Verifying  : apr-util-1.5.2-6.el7.x86_64                                                                                         3/4 
      Verifying  : httpd-2.4.6-90.el7.centos.x86_64                                                                                    4/4 
    
    Installed:
      httpd.x86_64 0:2.4.6-90.el7.centos                                                                                                   
    
    Dependency Installed:
      apr.x86_64 0:1.4.8-5.el7             apr-util.x86_64 0:1.5.2-6.el7             httpd-tools.x86_64 0:2.4.6-90.el7.centos            
    
    Complete!
    [root@node106.yinzhengjie.org.cn ~]# 
    [root@node106.yinzhengjie.org.cn ~]# yum -y install httpd
    [root@node107.yizhengjie.org.cn ~]# yum -y install httpd
    Loaded plugins: fastestmirror
    Determining fastest mirrors
     * base: mirrors.aliyun.com
     * extras: mirrors.tuna.tsinghua.edu.cn
     * updates: mirrors.aliyun.com
    base                                                                                                                                                 | 3.6 kB  00:00:00     
    extras                                                                                                                                               | 2.9 kB  00:00:00     
    updates                                                                                                                                              | 2.9 kB  00:00:00     
    (1/4): base/7/x86_64/group_gz                                                                                                                        | 165 kB  00:00:00     
    (2/4): extras/7/x86_64/primary_db                                                                                                                    | 153 kB  00:00:00     
    (3/4): updates/7/x86_64/primary_db                                                                                                                   | 5.9 MB  00:00:01     
    base/7/x86_64/primary_db       FAILED                                          ==================================                         ]  224 B/s | 7.3 MB  06:26:13 ETA 
    http://mirrors.nju.edu.cn/centos/7.7.1908/os/x86_64/repodata/04efe80d41ea3d94d36294f7107709d1c8f70db11e152d6ef562da344748581a-primary.sqlite.bz2: [Errno 12] Timeout on http
    ://mirrors.nju.edu.cn/centos/7.7.1908/os/x86_64/repodata/04efe80d41ea3d94d36294f7107709d1c8f70db11e152d6ef562da344748581a-primary.sqlite.bz2: (28, 'Operation too slow. Less than 1000 bytes/sec transferred the last 30 seconds')Trying other mirror.
    (4/4): base/7/x86_64/primary_db                                                                                                                      | 6.0 MB  00:00:00     
    Resolving Dependencies
    --> Running transaction check
    ---> Package httpd.x86_64 0:2.4.6-90.el7.centos will be installed
    --> Processing Dependency: httpd-tools = 2.4.6-90.el7.centos for package: httpd-2.4.6-90.el7.centos.x86_64
    --> Processing Dependency: libaprutil-1.so.0()(64bit) for package: httpd-2.4.6-90.el7.centos.x86_64
    --> Processing Dependency: libapr-1.so.0()(64bit) for package: httpd-2.4.6-90.el7.centos.x86_64
    --> Running transaction check
    ---> Package apr.x86_64 0:1.4.8-5.el7 will be installed
    ---> Package apr-util.x86_64 0:1.5.2-6.el7 will be installed
    ---> Package httpd-tools.x86_64 0:2.4.6-90.el7.centos will be installed
    --> Finished Dependency Resolution
    
    Dependencies Resolved
    
    ============================================================================================================================================================================
     Package                                   Arch                                 Version                                            Repository                          Size
    ============================================================================================================================================================================
    Installing:
     httpd                                     x86_64                               2.4.6-90.el7.centos                                base                               2.7 M
    Installing for dependencies:
     apr                                       x86_64                               1.4.8-5.el7                                        base                               103 k
     apr-util                                  x86_64                               1.5.2-6.el7                                        base                                92 k
     httpd-tools                               x86_64                               2.4.6-90.el7.centos                                base                                91 k
    
    Transaction Summary
    ============================================================================================================================================================================
    Install  1 Package (+3 Dependent packages)
    
    Total download size: 3.0 M
    Installed size: 9.9 M
    Downloading packages:
    (1/4): apr-1.4.8-5.el7.x86_64.rpm                                                                                                                    | 103 kB  00:00:00     
    (2/4): apr-util-1.5.2-6.el7.x86_64.rpm                                                                                                               |  92 kB  00:00:00     
    (3/4): httpd-tools-2.4.6-90.el7.centos.x86_64.rpm                                                                                                    |  91 kB  00:00:00     
    (4/4): httpd-2.4.6-90.el7.centos.x86_64.rpm                                                                                                          | 2.7 MB  00:00:01     
    ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    Total                                                                                                                                       1.8 MB/s | 3.0 MB  00:00:01     
    Running transaction check
    Running transaction test
    Transaction test succeeded
    Running transaction
      Installing : apr-1.4.8-5.el7.x86_64                                                                                                                                   1/4 
      Installing : apr-util-1.5.2-6.el7.x86_64                                                                                                                              2/4 
      Installing : httpd-tools-2.4.6-90.el7.centos.x86_64                                                                                                                   3/4 
      Installing : httpd-2.4.6-90.el7.centos.x86_64                                                                                                                         4/4 
      Verifying  : apr-1.4.8-5.el7.x86_64                                                                                                                                   1/4 
      Verifying  : httpd-tools-2.4.6-90.el7.centos.x86_64                                                                                                                   2/4 
      Verifying  : apr-util-1.5.2-6.el7.x86_64                                                                                                                              3/4 
      Verifying  : httpd-2.4.6-90.el7.centos.x86_64                                                                                                                         4/4 
    
    Installed:
      httpd.x86_64 0:2.4.6-90.el7.centos                                                                                                                                        
    
    Dependency Installed:
      apr.x86_64 0:1.4.8-5.el7                          apr-util.x86_64 0:1.5.2-6.el7                          httpd-tools.x86_64 0:2.4.6-90.el7.centos                         
    
    Complete!
    [root@node107.yizhengjie.org.cn ~]# 
    [root@node107.yizhengjie.org.cn ~]# yum -y install httpd

    4>.准备测试数据

    [root@node106.yinzhengjie.org.cn ~]# ll /var/www/html/
    total 0
    [root@node106.yinzhengjie.org.cn ~]# 
    [root@node106.yinzhengjie.org.cn ~]# echo "<h1>node106.yinzhengjie.org.cn</h1>" > /var/www/html/index.html
    [root@node106.yinzhengjie.org.cn ~]# 
    [root@node106.yinzhengjie.org.cn ~]# mkdir /var/www/html/{app01,app02}
    [root@node106.yinzhengjie.org.cn ~]# 
    [root@node106.yinzhengjie.org.cn ~]# echo "172.30.1.106 app01" > /var/www/html/app01/index.html
    [root@node106.yinzhengjie.org.cn ~]# 
    [root@node106.yinzhengjie.org.cn ~]# echo "172.30.1.106 app02" > /var/www/html/app02/index.html
    [root@node106.yinzhengjie.org.cn ~]# 
    [root@node106.yinzhengjie.org.cn ~]# ll /var/www/html/ -R
    /var/www/html/:
    total 4
    drwxr-xr-x 2 root root 24 Jan  1 18:04 app01
    drwxr-xr-x 2 root root 24 Jan  1 18:05 app02
    -rw-r--r-- 1 root root 36 Jan  1 18:03 index.html
    
    /var/www/html/app01:
    total 4
    -rw-r--r-- 1 root root 19 Jan  1 18:04 index.html
    
    /var/www/html/app02:
    total 4
    -rw-r--r-- 1 root root 19 Jan  1 18:05 index.html
    [root@node106.yinzhengjie.org.cn ~]# 
    [root@node107.yizhengjie.org.cn ~]# ll /var/www/html/
    total 0
    [root@node107.yizhengjie.org.cn ~]# 
    [root@node107.yizhengjie.org.cn ~]# echo "<h2>node107.yinzhengjie.org.cn</h1>" > /var/www/html/index.html
    [root@node107.yizhengjie.org.cn ~]# 
    [root@node107.yizhengjie.org.cn ~]# mkdir /var/www/html/{app01,app02}
    [root@node107.yizhengjie.org.cn ~]# 
    [root@node107.yizhengjie.org.cn ~]# echo "172.30.1.107 app01" > /var/www/html/app01/index.html
    [root@node107.yizhengjie.org.cn ~]# 
    [root@node107.yizhengjie.org.cn ~]# echo "172.30.1.107 app02" > /var/www/html/app02/index.html
    [root@node107.yizhengjie.org.cn ~]# 
    [root@node107.yizhengjie.org.cn ~]# ll /var/www/html/ -R
    /var/www/html/:
    total 4
    drwxr-xr-x 2 root root 24 Jan  2 06:57 app01
    drwxr-xr-x 2 root root 24 Jan  2 06:59 app02
    -rw-r--r-- 1 root root 36 Jan  2 06:56 index.html
    
    /var/www/html/app01:
    total 4
    -rw-r--r-- 1 root root 19 Jan  2 06:57 index.html
    
    /var/www/html/app02:
    total 4
    -rw-r--r-- 1 root root 19 Jan  2 06:59 index.html
    [root@node107.yizhengjie.org.cn ~]# 
    [root@node107.yizhengjie.org.cn ~]# ll /var/www/html/ -R

    5>.启动httpd服务

    [root@node106.yinzhengjie.org.cn ~]# ss -ntl
    State       Recv-Q Send-Q                      Local Address:Port                                     Peer Address:Port              
    LISTEN      0      128                                     *:22                                                  *:*                  
    LISTEN      0      128                                    :::22                                                 :::*                  
    [root@node106.yinzhengjie.org.cn ~]# 
    [root@node106.yinzhengjie.org.cn ~]# systemctl start httpd
    [root@node106.yinzhengjie.org.cn ~]# 
    [root@node106.yinzhengjie.org.cn ~]# ss -ntl
    State       Recv-Q Send-Q                      Local Address:Port                                     Peer Address:Port              
    LISTEN      0      128                                     *:80                                                  *:*                  
    LISTEN      0      128                                     *:22                                                  *:*                  
    LISTEN      0      128                                    :::22                                                 :::*                  
    [root@node106.yinzhengjie.org.cn ~]# 
    [root@node107.yizhengjie.org.cn ~]# ss -ntl
    State      Recv-Q Send-Q                       Local Address:Port                                      Peer Address:Port              
    LISTEN     0      128                                      *:22                                                   *:*                  
    LISTEN     0      128                                     :::22                                                  :::*                  
    [root@node107.yizhengjie.org.cn ~]# 
    [root@node107.yizhengjie.org.cn ~]# systemctl start httpd
    [root@node107.yizhengjie.org.cn ~]# 
    [root@node107.yizhengjie.org.cn ~]# ss -ntl
    State      Recv-Q Send-Q                       Local Address:Port                                      Peer Address:Port              
    LISTEN     0      128                                      *:80                                                   *:*                  
    LISTEN     0      128                                      *:22                                                   *:*                  
    LISTEN     0      128                                     :::22                                                  :::*                  
    [root@node107.yizhengjie.org.cn ~]# 
    [root@node107.yizhengjie.org.cn ~]# 
    [root@node107.yizhengjie.org.cn ~]# systemctl start httpd

    6>.模拟客户端访问node106.yinzhengjie.org.cn的服务

    [root@node106.yinzhengjie.org.cn ~]# curl http://node106.yinzhengjie.org.cn
    <h1>node106.yinzhengjie.org.cn</h1>
    [root@node106.yinzhengjie.org.cn ~]# 
    [root@node106.yinzhengjie.org.cn ~]# curl http://node106.yinzhengjie.org.cn/app01/index.html
    172.30.1.106 app01
    [root@node106.yinzhengjie.org.cn ~]# 
    [root@node106.yinzhengjie.org.cn ~]# curl http://node106.yinzhengjie.org.cn/app02/index.html
    172.30.1.106 app02
    [root@node106.yinzhengjie.org.cn ~]# 
    [root@node106.yinzhengjie.org.cn ~]# curl http://node107.yinzhengjie.org.cn
    <h2>node107.yinzhengjie.org.cn</h1>
    [root@node106.yinzhengjie.org.cn ~]# 
    [root@node106.yinzhengjie.org.cn ~]# curl http://node107.yinzhengjie.org.cn/app01/index.html
    172.30.1.107 app01
    [root@node106.yinzhengjie.org.cn ~]# 
    [root@node106.yinzhengjie.org.cn ~]# curl http://node107.yinzhengjie.org.cn/app02/index.html
    172.30.1.107 app02
    [root@node106.yinzhengjie.org.cn ~]# 
    [root@node106.yinzhengjie.org.cn ~]# 

    二.在haproxy节点上配置反向代理

    1>.基于源码方式安装haproxy服务器

    博主推荐阅读:
      https://www.cnblogs.com/yinzhengjie/p/12113144.html

    2>.编辑haproxy服务的配置文件

    [root@node102.yinzhengjie.org.cn ~]# cat /etc/haproxy/haproxy.cfg 
    global
    maxconn 100000
    chroot /yinzhengjie/softwares/haproxy
    #stats socket /var/lib/haproxy/haproxy.sock mode 600 level admin
    user haproxy
    group haproxy
    daemon
    nbproc 4
    cpu-map 1 0
    cpu-map 2 1
    cpu-map 3 2
    cpu-map 4 3
    nbthread 2
    pidfile /yinzhengjie/softwares/haproxy/haproxy.pid
    log 127.0.0.1 local5 info
    
    defaults
    option http-keep-alive
    option  forwardfor
    option redispatch
    option abortonclose
    maxconn 100000
    mode http
    timeout connect 300000ms
    timeout client  300000ms
    timeout server  300000ms
    
    listen stats
     mode http
     bind 0.0.0.0:9999
     stats enable
     log global
     stats uri     /haproxy-status
     stats auth    haadmin:q1w2e3r4ys
    
    #frontend web
    # bind 172.30.1.102:80
    # use_backend myweb
    
    #backend myweb
    # server web01 172.30.1.106:80 weight 10 check inter 3s fall 3 rise 5
    # server web02 172.30.1.107:80 weight  5 check inter 3s fall 3 rise 5
    
    #可以使用listen指令来代替frontend和backend的配置部分
    listen myweb
     bind 172.30.1.102:80
     server web01 172.30.1.106:80 weight 10 check inter 3s fall 3 rise 5
     server web02 172.30.1.107:80 weight  5 check inter 3s fall 3 rise 5
    [root@node102.yinzhengjie.org.cn ~]# 
    [root@node102.yinzhengjie.org.cn ~]# 

    3>.启动haproxy服务

    [root@node102.yinzhengjie.org.cn ~]# netstat -untalp | grep haproxy
    [root@node102.yinzhengjie.org.cn ~]# 
    [root@node102.yinzhengjie.org.cn ~]# systemctl start haproxy
    [root@node102.yinzhengjie.org.cn ~]# 
    [root@node102.yinzhengjie.org.cn ~]# netstat -untalp | grep haproxy
    tcp        0      0 0.0.0.0:9999            0.0.0.0:*               LISTEN      20913/haproxy       
    tcp        0      0 172.30.1.102:80         0.0.0.0:*               LISTEN      20913/haproxy       
    tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      20913/haproxy       
    udp        0      0 0.0.0.0:56745           0.0.0.0:*                           20911/haproxy       
    [root@node102.yinzhengjie.org.cn ~]# 
    [root@node102.yinzhengjie.org.cn ~]# 

     

    三.访问haproxy服务器

    1>.访问"http://node102.yinzhengjie.org.cn"同一个URL10次,由于权重的问题,因此我们会发现node106.yinzhengjie.org.cn节点响应次数较多。

    [root@node105.yinzhengjie.org.cn ~]# curl http://node102.yinzhengjie.org.cn
    <h1>node106.yinzhengjie.org.cn</h1>
    [root@node105.yinzhengjie.org.cn ~]# 
    [root@node105.yinzhengjie.org.cn ~]# curl http://node102.yinzhengjie.org.cn
    <h1>node106.yinzhengjie.org.cn</h1>
    [root@node105.yinzhengjie.org.cn ~]# 
    [root@node105.yinzhengjie.org.cn ~]# curl http://node102.yinzhengjie.org.cn
    <h1>node106.yinzhengjie.org.cn</h1>
    [root@node105.yinzhengjie.org.cn ~]# 
    [root@node105.yinzhengjie.org.cn ~]# curl http://node102.yinzhengjie.org.cn
    <h2>node107.yinzhengjie.org.cn</h1>
    [root@node105.yinzhengjie.org.cn ~]# 
    [root@node105.yinzhengjie.org.cn ~]# curl http://node102.yinzhengjie.org.cn
    <h1>node106.yinzhengjie.org.cn</h1>
    [root@node105.yinzhengjie.org.cn ~]# 
    [root@node105.yinzhengjie.org.cn ~]# curl http://node102.yinzhengjie.org.cn
    <h1>node106.yinzhengjie.org.cn</h1>
    [root@node105.yinzhengjie.org.cn ~]# 
    [root@node105.yinzhengjie.org.cn ~]# curl http://node102.yinzhengjie.org.cn
    <h1>node106.yinzhengjie.org.cn</h1>
    [root@node105.yinzhengjie.org.cn ~]# 
    [root@node105.yinzhengjie.org.cn ~]# curl http://node102.yinzhengjie.org.cn
    <h1>node106.yinzhengjie.org.cn</h1>
    [root@node105.yinzhengjie.org.cn ~]# 
    [root@node105.yinzhengjie.org.cn ~]# curl http://node102.yinzhengjie.org.cn
    <h2>node107.yinzhengjie.org.cn</h1>
    [root@node105.yinzhengjie.org.cn ~]# 
    [root@node105.yinzhengjie.org.cn ~]# curl http://node102.yinzhengjie.org.cn
    <h2>node107.yinzhengjie.org.cn</h1>
    [root@node105.yinzhengjie.org.cn ~]# 

    2>.访问"http://node102.yinzhengjie.org.cn/app01/index.html"同一个URL10次,由于权重的问题,因此我们会发现node106.yinzhengjie.org.cn节点响应次数较多。

    [root@node105.yinzhengjie.org.cn ~]# curl http://node102.yinzhengjie.org.cn/app01/index.html
    172.30.1.106 app01
    [root@node105.yinzhengjie.org.cn ~]# 
    [root@node105.yinzhengjie.org.cn ~]# curl http://node102.yinzhengjie.org.cn/app01/index.html
    172.30.1.106 app01
    [root@node105.yinzhengjie.org.cn ~]# 
    [root@node105.yinzhengjie.org.cn ~]# curl http://node102.yinzhengjie.org.cn/app01/index.html
    172.30.1.106 app01
    [root@node105.yinzhengjie.org.cn ~]# 
    [root@node105.yinzhengjie.org.cn ~]# curl http://node102.yinzhengjie.org.cn/app01/index.html
    172.30.1.107 app01
    [root@node105.yinzhengjie.org.cn ~]# 
    [root@node105.yinzhengjie.org.cn ~]# curl http://node102.yinzhengjie.org.cn/app01/index.html
    172.30.1.106 app01
    [root@node105.yinzhengjie.org.cn ~]# 
    [root@node105.yinzhengjie.org.cn ~]# curl http://node102.yinzhengjie.org.cn/app01/index.html
    172.30.1.106 app01
    [root@node105.yinzhengjie.org.cn ~]# 
    [root@node105.yinzhengjie.org.cn ~]# curl http://node102.yinzhengjie.org.cn/app01/index.html
    172.30.1.106 app01
    [root@node105.yinzhengjie.org.cn ~]# 
    [root@node105.yinzhengjie.org.cn ~]# curl http://node102.yinzhengjie.org.cn/app01/index.html
    172.30.1.107 app01
    [root@node105.yinzhengjie.org.cn ~]# 
    [root@node105.yinzhengjie.org.cn ~]# curl http://node102.yinzhengjie.org.cn/app01/index.html
    172.30.1.106 app01
    [root@node105.yinzhengjie.org.cn ~]# 
    [root@node105.yinzhengjie.org.cn ~]# curl http://node102.yinzhengjie.org.cn/app01/index.html
    172.30.1.106 app01
    [root@node105.yinzhengjie.org.cn ~]# 

    3>.访问"http://node102.yinzhengjie.org.cn/app02/index.html"同一个URL10次,由于权重的问题,因此我们会发现node106.yinzhengjie.org.cn节点响应次数较多。

    [root@node105.yinzhengjie.org.cn ~]# curl http://node102.yinzhengjie.org.cn/app02/index.html
    172.30.1.106 app02
    [root@node105.yinzhengjie.org.cn ~]# 
    [root@node105.yinzhengjie.org.cn ~]# curl http://node102.yinzhengjie.org.cn/app02/index.html
    172.30.1.107 app02
    [root@node105.yinzhengjie.org.cn ~]# 
    [root@node105.yinzhengjie.org.cn ~]# curl http://node102.yinzhengjie.org.cn/app02/index.html
    172.30.1.107 app02
    [root@node105.yinzhengjie.org.cn ~]# 
    [root@node105.yinzhengjie.org.cn ~]# curl http://node102.yinzhengjie.org.cn/app02/index.html
    172.30.1.106 app02
    [root@node105.yinzhengjie.org.cn ~]# 
    [root@node105.yinzhengjie.org.cn ~]# curl http://node102.yinzhengjie.org.cn/app02/index.html
    172.30.1.106 app02
    [root@node105.yinzhengjie.org.cn ~]# 
    [root@node105.yinzhengjie.org.cn ~]# curl http://node102.yinzhengjie.org.cn/app02/index.html
    172.30.1.106 app02
    [root@node105.yinzhengjie.org.cn ~]# 
    [root@node105.yinzhengjie.org.cn ~]# curl http://node102.yinzhengjie.org.cn/app02/index.html
    172.30.1.107 app02
    [root@node105.yinzhengjie.org.cn ~]# 
    [root@node105.yinzhengjie.org.cn ~]# curl http://node102.yinzhengjie.org.cn/app02/index.html
    172.30.1.106 app02
    [root@node105.yinzhengjie.org.cn ~]# 
    [root@node105.yinzhengjie.org.cn ~]# curl http://node102.yinzhengjie.org.cn/app02/index.html
    172.30.1.107 app02
    [root@node105.yinzhengjie.org.cn ~]# 
    [root@node105.yinzhengjie.org.cn ~]# curl http://node102.yinzhengjie.org.cn/app02/index.html
    172.30.1.106 app02
    [root@node105.yinzhengjie.org.cn ~]# 
  • 相关阅读:
    对生产稳定的一些思考
    tsar指标解释
    tsar采集nginx指标
    Nginx如何处理一个连接
    Java : 如何更优雅的设计异常
    MySql的索引实现
    IntelliJ Idea 常用配置
    ICSharpCode.SharpZipLib.dll 压缩、解压Zip文件 附源码
    Java BigDecimal使用
    社交系统中用户好友关系数据库设计
  • 原文地址:https://www.cnblogs.com/yinzhengjie/p/12114195.html
Copyright © 2020-2023  润新知