티스토리 뷰

반응형

 

다운로드 및 설치

Wget 으로 다운로드 및 설치 하는 방법과 Homebrew를 통한 설치 방법이 존재합니다.

 

wget

wget https://downloads.apache.org/kafka/3.5.0/kafka_2.12-3.5.0.tgz
tar -xzf kafka_2.12-3.5.0.tgz

homebrew

brew install zookeeper
# brew install kafka 를 진행하면 kafka와 관련된 zookeeper , jdk 등 모두 다운로드를 진행된다. 
brew install kafka

설치 방법은 위와 같이 진행하면되고, 기존에는 wget 파일을 설치하였지만, 이번에는 brew install 을 통해서 설치를 진행해 보겠습니다.

 

 

brew install kafka 만 설치하여도 zookeeper 및 kafka 실행에 필요한 openjdk 까지 설치가 됩니다.

그로인해 brew install zookeeper를 따로 진행하지 않아도 모든 실행 구성요소들이 설치됩니다.

 

 

시작하기

설치 완료시 시작 방법

 

!! 설치후 아래 명령어로 실행하게 된다면 기본적으로 local환경에서의 kafka 및 zookeeper의 사용 port는 2181, 9092를 사용합니다.

zookeeper -> *:2181
kafka -> *:9092

하지만 실행하고 port를 확인해본다면 zooekeeper의 같은 pid에서 2181, 8080을 사용하는걸 볼 수 있습니다.

 

zookeeper에서 사용되는 8080 port는

AdminServer는 네 글자로 된 단어 명령에 HTTP 인터페이스를 제공하는 임베디드 제티 서버입니다. 

이로인해 adminServer Port를 다른 Port로 변경해주시면 좋습니다. 개발단계에서 보통 우리가 실행되는 appliction이 8080으로 시작되다보니, 다른 개발 어플리케이션을 실행시

 

아래와 같은 메세지를 볼수 있습니다.

Web server failed to start. Port 8080 was already in use. 

이를 방지하기 위해 zookeeper 의 설정에서 adminServer port를 변경해줘야합니다.

 

vi /opt/homebrew/etc/zookeeper/zoo.cfg

## Metrics Providers
#
# https://prometheus.io Metrics Exporter
#metricsProvider.className=org.apache.zookeeper.metrics.prometheus.PrometheusMetricsProvider
#metricsProvider.httpHost=0.0.0.0
#metricsProvider.httpPort=7000
#metricsProvider.exportJvmInfo=true

# 8080 -> 9090 port change
admin.serverPort=9090

 

변경후 zookeeper를 실행하게되면 아래와 같이 확인 할 수있고, 다른 어플리케이션에 영향없이 사용이 가능합니다.

만약 9090 port와 충돌이 일어난다면 다시 수정해서 실행하면됩니다.

변경된 zookeeper adminServer Port 9090

 

 

## brew 를 통한 실행방법
brew services start zookeeper
brew services start kafka

## brew 를통한 중지
brew services stop kafka
brew services stop zookeeper

## Root 폴더에서 실행 /opt/homebrew/opt/ 
/opt/homebrew/opt/kafka/bin/zookeeper-server-start /opt/homebrew/etc/kafka/zookeeper.properties
/opt/homebrew/opt/kafka/bin/kafka-server-start /opt/homebrew/etc/kafka/server.properties

2가지의 명령어로 kafka 를 실행 할 수 있습니다. 아래는 brew services start 를 통해 zookeeper와 kafka를 실행하고 brew services list 를 통해 정상적으로 started 된 상태를 캡처한 사진 입니다.

 

brew services start zookeeper , brew services start kafka Command

brew services list 를 통해 status가 모두 started 상태라면 정상적으로 kafka 가 실행된 상태입니다.

 

기존 command로 실행 할때는 terminal을 여러개 띄워 작업해야 했지만, brew services start의 장점은 백그라운드에 항목이 추가되어

cosumer 및 producer 창만 띄워 테스트가 가능하니 더 편한 부분 인것 같습니다.

 

백그라운드 등록 알림

 

 

 

 

Topic 생성

 

!!! Topic이 생성되지 않는경우 

zookeeper , kafka 실행후 kafka-topics 를통해 topic 을 create 하거나, list를 조회시 응답이 없는경우가 발생된다.

topic을 생성하였지만 응답이 없음.

위와 같은 상황이 발생되면 아래와 같이 /otp/homebrew/etc/kafka/server.properties 에서 Socket Server Settings의 

listeners=PLAINTEXT://:9092 주석된 부분을 해제 변경된 값을 저장한다.

## kafka 종료
brew services stop kafka

## kafka server.propreties 설정 수정 필요
vi /otp/homebrew/etc/kafka/server.properties


############################# Socket Server Settings #############################

# The address the socket server listens on. If not configured, the host name will be equal to the value of
# java.net.InetAddress.getCanonicalHostName(), with PLAINTEXT listener name, and port 9092.
#   FORMAT:
#     listeners = listener_name://host_name:port
#   EXAMPLE:
#     listeners = PLAINTEXT://your.host.name:9092
listeners=PLAINTEXT://:9092 ## 주석해제

 

 

 

hello-world topic 생성

cd /opt/homebrew/opt/kafka

bin/kafka-topics --create --topic hello-world --bootstrap-server localhost:9092 --partitions 1
bin/kafka-topics --bootstrap-server localhost:9092 --list

 

Topic 생성
Topic 생성후 list 확인

 

Topic Producer(메세지 전송) 및 Consumer 확인

메세지를 주고 받기 위해서는 두개의 Terminal을 통해서 확인이 가능합니다.

 

cd /opt/homebrew/opt/kafka

# Producer 실행
bin/kafka-console-producer --bootstrap-server localhost:9092 --topic hello-world


# Consumer 실행
bin/kafka-console-consumer --bootstrap-server localhost:9092 --topic hello-world

Producer / Consumer 내용 전달 및 확인

 

이로써 Homebrew 를 통한 kafka 설치 및 기본 동작들을 확인해 보았습니다.

 

다음에는 Kafka에서 주로 사용되는 command 들을 정리하여 공유 하겠습니다.

 

감사합니다  __)

 

 

Reference.

https://medium.com/@Ankitthakur/apache-kafka-installation-on-mac-using-homebrew-a367cdefd273

https://kafka.apache.org

https://zookeeper.apache.org/doc/r3.5.1-alpha/zookeeperAdmin.html#sc_adminserver_confighttps://stackoverflow.com/questions/59943241/zookeeper-admin-server-port

반응형
댓글
반응형
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함