728x90
<실습5 :: HAproxy 구성>
- HAproxy란?
- 실제 서버 앞단에 존재하며 서버로 오는 요청을 대신 받아 뒷단의 서버에 전달하고 결과를 리턴받아 요청한 곳에 다시 전달하는 역할
- 리버스프록시를 기반으로 한 L4, L7 소프트웨어 로드밸런서
1. 네트워크 생성 (proxy-net)
ubuntu@host1:~/Labs/ch05$ docker network create proxy-net
1ab9e69cadd92c6c5a87e622e99b8383d715986a150275c3d69e1a576060a56a
<네트워크 생성 확인>
ubuntu@host1:~/Labs/ch05$ docker network ls
NETWORK ID NAME DRIVER SCOPE
711070d16ea3 bridge bridge local
10ae368d91ff han-net bridge local
a10c647d79d1 host host local
2785de26c8d7 none null local
**1ab9e69cadd9 proxy-net bridge local**
<라우트 설정 확인>
ubuntu@host1:~/Labs/ch05$ route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default _gateway 0.0.0.0 UG 100 0 0 enp0s3
default 192.168.56.2 0.0.0.0 UG 20101 0 0 enp0s8
10.0.2.0 0.0.0.0 255.255.255.0 U 100 0 0 enp0s3
link-local 0.0.0.0 255.255.0.0 U 1000 0 0 enp0s8
172.17.0.0 0.0.0.0 255.255.0.0 U 0 0 0 docker0
172.18.0.0 0.0.0.0 255.255.0.0 U 0 0 0 br-10ae368d91ff
**172.19.0.0 0.0.0.0 255.255.0.0 U 0 0 0 br-1ab9e69cadd9**
192.168.56.0 0.0.0.0 255.255.255.0 U 101 0 0 enp0s8
2. 컨테이너 생성
ubuntu@host1:~/Labs/ch05$ docker run -d -p 6001:5678 --net=proxy-net --name=echo-web1 hashicorp/ht
tp-echo -text="Webserver1"
ad0f99349e524b2c3e58270a61eb9e8915ae83158fc009872507bac96b089f34
ubuntu@host1:~/Labs/ch05$ docker run -d -p 6002:5678 --net=proxy-net --name=echo-web2 hashicorp/htt
p-echo -text="Webserver2"
e5354212c154bd6af108b09721f776b6df8f41a194aa96aa7cb50269b9b7d240
ubuntu@host1:~/Labs/ch05$ docker run -d -p 6003:5678 --net=proxy-net --name=echo-web3 hashicorp/htt
p-echo -text="Webserver3"
b0cd8ddc0e5cae5e25aa8ff0e6664eb765590a456a2022d26b83c7ffc05d4b09
ubuntu@host1:~/Labs/ch05$ docker container ps
<상태확인>
- echo-web1 / echo-web2 / echo-web3
ubuntu@host1:~/Labs/ch05$ docker container ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
**b0cd8ddc0e5c hashicorp/http-echo "/http-echo -text=We…" 3 seconds ago Up 2 seconds 0.0.0.0:6003->5678/tcp, :::6003->5678/tcp echo-web3
e5354212c154 hashicorp/http-echo "/http-echo -text=We…" 14 seconds ago Up 14 seconds 0.0.0.0:6002->5678/tcp, :::6002->5678/tcp echo-web2
ad0f99349e52 hashicorp/http-echo "/http-echo -text=We…" 31 seconds ago Up 31 seconds 0.0.0.0:6001->5678/tcp, :::6001->5678/tcp echo-web1**
9a8418c7ee8e nginx:1.25.0-alpine "/docker-entrypoint.…" 32 minutes ago Up 20 minutes 0.0.0.0:5000->80/tcp, :::5000->80/tcp proxy-container
4e49879f5e7f nginx "/docker-entrypoint.…" 2 hours ago Up 2 hours 0.0.0.0:8003->80/tcp, :::8003->80/tcp alb-node03
5616dd359296 nginx "/docker-entrypoint.…" 2 hours ago Up 2 hours 0.0.0.0:8002->80/tcp, :::8002->80/tcp alb-node02
ccd6c942f9f5 nginx "/docker-entrypoint.…" 2 hours ago Up 2 hours 0.0.0.0:8001->80/tcp, :::8001->80/tcp alb-node01
3. haproxy.cfg 편집
ubuntu@host1:~/Labs/ch05$ vi haproxy.cfg
<vi 편집내용>
global
stats socket /var/run/api.sock user haproxy group haproxy mode 660 level admin expose-fd listeners
log stdout format raw local0 info
defaults
mode http
timeout client 10s
timeout connect 5s
timeout server 10s
timeout http-request 10s
log global
frontend stats
bind *:8404
stats enable
stats uri /
stats refresh 10s
frontend myfrontend
bind :80
default_backend webservers
**backend webservers
server s1 echo-web1:5678 check
server s2 echo-web2:5678 check
server s3 echo-web3:5678 check**
<컨테이너 생성>
ubuntu@host1:~/Labs/ch05$ docker container run -d --name=haproxy-container --net=proxy-net -p 80:80 -p 8404:8404 -v $(pwd):/usr/local/etc/haproxy:ro haproxytech/haproxy-alpine:2.5
Unable to find image 'haproxytech/haproxy-alpine:2.5' locally
2.5: Pulling from haproxytech/haproxy-alpine
96526aa774ef: Pull complete
25597ce8cc3a: Pull complete
356dd0b52d3e: Pull complete
f528cddf9d74: Pull complete
cf680ef11bb3: Pull complete
Digest: sha256:5cecad80d3e517f764d4801039d63482260cf40697aa11607c618889c7f3531e
Status: Downloaded newer image for haproxytech/haproxy-alpine:2.5
a5ba66a07e2408352f877fa8fca545a2654e8421de3296f735472d171f95ba6a
<컨테이너 생성 결과 확인>
ubuntu@host1:~/Labs/ch05$ docker container ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a5ba66a07e24 haproxytech/haproxy-alpine:2.5 "/docker-entrypoint.…" 56 seconds ago Up 54 seconds 0.0.0.0:80->80/tcp, :::80->80/tcp, 0.0.0.0:8404->8404/tcp, :::8404->8404/tcp haproxy-container
b0cd8ddc0e5c hashicorp/http-echo "/http-echo -text=We…" 27 minutes ago Up 27 minutes 0.0.0.0:6003->5678/tcp, :::6003->5678/tcp echo-web3
e5354212c154 hashicorp/http-echo "/http-echo -text=We…" 27 minutes ago Up 27 minutes 0.0.0.0:6002->5678/tcp, :::6002->5678/tcp echo-web2
ad0f99349e52 hashicorp/http-echo "/http-echo -text=We…" 27 minutes ago Up 27 minutes 0.0.0.0:6001->5678/tcp, :::6001->5678/tcp echo-web1
9a8418c7ee8e nginx:1.25.0-alpine "/docker-entrypoint.…" 59 minutes ago Up 47 minutes 0.0.0.0:5000->80/tcp, :::5000->80/tcp proxy-container
4e49879f5e7f nginx "/docker-entrypoint.…" 3 hours ago Up 3 hours 0.0.0.0:8003->80/tcp, :::8003->80/tcp alb-node03
5616dd359296 nginx "/docker-entrypoint.…" 3 hours ago Up 3 hours 0.0.0.0:8002->80/tcp, :::8002->80/tcp alb-node02
ccd6c942f9f5 nginx "/docker-entrypoint.…" 3 hours ago Up 3 hours 0.0.0.0:8001->80/tcp, :::8001->80/tcp alb-node01
<컨테이너 가동 확인>
1. 192.168.56.101:8404 접속해 컨테이너 가동 확인
2. curl localhost로 결과 확인
ubuntu@host1:~/Labs/ch05$ curl localhost
Webserver1
ubuntu@host1:~/Labs/ch05$ curl localhost
Webserver2
ubuntu@host1:~/Labs/ch05$ curl localhost
Webserver3
ubuntu@host1:~/Labs/ch05$ curl localhost
Webserver1
ubuntu@host1:~/Labs/ch05$ curl localhost
Webserver2
ubuntu@host1:~/Labs/ch05$ curl localhost
Webserver3
ubuntu@host1:~/Labs/ch05$ curl localhost
Webserver1
ubuntu@host1:~/Labs/ch05$ curl localhost
Webserver2
ubuntu@host1:~/Labs/ch05$ curl localhost
Webserver3
ubuntu@host1:~/Labs/ch05$ curl localhost
Webserver1
ubuntu@host1:~/Labs/ch05$ curl localhost
Webserver2
ubuntu@host1:~/Labs/ch05$ curl localhost
Webserver3
'클라우드 + DevOps > Docker' 카테고리의 다른 글
Docker :: 컨테이너CPU 자원 한계 설정 (1) | 2024.02.25 |
---|---|
Docker 네트워크 실습 심화 :: HAproxy ACL 조건 설정 (1) | 2024.02.24 |
Docker 네트워크 실습 :: NginX 컨테이너 리버스 프록시 구성 (0) | 2024.02.22 |
Docker 네트워크 실습 :: NginX 리버스 프록시 구성 (0) | 2024.02.21 |
Docker 네트워크 실습 :: DNS와 부하분산 설정 (0) | 2024.02.20 |