nginx 역방향 에이전트 부하 균형 기능

클 라 이언 트 = = = 프 록 시 서버 = = = 웹 서버 클 러 스 터: 1. 고가 용 클 러 스 터 HA2, 부하 균형 클 러 스 터 LB 하드웨어 구현: F5 A10 소프트웨어 구현: nginx (7 층, 1.19 버 전 이후 에 도 4 층 지원), LVS (4 층), HAproxy (4 층, 7 층)
        
3 web   ,   web     
web01  10.0.0.7   172.16.1.7
web02  10.0.0.8   172.16.1.8
web03  10.0.0.9   172.16.1.9
1        
lb01   10.0.0.5   172.16.1.5    

①. 웹 서버 배치
         :    nginx     :    web          nginx  
    mkdir /server/tools -p
    cd /server/tools
    wget http://nginx.org/download/nginx-1.12.2.tar.gz
    tar xf nginx-1.12.2.tar.gz
    yum install -y pcre-devel openssl-devel
    useradd -M -s /sbin/nologin www
    cd nginx-1.12.2
    ./configure --prefix=/application/nginx-1.12.2 --user=www --group=www --with-http_ssl_module --with-http_stub_status_module
    make && make install
    ln -s /application/nginx-1.12.2 /application/nginx
    /application/nginx/sbin/nginx
    netstat -lntup|grep nginx

        :  nginx    
   server {
       listen       80;
       server_name  www.etiantian.org;
       root   html/www;
       index  index.html index.htm;
   }
   server {
       listen       80;
       server_name  bbs.etiantian.org;
       root   html/bbs;
       index  index.html index.htm;
   }
   scp -rp /application/nginx/conf/nginx.conf 172.16.1.8:/application/nginx/conf/
   scp -rp /application/nginx/conf/nginx.conf 172.16.1.9:/application/nginx/conf/

       :        
   mkdir /application/nginx/html/{www,bbs} -p
   for name in www bbs;do echo "$(hostname) $name.etiantian.org" >/application/nginx/html/$name/oldboy.html;done
   for name in www bbs;do cat /application/nginx/html/$name/oldboy.html;done

       :         ,      
   curl -H host:www.etiantian.org 10.0.0.7/oldboy.html
   web01 www.etiantian.org
   curl -H host:bbs.etiantian.org 10.0.0.7/oldboy.html
   web01 bbs.etiantian.org
   curl -H host:www.etiantian.org 10.0.0.8/oldboy.html
   web02 www.etiantian.org
   curl -H host:bbs.etiantian.org 10.0.0.8/oldboy.html
   web02 bbs.etiantian.org
   curl -H host:www.etiantian.org 10.0.0.9/oldboy.html
   web03 www.etiantian.org
   curl -H host:bbs.etiantian.org 10.0.0.9/oldboy.html
   web03 bbs.etiantian.org

②. 부하 균형 서버 배치
         :    nginx  
    mkdir /server/tools -p
    cd /server/tools
    wget http://nginx.org/download/nginx-1.12.2.tar.gz
    tar xf nginx-1.12.2.tar.gz
    yum install -y pcre-devel openssl-devel
    useradd -M -s /sbin/nologin www
    cd nginx-1.12.2
    ./configure --prefix=/application/nginx-1.12.2 --user=www --group=www --with-http_ssl_module --with-http_stub_status_module
    make && make install
    ln -s /application/nginx-1.12.2 /application/nginx
    /application/nginx/sbin/nginx
    netstat -lntup|grep nginx

         :  nginx        
    grep -Ev "#|^$" nginx.conf.default >nginx.conf

        :http://nginx.org/en/docs/http/ngx_http_upstream_module.html#upstream
    Syntax: upstream name { ... }
    Default:    —
    Context:    http
    eg:
    upstream oldboy {
       server 10.0.0.7:80;
       server 10.0.0.8:80;
       server 10.0.0.9:80;
    }
      :upstream                   web    

        :http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_pass
    Syntax: proxy_pass URL;
    Default:    —
    Context:    location, if in location, limit_except
    eg:
    location / {
       proxy_pass http://oldboy;
    }
      :proxy_pass               upstream           

    worker_processes  1;
    events {
        worker_connections  1024;
    }
    http {
        include       mime.types;
        default_type  application/octet-stream;
        sendfile        on;
        keepalive_timeout  65;
        upstream oldboy {
            server 10.0.0.7:80;
            server 10.0.0.8:80;
            server 10.0.0.9:80;
        }
        server {
            listen       80;
            server_name  localhost;
            root   html;
            index  index.html index.htm;
          location / {
            proxy_pass http://oldboy;
           }   
        }
    }

    /application/nginx/sbin/nginx -t
    /application/nginx/sbin/nginx -s reload

         :             
    1)         
         hosts  ,    windows   hostname       10.0.0.5         。
       http://www.etiantian.org/oldboy.html  

좋은 웹페이지 즐겨찾기