home

카프카 설치하기

브로커 설정하기

# The id of the broker. This must be set to a unique integer for each broker.
broker.id=0
  • 브로커 ID는 클러스터 안의 브로커별로 전부 달라야 한다.
# The address the socket server listens on. It will get the value returned from 
# java.net.InetAddress.getCanonicalHostName() if not configured.
#   FORMAT:
#     listeners = listener_name://host_name:port
#   EXAMPLE:
#     listeners = PLAINTEXT://your.host.name:9092
listeners=PLAINTEXT://localhost:9092
  • 9092 TCP 포트에서 돌아가는 리스너와 카프카를 실행시킨다.
############################# Zookeeper #############################

# Zookeeper connection string (see zookeeper docs for details).
# This is a comma separated host:port pairs, each corresponding to a zk
# server. e.g. "127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002".
# You can also append an optional chroot string to the urls to specify the
# root directory for all kafka znodes.
zookeeper.connect=localhost:2181
  • 브로커의 메타데이터가 저장되는 주키퍼의 위치를 가르킨다.
# The number of threads per data directory to be used for log recovery at startup and flushing at shutdown.
# This value is recommended to be increased for installations with data dirs located in RAID array.
num.recovery.threads.per.data.dir=1
  • 설정 가능한 스레드 풀을 사용해서 로그 세그먼트를 관리

  • auto.leader.rebalance.enable
    • 리더 역할을 균등하게 분산해준다.
    • leader.imbalance.per.borker.percentage에 설정 값이 넘어가면 파티션의 선호리더 리밸런싱 발생
  • num.partitions=1
    • 토픽 생성시 몇 개의 파티션을 갖게하는지 설정
    • 대부분 토픽당 파티션 개수를 클러스터 내 브로커 수와 맞추거나 배수로 한다.
    • 토픽의 목표 처리량과 컨슈머의 예쌍 처리량에 대해서 추정 값이 있으면 전자를 후자로 나눠서 추정치를 얻을 수 있다.
    • 디스크 안에 저장되어있는 파티션의 용량을 6gb 미만으로 유지하는게 좋다.
  • log.retention.hours=168
    • 카프카가 얼마나 오랫동안 메시지를 보존해야 하는가?
  • log.retention.bytes=1073741824
    • 파티션 별 메시지 용량
    • 모든 보존 기능은 파티션 단위이지 토픽 단위가 아니다.
    • 파티션이 하나 늘어나면 토픽의 최대 용량이 설정 값만큼 늘어난다.
  • log.segment.bytes=1073741824
    • 로그 세그먼트가 해당 용량에 다다르면 기존 세그먼트를 닫고 새로운 세그먼트를 연다.
    • 닫히기 전까지는 삭제의 대상이 되지 않기 때문에 값을 적절히 설정해야함
  • min.insync.replicas
    • 몇 개의 레플리카가 최신 상태로 프로듀서와 동기화 하는가?

하드웨어 선택하기

  • 브로커의 디스크 처리량은 프로듀서 클라이언트 성능에 가장 큰 영향
  • 메모리는 컨슈머가 페이지 캐시에 저장되어있는 메시지를 받아오는 데 성능에 영향

브로커 개수

  • 디스크 용량
  • 브로커당 레플리카 용량
  • CPU 용량
  • 네트워크 용량