Kafka local 환경 구축
1. https://www.apache.org/dyn/closer.cgi?path=/kafka/0.11.0.0/kafka_2.11-0.11.0.0.tgz 에서 0.11.0 버전 다운로드
2.tar
-xzf kafka_2.11-0.11.0.0.tgz - 압출풀기
3.Kafka 서버 구동
- Kafka 는 주키퍼 서버를 사용하기 때문에 주키퍼 서버를 먼저 시작해야 한다. ( bin
/zookeeper-server-start
.sh config
/zookeeper
.properties )
- Kafka 서버 시작 ( bin
/kafka-server-start
.sh config
/server
.properties
)
4. Topic 생성 <로컬에서 개발할때 해당 IP와 토픽을 주고 개발할 수 있을 것 같다.>
- 'test' 라는 이름의 토픽을 생성한다. ( bin
/kafka-topics
.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic
test
)
- 생성된 토픽을 확인할 수 있다. ( bin
/kafka-topics
.sh --list --zookeeper localhost:2181
)
5. Consumer 동작시키기 <로컬에서 아래 컨슈머를 작동시켜 놓으면 메시지 Publishing이 잘되는지 확인할 수 있을 것 같다.>
- 메시지를 읽어서 Console 에 출력하는 컨슈머를 먼저 작동시킨다. ( bin
/kafka-console-consumer
.sh --bootstrap-server localhost:9092 --topic
test
--from-beginning
)
6. Mutli-broker cluster 세팅. ( 3개의 노드로 )
- 각 서버의 property 파일을 복사한다.
cp
config
/server
.properties config
/server-1
.properties
cp
config
/server
.properties config
/server-2
.properties
- 복사한 각 프로퍼티 파일을 다음과 같이 수정한다.
config/server-1.properties: listeners=PLAINTEXT://:9093 log.dir=/tmp/kafka-logs-1 config/server-2.properties: listeners=PLAINTEXT://:9094 log.dir=/tmp/kafka-logs-2 |
---|
- 위에서 수정한 2노드를 실행한다.
bin
/kafka-server-start
.sh config
/server-1
.properties &
bin
/kafka-server-start
.sh config
/server-2
.properties &
7. 복사본 새로운 토픽하나를 더 생성한다. ( bin
/kafka-topics
.sh --create --zookeeper localhost:2181 --replication-factor 3 --partitions 1 --topic my-replicated-topic
)
8. 위에서 만든 토픽으로 message 를 발행한다 ( bin
/kafka-console-producer
.sh --broker-list localhost:9092 --topic my-replicated-topic
)
- bin
/kafka-console-producer
.sh --broker-list localhost:9092 --topic my-replicated-topic
> my test message 1
> my test message 2
ctrl C
9. 위에서 발행한 토픽을 Consuming 한다 ( bin
/kafka-console-consumer
.sh --bootstrap-server localhost:9092 --from-beginning --topic my-replicated-topic
)
Zookeeper Server Start -> Kafka Server Start -> Publish Server Start -> Consumer Server Start -> send message to Publish Server