'haproxy'에 해당되는 글 2건

  1. 2017.03.28 socket.io load balancing with HAProxy on Docker
  2. 2017.03.24 HAProxy with Docker

Load Balancing with HAProxy on Docker


Setup


HAProxy + Socket.io + Node

 


HAProxy Config 


haproxy.cfg


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
global
  maxconn 4096
 
defaults
  mode http
  balance roundrobin
  option redispatch
  option forwardfor
  timeout connect 5s
  timeout queue 5s
  timeout client 50s
  timeout server 50s
 
listen stats
  bind  *:1936
  mode  http
  stats enable
  stats uri /stats
  stats auth guest:guest
  stats refresh 5s
 
frontend http-in
  bind *:8000
 
# check request ws acl
  acl backend_ws path_beg /socket.io
  acl backend_ws hdr(Upgrade) -i webSocket
  acl backend_ws hdr_beg(Host) -i ws
 
# if it is ws request , use websockets
  use_backend websockets if is_websocket
# if it is http request, use webservers
  default_backend servers 
 
backend servers # web server
  server server1 [address]:[port] check
#example
#server server1 172.17.0.10:8080 check
 
backend websockets # socket server
  balance source # if use balance to roundrobin, you have to use stick option
  option http-server-close
  option forceclose
  server ws-server1 [address]:[port] maxconn 30000 weight 1 maxconn 1024 check
#example
#server ws-server1 172.17.0.1:80 maxconn 30000 weight 1 maxconn 1024 check
  #server ws-server2 172.17.0.2:80 maxconn 30000 weight 1 maxconn 1024 check
  #server ws-server3 172.17.0.3:80 maxconn 30000 weight 1 maxconn 1024 check
cs


Docker run HAProxy


1
docker run -d -p 1936:1936 -p 8000:8000 --name docker-haproxy my-haproxy
cs


reference - http://mydreamisthebestcooder.tistory.com/78


Test

Load test

1. Use websocket-bench


1
$ websocket-bench -a 100 -c 20 ws://127.0.0.1:8000
cs


https://github.com/M6Web/websocket-bench


2. Use Socket.io test client

http://amritb.github.io/socketio-client-tool/



Posted by 사용자 guru_k

댓글을 달아 주세요

HAProxy with Docker

Docker 2017. 3. 24. 22:14

Use HAProxy with Docker


1. Create Dockerfile for HAProxy Build with Docker 

1
2
FROM haproxy:1.7 // Set HAProxy version
ADD haproxy.cfg /usr/local/etc/haproxy/haproxy.cfg
cs


2. Docker build using Dockerfile created

1
docker build -t my-haproxy .
cs


3.  After you build Dockerfile, you can find docker images that is my-haproxy 

1
2
3
$ docker images
REPOSITORY                              TAG                 IMAGE ID            CREATED             SIZE
my-haproxy                              latest              98f53e224010        5 hours ago         134.9 MB
cs


4. To create HAProxy you should make haproxy.cfg that is configure file for haproxy. 

For test I already created two nodes

haproxy.cfg are contained health check 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
global
 
  log 127.0.0.1  local0
  log 127.0.0.1  local1 notice
  maxconn  8192
 
defaults
  balance roundrobin
  log     global
  mode    tcp
  option  tcplog
  option  redispatch
  option  log-health-checks
  retries 5
  maxconn 8192
  timeout connect 50s
  timeout client  500s
  timeout server  500s
 
listen stats
  bind  *:1936
  mode  http
  stats enable
  stats uri /stats
  stats auth guest:guest
  stats refresh 5s
 
listen web
bind *:80 mode http balance roundrobin server web1 172.17.0.8:7777 check server web2 172.17.0.9:7778 check
cs


  • stats
    • Set haproxy monitoring
    • You can connect [host_ip]:1936/stats and see haproxy web ui
    • auth - account ID / account PW
  • web
    • Bind 80 port.
    • balance mode is roundrobin.
    • health check for web1, web2.

5. Use haproxy.cfg that you set to run the docker.
1
docker run -d -p 1936:1936 -p 80:80 --name docker-haproxy my-haproxy
cs

6. If docker is run well, You can see the stats UI.
Through [host_ip]:1936/stats, You can see web ui below.




Posted by 사용자 guru_k

댓글을 달아 주세요