눈가락

[Fluentd] Docker 를 이용한 High Aavailability 구성

눈가락 2021. 4. 15. 13:33

 

HA(High Availability) 에 대한 자세한 내용은 공식 문서 참조

 

 

< 역할 >

forward fluentd : 사용자로부터 http 데이터를 받고, active 와 backup 으로 데이터를 전송

active fluentd : forward 로부터 데이터를 전달받음

backup fluentd : active 가 죽은 경우, active 대신 forward 로부터 데이터를 전달받음

 

 

< fluentd docker containers 생성 명령어 >

docker run -d -p 9880:9880 --network my-net --name fluentd -v /home/eye/forward:/fluentd/etc -e FLUENTD_CONF=fluentd.conf fluent/fluentd:v1.6-debian-1
docker run -d --network my-net --name active -v /home/eye/active:/fluentd/etc -e FLUENTD_CONF=fluentd.conf fluent/fluentd:v1.6-debian-1
docker run -d --network my-net --name backup -v /home/eye/backup:/fluentd/etc -e FLUENTD_CONF=fluentd.conf fluent/fluentd:v1.6-debian-1

 

아래 내용을 참고하여,

/home/eye/forward,

/home/eye/active,

/home/eye/backup 에 각각 fluentd.conf 를 생성함.

 

< /home/eye/forward 내의 fluentd.conf >

# TCP input
<source>
  @type forward
  port 24224
</source>

# HTTP input
<source>
  @type http
  port 9880
</source>

# Log Forwarding
<match **>
  @type forward

  # primary host
  <server>
    host active
    port 24224
  </server>
  # use secondary host
  <server>
    host backup
    port 24224
    standby
  </server>

  # use longer flush_interval to reduce CPU usage.
  # note that this is a trade-off against latency.
  <buffer>
    flush_interval 2s
  </buffer>
</match>

 

< /home/eye/active, backup 내의 fluentd.conf >

<source>
  @type forward
  port 24224
</source>

<source>
  @type http
  port 9880
</source>

<match **>
  @type stdout
</match>

 

모든 docker container( active, backup, forward ) start 함.

 

터미널을 새로 열고, local 에서 아래 http 메세지를 전달

curl -X POST -d 'json={"json":"message"}' http://localhost:9880/sample.test

 

active 및 backup 에서 다음 명령어를 통해, forward 로부터 메세지를 잘 받는지 확인

< active 가 받는 메세지 확인 >
docker logs -f active
< backup 이 받는 메세지 확인 >
docker logs -f backup

 

 

< 테스트 >

 

1. forward 에 1~11 까지의 메세지를 차례대로 전달.

2. active 가 forward 로부터 메세지를 잘 받는지 확인.

3. 중간에 active 를 죽임.

4. timeout 이 난 이후, backup 이 active 대신 forward 로부터 메세지를 잘 받는지 확인

5. active 를 다시 살림

6. active 가 다시 forward 로부터 메세지를 잘 받는지 확인.

 

 

< forward 에게 http 메세지를 전달 >

 

< active 가 1,2,3 까지 받다가 죽었고, 다시 살아났을 때 11을 다시 받음 >

 

< 1,2,3 까지 받던 active 가 죽자, backup 이 4부터 메세지를 대신 받음 >