Haproxy 구축 웹 클 러 스 터 실험

5003 단어 nginx
여기 디 렉 터 리 제목 써 주세요.
  • Haproxy 구축 웹 클 러 스 터 실험
  • 실험 환경
  • Haproxy 서버 배치 (192.168.19.10)
  • 방화벽 을 닫 고 패 키 지 를 / opt 디 렉 터 리 에 전송
  • 컴 파일 설치 Haproxy
  • Haproxy 서버 설정
  • Nginx 노드 서버 배치 (192.168.109.20, 192.168.109.30)
  • Haproxy 서비스 시작 (192.168.19.10)
  • 브 라 우 저 테스트 웹 클 러 스 터
  • 로그 정의
  • Haproxy 구축 웹 클 러 스 터 실험
    실험 환경
    호스트
    운영 체제
    IP 주소
    Haproxy-Server
    CentOS7
    192.168.199.10
    Nginx-Server1
    CentOS7
    192.168.199.20
    Nginx-Server2
    CentOS7
    192.168.199.30
    클 라 이언 트
    CentOS7
    192.168.199.40
    Haproxy 서버 배치 (192.168.19.10)
    방화벽 을 닫 고 패 키 지 를 / opt 디 렉 터 리 로 전송 합 니 다.
    systemctl stop firewalld.service
    setenforce 0
    
    cd  /opt
    haproxy-1.5.19.tar.gz
    

    컴 파일 설치 Haproxy
    yum install -y pcre-devel bzip2-devel gcc gcc-c++ make
    
    tar zxvf haproxy-1.5.19.tar.gz
    cd haproxy-1.5.19/
    make TARGET=linux2628 ARCH=x86_64
    make install
    
        :
    TARGET=linux26  #    ,
    #  uname -r    , :2.6.18-371.el5,      TARGET=linux26;
    kernel  2.6.28  TARGET=linux2628
    
    ARCH=x86_64   #    ,64   
    

    해 프 록 시 서버 설정
    mkdir /etc/haproxy
    cp examples/haproxy.cfg /etc/haproxy/
    
    cd /etc/haproxy/
    vim haproxy.cfg
    global
    
          log /dev/log local0 info     #  4~5 ,      ,local0     ,         
          log /dev/log local0 notice
          #log loghost local0 info
          maxconn 4096                 #     ,   ulimit-n  
    
          #chroot /usr/share/haproxy   #8 ,chroot    ,           ,         
          uid 99                       #  UID
          gid 99                       #  GID
          daemon                       #      
    	  
    defaults
            log       global           #     global        
            mode      http             #   http
            option    httplog          #  http        
            option    dontlognull      #           
            retries 3                  #           ,        ,        
    		redispatch                 #         ,                
    		maxconn 2000               #     
    		contimeout     5000        #      
    		clitimeout     50000       #       
    		srvtimeout     50000       #       
    		
         listen (    ),      :
    listen webcluster 0.0.0.0:80                                     #      webcluster   
    		option httpchk GET /test.html                            #      test.html  
    	    balance roundrobin                                       #              roundrobin
    	    server inst1 192.168.199.20:80 check inter 2000 fall 3   #      
    		server inst2 192.168.199.30:80 check inter 2000 fall 3
    

    Nginx 노드 서버 배치 (192.168.109.20, 192.168.109.30)
    systemctl stop firewalld
    setenforce 0
    
    yum install -y pcre-devel zlib-devel gcc gcc-c++ make 
    
    useradd -M -s /sbin/nologin nginx
    
    cd /opt
         
    tar zxvf nginx-1.12.0.tar.gz -C /opt/
    
    cd nginx-1.12.0/
    ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx
    
    make && make install
    
    ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/
    
    nginx      #  nginx   
    

    -----192.168.199.20-----
    echo "this is test1 web" > /usr/local/nginx/html/test.html
    ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin
    

    -----192.168.199.30-----
    echo "this is test2 web" > /usr/local/nginx/html/test.html
    ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin
    

    Haproxy 서비스 시작 (192.168.19.10)
    cp /opt/haproxy-1.5.19/examples/haproxy.init /etc/init.d/haproxy
    chmod +x haproxy
    chkconfig --add /etc/init.d/haproxy
    ln -s /usr/local/sbin/haproxy /usr/sbin/haproxy
    service haproxy start   /etc/init.d/haproxy start
    

    브 라 우 저 테스트 웹 클 러 스 터
    클 라 이언 트 가 브 라 우 저 로 열기http://192.168.199.10/test.html , 끊임없이 새로 고침 브 라 우 저 테스트 부하 균형 효과
    로그 정의
  • 기본 haproxy 로 그 는 시스템 syslog 에 출력 됩 니 다. 보기 가 쉽 지 않 습 니 다. haproxy 로 그 를 잘 관리 하기 위해 서 는 생산 환경 에서 따로 정의 합 니 다. haproxy 의 info 와 notice 로 그 를 각각 다른 로그 파일 에 기록 해 야 합 니 다.
  • vim /etc/haproxy/haproxy.cfg
    global
    	log /dev/log local0 info
    	log /dev/log local0 notice
    
    service haproxy restart
    
  • 관리 하기 편리 하도록 rsyslog 설정 을 수정 해 야 합 니 다. haproxy 와 관련 된 설정 을 haproxy. conf 로 독립 적 으로 정의 하고 / etc / rsyslog. d / 아래 에 놓 으 면 rsyslog 가 시작 할 때 이 디 렉 터 리 에 있 는 모든 설정 파일 을 자동 으로 불 러 옵 니 다.
  • vim /etc/rsyslog.d/haproxy.conf
    
    if ($programname == 'haproxy' and $syslogseverity-text == 'info')
    then -/var/log/haproxy/haproxy-info.log
    &~
    if ($programname == 'haproxy' and $syslogseverity-text == 'notice')
    then -/var/log/haproxy/haproxy-notice.log
    &~
    
  • 설명: 이 부분 설정 은 haproxy 의 info 로 그 를 / var / log / haproxy / haproxy - info. log 에 기록 하고 notice 로 그 를 / var / log / haproxy / haproxy - notice. log 에 기록 합 니 다. "& ~" 로 그 를 로그 파일 에 기록 하면 rsyslog 에서 이 메 시 지 를 처리 하지 않 습 니 다.
  • systemctl restart rsyslog.service
    
    tail -f/var/log/haproxy/haproxy-info.log		#  haproxy        
    

    좋은 웹페이지 즐겨찾기