Kafka 완전 정복 : 클러스터 구축부터 MSA 환경 활용까지/클러스터 구축부터 MSA 환경에서 활용까지

Ch01. Kafka 설치와 설정 - Kafka 빠르게 설치해보기

webmaster 2023. 4. 11. 23:54
728x90

Kafka 설치하기

https://kafka.apache.org/downloads

 

Apache Kafka

Apache Kafka: A Distributed Streaming Platform.

kafka.apache.org

Scala 2.13에 압축된 버전으로 설치하기를 권장한다.

Zookeeper 실행하기

카프카를 띄우기 위해서는 Zookeeper를 먼저 띄어야 한다.

bin/zookeeper-server-start.sh config/zookeeper.properties

2181 Port로 Zookeeper가 떴는지 확인해야 한다.

bin/zookeeper-shell.sh localhost:2181

해당 명령어로 Zookeeper 쉘에 접속할 수 있다.

Broker 실행하기

vi 명령어로 Broker 설정파일 수정

vi config/server.properties

주석 해제 후 listeners 부분 변경

주석 해제 후 listeners 부분 변경

서버 실행하기 

bin/kafka-server-start.sh config/server.properties

토픽 생성

토픽 생성

bin/kafka-topics.sh --create --topic fastcampus --bootstrap-server localhost:9092
  • 토픽이름은 공백을 허용하지 않고, "_", "." 같은 경우는 내부에 사용하고 있는 것이 있기 때문에 사용하지 않는 것이 좋다.
  • 토픽을 이름은 최대 249자까지 허용한다.

토픽 확인

bin/kafka-topics.sh --list --topic fastcampus --bootstrap-server localhost:9092

프로듀서 생성

bin/kafka-console-producer.sh --bootstrap-server localhost:9092 --topic fastcampus

컨슈머 생성

bin/kafka-console-producer.sh --bootstrap-server localhost:9092 --topic fastcampus

단, 해당 컨슈머는 이전 메시지를 받을 수 없다. -> 받고 싶다면 아래와 같은 옵션으로 생성해야 한다.

bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic fastcampus --from-beginning

Zookeeper에 접근해서 확인해 보면 내가 생성하지 않은 Topic이 생성되어 있다.

  • 카프카에서는 컨슈머 그룹이 읽어간 컴슈머 옵셋정보를 저장하고 있다.(__consumer_offsets)
  • 컨슈머가 죽거나 문제가 발생했을 때, 해당 정보를 참조해서 옵셋 정보를 가지고 정보를 조회할 수 있다.
728x90