Today
Total
KoreanEnglishFrenchGermanJapaneseSpanishChinese (Simplified)
관리 메뉴

DB & AWS Knowledge

Kafka Broker 설치 방법 본문

Kafka, MSK, Kinesis/아키텍처 및 내부 구조

Kafka Broker 설치 방법

`O` 2025. 6. 16. 02:46
728x90
반응형

이 페이지에서는 Zookeeper 설치 이후, Kafka Broker 를 설치하는 방법에 대하여 다룬다.

Kafka Broker 설치는 Zookeeper 설치가 먼저 선행 되어야 하기에 아래의 게시글을 먼저 참조 및 수행 후, 이 게시글을 확인하는 것을 권장한다.

 

[1] 2025.06.13 - [Kafka, MSK, Kinesis/아키텍처 및 내부 구조] - Zookeeper 설치 방법 - 기본설치

 

[2] 2025.06.15 - [Kafka, MSK, Kinesis/아키텍처 및 내부 구조] - Zookeeper 설치 방법 - 앙상블 (ensemble) 구성

 

또한 설치하는 방법에 추가로 덧붙일 내용은 ※ 로 추가한다.

 

필자는 AWS EC2 Linux 2 기준으로 Kafka 를 설치한다.

 

Kafka 설치

 

Zookeeper 를 설치했다면 이제 Kafka 를 설치할 수 있다.

Kafka 는 아래의 링크에서 설치할 버전을 고르면 된다.

 

[+] https://kafka.apache.org/downloads

 

- 여기서 필자는 Scala 2.13.0 - Kafka 3.9.1 버전을 사용한다.

 

출처 : 본인 테스트

 

※ Kakfa 는 JVM 기반에서 작동하는 Scala 언어로 만들어졌다.

 

- EC2 에서 Zookeeper 와 유사하게 wget 으로 다운로드 및 tar 로 압축을 푼다.

(필자는 ec2-user home directory 에 이를 설치 및 구성을 한다.)

 

$ wget https://dlcdn.apache.org/kafka/3.9.1/kafka_2.13-3.9.1.tgz
--2025-06-15 17:00:49--  https://dlcdn.apache.org/kafka/3.9.1/kafka_2.13-3.9.1.tgz
Resolving dlcdn.apache.org (dlcdn.apache.org)... 151.101.2.132, 2a04:4e42::644
Connecting to dlcdn.apache.org (dlcdn.apache.org)|151.101.2.132|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 122110298 (116M) [application/x-gzip]
Saving to: ‘kafka_2.13-3.9.1.tgz’

100%[========================================================================================>] 122,110,298  316MB/s   in 0.4s

2025-06-15 17:00:50 (316 MB/s) - ‘kafka_2.13-3.9.1.tgz’ saved [122110298/122110298]

$ tar -xzf kafka_2.13-3.9.1.tgz

 

 

- kafka 의 log 를 보관할 디렉토리를 임의로 생성 후, kafka 디렉토리에 있는 bin 디렉토리에서 아래의 명령어로 kafka daemon 을 실행한다.

 

# log 디렉토리 생성

$ mkdir /tmp/kafka-logs
 
# bin 디렉토리에서 daemon 기동
 
$ sh /home/ec2-user/kafka_2.13-3.9.1/bin/kafka-server-start.sh \
> -daemon /home/ec2-user/kafka_2.13-3.9.1/config/server.properties

# kafka 기동유무 확인

$ ps -ef | grep kafka

ec2-user 20794     1  4 17:06 pts/1    00:00:06 /usr/java/jdk-17.0.2//bin/java -Xmx1G -Xms1G -server -XX:+UseG1GC -XX:MaxGCPauseMillis=20 -XX:InitiatingHeapOccupancyPercent=35 -XX:+ExplicitGCInvokesConcurrent -XX:MaxInlineLevel=15 -Djava.awt.headless=true -Xlog:gc*:file=/home/ec2-user/kafka_2.13-3.9.1/bin/../logs/kafkaServer-gc.log:time,tags:filecount=10,filesize=100M -Dcom.sun.management.jmxremote=true -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dkafka.logs.dir=/home/ec2-user/kafka_2.13-3.9.1/bin/../logs -Dlog4j.configuration=file:/home/ec2-user/kafka_2.13-3.9.1/bin/../config/log4j.properties -cp /home/ec2-user/kafka_2.13-3.9.1/bin/../libs/activation-1.1.1.jar:/home/ec2-user/kafka_2.13-3.9.1/bin/../libs/aopalliance-repack
(...)

 

- Kafka 기동을 확인하면 아래 명령어들을 수행하여 topic 을 생성하고, 메시지를 기록해 본다.

 

# bin 디렉토리에서 해당 명령어로 Topic 생성

sh kafka-topics.sh --bootstrap-server localhost:9092 \
> --create --replication-factor 1 --partitions 1 --topic test

Created topic test.

# 메시지 기입, 기입 후 ctrl + c 로 빠져나오기가 가능

sh kafka-console-producer.sh --bootstrap-server localhost:9092 --topic test
>Test Message 1
>Test Message 2
^C

# 작성한 메시지 읽기

sh kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test --from-beginning
Test Message 1
Test Message 2
^C
Processed a total of 2 messages
728x90
반응형
Comments