• 简单的负载均衡


    架构图

    client -- > reverser server --> server 129
                                --> server 130

    准备

    1.配置3台虚拟机,操作系统使用centos7.0+,ip如下

    • 192.168.154.129
    • 192.168.154.130
    • 192.168.154.132

    2 一个纯静态html文件-index.html

    <html>
    <head>
    <title>hi nlb!</title>
    </head>
    
    <body>
    hi~, this is 192.168.154.129!
    </body>
    </html>

    3.通用配置

    # 在3台上安装nginx
    yum install -y nginx
    
    # 关闭防火墙
    setenforce 0
    
    chkconfig iptables off
    firewall-cmd --state
    
    # 稍后会修改服务器目录为/nlb
    mkdir /nlb
    vim /nlb/index.html # 根据ip修改准备index.html
    

    代理机配置(反向代理+负载均衡配置)

    • vim /etc/nginx/nginx.conf
    upstream nlb {
     ip_hash;
     server 192.168.154.129:6180;
     server 192.168.154.130:6180;
    }
    
    server {
     listen 6180 default_server;
     listen [::]:6180 default_server;
     server_name www.nlb.com;
     root /nlb/;
    
     # Load configuration files for the default server block.
     include /etc/nginx/default.d/*.conf;
    
     location / {
      proxy_pass http://nlb;
      proxy_set_header Host $host:server_port;
     }
    
     error_page 404 /404.html;
      location = /40x.html {
     }
    
     error_page 500 502 503 504 /50x.html;
      location = /50x.html {
     }
    }
    
    • 启动服务
    service nginx start
    

    129服务器上的配置

    • vim /etc/nginx/nginx.conf
    server {
     listen 6180 default_server;
     listen [::]:6180 default_server;
     server_name _;
     root /nlb;
    
     # Load configuration files for the default server block.
     include /etc/nginx/default.d/*.conf;
    
     location / {
     }
    
     error_page 404 /404.html;
      location = /40x.html {
     }
    
     error_page 500 502 503 504 /50x.html;
      location = /50x.html {
     }
    }
    • 启动服务
    service nginx start
    

    130服务器上的配置

    • vim /etc/nginx/nginx.conf
    server {
     listen 6180 default_server;
     listen [::]:6180 default_server;
     server_name _;
     root /nlb;
    
     # Load configuration files for the default server block.
     include /etc/nginx/default.d/*.conf;
    
     location / {
     }
    
     error_page 404 /404.html;
      location = /40x.html {
     }
    
     error_page 500 502 503 504 /50x.html;
      location = /50x.html {
     }
    }
    • 启动服务
    service nginx start
    

    浏览器上访问 http://192.168.154.132:6180/index.html

  • 相关阅读:
    APP测试
    Pycharm+Rf框架的自动化
    Robot Framework框架做UI自动化测试的介绍
    python-元组
    python-list一些用法
    [Python]之列表list
    接口测试用例(安全测试)
    cookie与session机制
    接口测试与网络通讯原理
    简单常用的SQL命令
  • 原文地址:https://www.cnblogs.com/gelu/p/9916811.html
Copyright © 2020-2023  润新知