Sysops Notepad

[Linux] Centos Haproxy Client IP forward 설정 본문

업무/sys

[Linux] Centos Haproxy Client IP forward 설정

sysops 2019. 2. 19. 16:16
global

        daemon  # 백그라운드에서 동작
        user    haproxy 
        group   haproxy
        log     127.0.0.1   local0
        log     127.0.0.1   local1 notice
    
 		maxconn 4096  # 프로세스 별 최대 connection 갯수
        ssl-default-bind-options no-sslv3  # Bind SSL 프로토콜 정의
        ssl-default-bind-ciphers ECDHE-RSA-AES128-GCM-SHA256:...  # Bind SSL 사용 알고리즘 목록 정의
 		ssl-default-server-options no-sslv3  # Server SSL 프로토콜 정의
        ssl-default-server-ciphers ECDHE-RSA-AES128-GCM-SHA256:...  # Server SSL 사용 알고리즘 목록 정의
   
 		tune.ssl.cachesize 100000  # SSL Session Cache 크기 설정
        tune.ssl.lifetime 600  # SSL Session 유효시간 설정
        tune.ssl.default-dh-param 2048  # Diffie-Hellman 키 교환 시 최대 크기 설정



frontend https-in
        mode    http
        log     global
        option  httplog
        option  dontlognull

        bind *:80         # listening 되어야하는 ip, port 설정
        bind *:443 ssl crt ~/key.pem ca-file ~/key.ca verify optional alpn h2,http/2
        timeout client  30s  # client에서 haproxy 접속 시 timeout 설정
        timeout http-keep-alive 5s  # 새로운 http 요청이 들어오기까지의 대기시간

        acl stats hdr(host) -i test.haproxy.com  # host 지정 모든문자열이 일치 할 경우
        acl host_api_cluster hdr(host) -i test.server.com
        use_backend haproxy_stats if host_haproxy_stats # host가 일치할 때 지정 된 backend로 진행
        use_backend test_server if host_api_cluster

backend test_server
        mode    http
        log     global
        option  httplog
 		#option forwardfor header X-Client-IP
 		#option http-server-close

        balance leastconn  # 요청 분배 알고리즘 설정
        timeout connect 10s  # haproxy에서 server 접속 시 timeout 설정
        timeout check   5s  # haproxy에서 check 목적으로 접속 시 timeout 설정
        timeout server  30s  # haproxy에서 server 접속 시 timeout 설정
        timeout http-keep-alive 5s  # 새로운 http 요청이 들어오기까지의 대기시간

        acl valid_method method GET POST PUT DELETE  # 허용할 메소드 설정
        http-request deny if ! valid_method # 메소스 조건 확인
        http-request replace-value Host (.*):.* 1  # server에 client에서 요청한 Host 전달
        http-request set-header x-forwarded-for %ci  # server에 remoteAddress 전달
 		#http-request set-header X-Client-IP %[src]
        #http-request set-header X-Client-IP req.hdr_ip([X-Forwarded-For]) 
        
        option httpchk GET /status  # server에 지정된 상태 체크 url로 요청하여 확인
        http-check expect status 200 string OK  # 응답 시 상태코드 200 + 문자열 OK 확인
        default-server inter 100 rise 2 fall 5  # 검사 조건 (확인 주기 100/ms, 2번이상 성공시 정상 확인, 5번이상 실패 시 제외)
        
        server server-001 192.168.0.1:8080 check  # 서버 alias, ip:port, 검사 여부
        server server-002 192.168.0.2:8080 check 
        server server-003 192.168.0.3:8080 check

backend stats
        mode    http
        log     global
        option  httplog
        option http-server-close  # 응답이 완료되면 server 측에서 연결을 종료함
        stats enable  # 모니터링 활성화
        stats auth id:password  # 모니터링 인증 활성화 basic auth 아이디, 비밀번호 설정
        stats uri /stats  # 모니터링 페이지 url 설정
        stats hide-version  # 버전 숨김

 

참고:

https://belong2jesus.tistory.com/89

https://meetup.toast.com/posts/163

https://blog.whitelife.co.kr/321

 

Comments