[kafka](Window환경) kafka Cluster 설치 및 실행

 

1. 전체적인 흐름

   : 클러스터 1대 , 주키퍼서버 1대 , broker 서버 3개 실행

 

2. Broker 생성 ( 3가지 )

 

Broker#0 - server.properties

broker.id=0
listeners=PLAINTEXT://localhost:9092
log.dirs/tmp/kafka-logs

Broker#1 - server1.properties

broker.id=1
listeners=PLAINTEXT://localhost:9093
log.dirs/tmp/kafka-logs1

Broker#2 - server2.properties

broker.id=2
listeners=PLAINTEXT://localhost:9094
log.dirs/tmp/kafka-logs2

 

 

3. conf/server.properties 파일 열어서

    server.port 번호 변경해주기

# The id of the broker. This must be set to a unique integer for each broker.
broker.id=0

############################# 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://localhost:9092

# Listener name, hostname and port the broker will advertise to clients.
# If not set, it uses the value for "listeners".
#advertised.listeners=PLAINTEXT://your.host.name:9092

 

그리고 0,1,2 서버를 생성해주고 

 

위의 0,1,2 서버 파일을 실행해준다.

.\bin\windows\zookeeper-server-start.bat .\config\zookeeper.properties

 .\bin\windows\kafka-server-start.bat .\config\server.properties

 .\bin\windows\kafka-server-start.bat .\config\server1.properties

 .\bin\windows\kafka-server-start.bat .\config\server2.properties

 

 

실행명령어

.\bin\windows\zookeeper-server-start.bat .\config\zookeeper.properties

 .\bin\windows\kafka-server-start.bat .\config\server.properties

 .\bin\windows\kafka-server-start.bat .\config\server1.properties

 .\bin\windows\kafka-server-start.bat .\config\server2.properties



(생성)
.\bin\windows\kafka-topics.bat --create --topic topic2 --bootstrap-server=localhost:9092 --partitions 3 --replication-factor 2
                                           (생성할토픽이름)              (사용할 포트번호 ) (3개의브로크)     (원본의 토픽을 복사) 

(구독확인)
.\bin\windows\kafka-topics.bat --describe --topic topic2 --bootstrap-server=localhost:9092
                                 (확인)               (생성할토픽이름)                             ( 사용할 포트번호 )


(토픽에 메시지발행)

.\bin\windows\kafka-console-producer.bat --topic topic2 --bootstrap-server=localhost:9092,localhost:9093,localhost:9094


.\bin\windows\kafka-console-consumer.bat --topic topic2 --from-beginning --bootstrap-server=localhost:9092,localhost:9093,localhost:9094
( ==> --from-beginning 첫번째 수신된 메시지 받겠다 이거 안스면 consumer 접속이후에 온메시지만 받음)