[Fluentd] Consumer

AnHyunDong·2022년 6월 27일
0

개요

  • 실시간 크롤링한 뉴스 데이터를 전달할 플랫폼이 필요함
  • Consumer를 Fluentd를 사용할 예정
  • EC2(Python) -> Kafka -> Fluentd -> Elastic Search로 전달 예정
  • Fluentd로 보낸 데이터는 다시 ES(Elastic Search)로 전달할 예정
  • 크롤러 url : 크롤러
  • 따라서 Consumer를 Fluentd로 짜볼 예정

제한사항

  • topic 이름은 news(대문자가 들어가면 안됨)
  • 보낼 데이터(네이버 뉴스)
    • 뉴스 제목
    • 신문사
    • 뉴스 장르(정치, IT, 생활, 세계 등 6개)
    • 뉴스 url
  • 출력(stdout)은 표준출력으로 할 것(나중에 es로 전달할 예정)

Set Up

출처 : docs

ulimit -n
  • 위 코드 입력시 1024가 나오면 아래 코드 실행
  • /etc/security/limits.conf에 아래 코드 입력
vi /etc/security/limits.conf
    root soft nofile 65536
	root hard nofile 65536
	soft nofile 65536
	hard nofile 65536

  • /etc/sysctl.conf에 아래 코드 입력
vi /etc/sysctl.conf
	net.core.somaxconn = 1024
	net.core.netdev_max_backlog = 5000
	net.core.rmem_max = 16777216
	net.core.wmem_max = 16777216
	net.ipv4.tcp_wmem = 4096 12582912 16777216
	net.ipv4.tcp_rmem = 4096 12582912 16777216
	net.ipv4.tcp_max_syn_backlog = 8096
	net.ipv4.tcp_slow_start_after_idle = 0
	net.ipv4.tcp_tw_reuse = 1
	net.ipv4.ip_local_port_range = 10240 65535
  • /etc/sysctl.d/10-link-restrictions.conf 또는 /usr/lib/sysctl.d/50-default.conf에 아래 코드가 적혀있는지 확인
vi /etc/sysctl.d/10-link-restrictions.conf
vi /usr/lib/sysctl.d/50-default.conf
	fs.protected_hardlinks = 1
	fs.protected_symlinks = 1

Install

  • 지원 버전을 보고 다운로드

# curl 다운로드
apt install curl
# Bionic(Ubuntu 18.04 버전)
curl -fsSL https://toolbelt.treasuredata.com/sh/install-ubuntu-bionic-td-agent4.sh | sh
  • 설치되었는지 확인
systemctl status td-agent

Code

  • /etc/td-agent/td-agent.conf에서 코드 수정
  • @ 뒤에 연결할 방법을 입력
  • <source> : 데이터 받는 부분 > Consumer 역할
  • <match> : 데이터를 전달하는 부분 > stdout 즉, 표준출력하는 모습
<source>
  @type kafka

  brokers kafka2-59655564bd-cmfjg:9092
  format json
  tag news

  <topic>
    topic news
  </topic>

</source>

<match news>
  @type stdout
  include_timestamp true
  index_name news
  type_name fluentd
</match>

결과

URL

실시간 뉴스

profile
사진은 남아 추억이 메모는 남아 스펙이 된다

0개의 댓글