HAProxy

SunChan Kwon·2024년 6월 11일
0

Linux

목록 보기
19/20

webserver1

network

nmcli connection add type ethernet con-name static ifname eth1 ipv4.addresses 192.168.10.10/24 ipv4.method manual

package

$ dnf install httpd

$ systemctl enable --now httpd

http index file

$ echo "This is 01-webserver" > /var/www/html/index.html

firewall

$ firewall-cmd --add-service=http

webserver2

network

nmcli connection add type ethernet con-name static ifname eth1 ipv4.addresses 192.168.10.20/24 ipv4.method manual

package

$ dnf install httpd

$ systemctl enable --now httpd

http index file

$ echo "This is 02-webserver" > /var/www/html/index.html

firewall

$ firewall-cmd --add-service=http

haproxy server

network

nmcli connection add type ethernet con-name static ifname eth1 ipv4.addresses 192.168.10.100/24 ipv4.method manual

package

dnf install -y httpd
dnf install -y haproxy

config

$ vi /etc/haproxy/haproxy.cfg

    log         127.0.0.1 local2

    chroot      /var/lib/haproxy
    pidfile     /var/run/haproxy.pid
    maxconn     4000
    user        haproxy
    group       haproxy
    daemon
    .
    .
    .
    # 기타 옵션, 타임 아웃 등 설정
    defaults
    mode                    http # 웹 서버에 대한 로드밸런싱(애플리케이션 계층)
    log                     global
    option                  httplog
    option                  dontlognull
    option http-server-close
    option forwardfor       except 127.0.0.0/8
    option                  redispatch
    retries                 3
    timeout http-request    10s
    timeout queue           1m
    timeout connect         10s
    timeout client          1m
    timeout server          1m
    timeout http-keep-alive 10s
    timeout check           10s
    maxconn                 3000
	
    # 
	frontend main
    	bind *:80 # 모든 ip의 http 통신 가능
    default_backend             app
    # lb를 거쳐갈 실제 서버
	backend app
    	balance     roundrobin # 번갈아가며 전송하는 라운드 로빈 방식
   	 	server  app1 192.168.10.10:80 check
    	server  app2 192.168.10.20:80 check
        
# 파일 설정 후 시스템 시작
$ systemctl enable --now haproxy.service 

$ ss -nltp | grep 80
LISTEN 0      3000         0.0.0.0:80        0.0.0.0:*    users:(("haproxy",pid=3794,fd=6))

firewall

$ firewall-cmd --add-service=http

loadbalancing 확인

0개의 댓글