본문 바로가기
Devops

[Kafka] kafka의 console 명령어

by heekng 2022. 8. 16.
반응형

Kafka의 console 명령어

kafka를 이용하면서 콘솔에 접근하여 명령어를 내려야 하는 경우 지금까지 자주 사용하던 명령어를 정리하고자 합니다.

topic 생성하기

./kafka-topics.sh --create --bootstrap-server [ip:port] --replication-factor [replication] --partitions [partitions] --topic [topicName]
  • topic을 생성합니다.
  • --bootstrap-server: 카프카 서버의 주소를 입력합니다.
  • --replication-factor: replication의 수를 입력합니다.
  • --partitions: 해당 토픽의 partition 수를 입력합니다.
  • --topic: 해당 토픽의 이름을 지정합니다.

topic 리스트 확인하기

./kafka-topics.sh --list --bootstrap-server [ip:port]
  • 현재 kafka에 생성된 topic 리스트를 확인합니다.
  • --bootstrap-server: 카프카 서버의 주소를 입력합니다.

topic 상세보기

./kafka-topics.sh --describe --bootstrap-server [ip:port] --topic [topicName]
  • 생성된 토픽의 상세 정보를 확인합니다.
  • --bootstrap-server: 카프카 서버의 주소를 입력합니다.
  • --topic: 해당 토픽의 이름을 지정합니다.

topic 데이터 추가 (producer)

./kafka-console-producer.sh --broker-list [ip:port] --topic [topicName]
  • topic에 데이터를 추가합니다.
  • --broker-list: 카프카 서버의 주소를 입력합니다.
  • --topic: 해당 토픽의 이름을 지정합니다.

topic 데이터 확인 (consumer)

./kafka-console-consumer.sh --bootstrap-server [ip:port] --topic [topicName] --from-beginning
  • topic 안에 들어간 데이터를 확인합니다.
  • --bootstrap-server: 카프카 서버의 주소를 입력합니다.
  • --topic: 해당 토픽의 이름을 지정합니다.
  • --from-beginning: 명령어를 내린 이전에 존재하던 데이터도 함께 확인합니다.

topic offset 확인

./kafka-run-class.sh kafka.tools.GetOffsetShell --broker-list [ip:port] --topic [topicName]
  • topic의 offset을 확인합니다.
  • --broker-list: 카프카 서버의 주소를 입력합니다.
  • --topic: 해당 토픽의 이름을 지정합니다.
반응형