λ‘컬μ λ€μ΄λ°μ μΉ΄νμΉ΄ ν΄λμμ yml νμΌ νΈμ§
version: '2.1'
services:
zoo1:
image: confluentinc/cp-zookeeper:latest
hostname: zoo1
container_name: zoo1
ports:
- "2182:2181"
environment:
ZOOKEEPER_CLIENT_PORT: 2181
ZOOKEEPER_SERVER_ID: 1
ZOOKEEPER_SERVERS: zoo1:2888:3888
kafka1:
image: confluentinc/cp-kafka:latest
hostname: kafka1
container_name: kafka1
ports:
- "9093:9093"
- "29093:29093"
environment:
KAFKA_ADVERTISED_LISTENERS: INTERNAL://kafka1:19093,EXTERNAL://localhost:9093,DOCKER://host.docker.internal:29093
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: INTERNAL:PLAINTEXT,EXTERNAL:PLAINTEXT,DOCKER:PLAINTEXT
KAFKA_INTER_BROKER_LISTENER_NAME: INTERNAL
KAFKA_ZOOKEEPER_CONNECT: "zoo1:2181"
KAFKA_BROKER_ID: 1
KAFKA_LOG4J_LOGGERS: "kafka.controller=INFO,kafka.producer.async.DefaultEventHandler=INFO,state.change.logger=INFO"
KAFKA_AUTHORIZER_CLASS_NAME: kafka.security.authorizer.AclAuthorizer
KAFKA_ALLOW_EVERYONE_IF_NO_ACL_FOUND: "true"
depends_on:
- zoo1
kafka2:
image: confluentinc/cp-kafka:latest
hostname: kafka2
container_name: kafka2
ports:
- "9094:9094"
- "29094:29094"
environment:
KAFKA_ADVERTISED_LISTENERS: INTERNAL://kafka2:19094,EXTERNAL://localhost:9094,DOCKER://host.docker.internal:29094
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: INTERNAL:PLAINTEXT,EXTERNAL:PLAINTEXT,DOCKER:PLAINTEXT
KAFKA_INTER_BROKER_LISTENER_NAME: INTERNAL
KAFKA_ZOOKEEPER_CONNECT: "zoo1:2181"
KAFKA_BROKER_ID: 2
KAFKA_LOG4J_LOGGERS: "kafka.controller=INFO,kafka.producer.async.DefaultEventHandler=INFO,state.change.logger=INFO"
KAFKA_AUTHORIZER_CLASS_NAME: kafka.security.authorizer.AclAuthorizer
KAFKA_ALLOW_EVERYONE_IF_NO_ACL_FOUND: "true"
depends_on:
- zoo1
kafka3:
image: confluentinc/cp-kafka:latest
hostname: kafka3
container_name: kafka3
ports:
- "9095:9095"
- "29095:29095"
environment:
KAFKA_ADVERTISED_LISTENERS: INTERNAL://kafka3:19095,EXTERNAL://localhost:9095,DOCKER://host.docker.internal:29095
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: INTERNAL:PLAINTEXT,EXTERNAL:PLAINTEXT,DOCKER:PLAINTEXT
KAFKA_INTER_BROKER_LISTENER_NAME: INTERNAL
KAFKA_ZOOKEEPER_CONNECT: "zoo1:2181"
KAFKA_BROKER_ID: 3
KAFKA_LOG4J_LOGGERS: "kafka.controller=INFO,kafka.producer.async.DefaultEventHandler=INFO,state.change.logger=INFO"
KAFKA_AUTHORIZER_CLASS_NAME: kafka.security.authorizer.AclAuthorizer
KAFKA_ALLOW_EVERYONE_IF_NO_ACL_FOUND: "true"
depends_on:
- zoo1
λ‘컬 2182 ν¬νΈλ‘ μ£Όν€νΌ μ μ (λ΄λΆμ μΌλ‘ 2181)
μΉ΄νμΉ΄ 1 : 9093 ν¬νΈ
μΉ΄νμΉ΄ 2 : 9094 ν¬νΈ
μΉ΄νμΉ΄ 3 : 9095 ν¬νΈ
ports:
- "9095:9095"
- "29095:29095"
9095:9095: μ΄ λΆλΆμ νΈμ€νΈμ 9095 ν¬νΈλ₯Ό 컨ν μ΄λμ 9095 ν¬νΈλ‘ 맀ν
-> νΈμ€νΈμμ Kafka λΈλ‘컀μ μ μν λ 9095 ν¬νΈλ₯Ό μ¬μ©νλ€λ μλ―Έ
29095:29095: Docker λ΄λΆ λ€νΈμν¬μμμ ν¬νΈ 맀νμ μ μ
-> 컨ν μ΄λ λ΄λΆμμ Kafka λΈλ‘컀μ μ μν λ μ¬μ©ν ν¬νΈ μ§μ .
컨ν μ΄λ λ΄λΆμμ 29095 ν¬νΈλ₯Ό μ¬μ©νμ¬ Kafka λΈλ‘컀μ μ μν μ μμ.
$docker-compose -f docker-compose.yml up -d # ymlμ ν¬ν¨λ 컨ν
μ΄λλ€ μ¬λ¦¬λ λͺ
λ Ήμ΄
$docker ps # docker ps λͺ
λ Ήμ΄λ‘ μ λμκ°λ νμΈ
# λ‘컬 μΉ΄νμΉ΄ ν΄λλ΄μμ
./bin/kafka-topics.sh --create \
--replication-factor 3 \
--partitions 3 \
--topic app-push-topic \
--bootstrap-server localhost:9093,localhost:9094,localhost:9095
# ν ν½ μμΈ μ‘°ν
./bin/kafka-topics.sh --describe \
--topic app-push-topic \
--bootstrap-server localhost:9093,localhost:9094,localhost:9095
#κ²°κ³Ό
Topic: app-push-topic TopicId: C__MUpdpTv-Ej1s8Empw8A PartitionCount: 3 ReplicationFactor: 3 Configs:
Topic: app-push-topic Partition: 0 Leader: 1 Replicas: 1,2,3 Isr: 2,3,1
Topic: app-push-topic Partition: 1 Leader: 2 Replicas: 2,3,1 Isr: 2,3,1
Topic: app-push-topic Partition: 2 Leader: 3 Replicas: 3,1,2 Isr: 3,2,1
πΒ μΈ-μν¬λ?
Kafkaμμ κ° νν°μ μ μ¬λ¬ κ°μ 볡μ λ³Έμ κ°μ§ μ μμ, μ΄ μ€μμ νλλ 리λμ΄λ©°, λλ¨Έμ§λ νλ‘μ 볡μ λ³Έ. 리λ νν°μ μ λ©μμ§λ₯Ό μ°κ³ μλΉνλ μν μ μννλ©°, νλ‘μ 볡μ λ³Έλ€μ 리λμ λκΈ°νλμ΄ μμ΄ λ¦¬λμ μ₯μ κ° λ°μνμ λ λ체 κ°λ₯.
β μΈ-μν¬λ νμ¬ λ©μμ§λ₯Ό λ°λΌκ°λ λκΈ°νλ μνμ μλ 볡μ λ³Έλ€μ λνλ. μ¦, μΈ-μν¬μ μν 볡μ λ³Έλ€μ 리λμ λμΌν λ©μμ§λ₯Ό κ°μ§κ³ μμΌλ©°, λ°μ΄ν°μ μΌκ΄μ±μ 보μ₯νλκ²
β λ§μ½ 리λ νν°μ μμ λ©μμ§λ₯Ό μ‘μ νκ³ μλλ° νλ‘μ μ€ νλκ° λκΈ°νλμ§ λͺ»ν μνλΌλ©΄ ν΄λΉ 볡μ λ³Έμ μΈ-μν¬μμ μ μΈλ¨.
# consumer jar νμΌ μλ λλ ν 리μμ
java -jar consumer-2.3.0.RELEASE.jar
# producer jar νμΌ μλ λλ ν 리μμ
java -jar producer-2.3.0.RELEASE.jar
λΆμ°μ²λ¦¬ νμΈμλ£
# 컨μλ¨Έ κ·Έλ£Ή 리μ€νΈ μ‘°ν
./bin/kafka-consumer-groups.sh --list \
--bootstrap-server localhost:9093,localhost:9094,localhost:9095
app-push-group
# 컨μλ¨Έ κ·Έλ£Ή μμΈμ‘°ν
./bin/kafka-consumer-groups.sh --describe \
--group app-push-group \
--bootstrap-server localhost:9093,localhost:9094,localhost:9095
GROUP TOPIC PARTITION CURRENT-OFFSET LOG-END-OFFSET LAG CONSUMER-ID HOST CLIENT-ID
app-push-group app-push-topic 0 264 264 0 consumer-app-push-group-1-a9d6852b-1f81-400b-8337-6466a1f0aab2 /192.168.65.1 consumer-app-push-group-1
app-push-group app-push-topic 2 248 248 0 consumer-app-push-group-1-dc22572f-eddf-4ed2-8299-d6da8db4edfa /192.168.65.1 consumer-app-push-group-1
app-push-group app-push-topic 1 270 270 0 consumer-app-push-group-1-c17f0f35-d5a2-48d4-8952-9c9f9cc820fd /192.168.65.1 consumer-app-push-group-1