본문 바로가기

시스템/Kafka

[Kafka] 구축 해보기[2] - topic 관련 명령어

반응형

공통


경로 : /usr/local/kafka/bin

  • <broker-ip> : 172.16.10.151:9092,172.16.10.152:9092,172.16.10.153:9092

 

 

 

Topic 생성 하기


 

./kafka-topics.sh --create --replication-factor 1 --partitions 3 --topic test2 --bootstrap-server <broker-ip>

 

 

 

 

Topic list 확인하기


./kafka-topics.sh --list --bootstrap-server <broker-ip>

 

 

 

 

Topic 상세 정보 확인하기


./kafka-topics.sh --describe --topic test2 --bootstrap-server <broker-ip>
Topic: test2	TopicId: gwqIMFK8RoORfnaNYW4VCw	PartitionCount: 3	ReplicationFactor: 1	Configs: segment.bytes=1073741824
	Topic: test2	Partition: 0	Leader: 3	Replicas: 3	Isr: 3
	Topic: test2	Partition: 1	Leader: 1	Replicas: 1	Isr: 1
	Topic: test2	Partition: 2	Leader: 2	Replicas: 2	Isr: 2

 

 

 

 

 

Topic partition 개수 수정하기


./kafka-topics.sh --alter --topic test2 --partitions 5 --bootstrap-server <broker-ip>

 

 

 

 

Topic Replica 개수 수정하기


  • partition 0번의 replication factor 1 -> 3 으로 수정

rf.json 파일 생성

{
   "version": 1,
   "partitions": [
           {"topic":"test2", "partition": 0, "replicas":[1,2,3]}
    ]
}

 

./kafka-reassign-partitions.sh --reassignment-json-file rf.json --execute --bootstrap-server <broker-ip>
Current partition replica assignment

{"version":1,"partitions":[{"topic":"test2","partition":0,"replicas":[3],"log_dirs":["any"]}]}

Save this to use as the --reassignment-json-file option during rollback
Successfully started partition reassignment for test2-0

 

 

 

 

Topic 삭제하기


./kafka-topics.sh --delete --topic test2 --bootstrap-server <broker-ip>

 

 

 

 

 

Producer 테스트 해보기


./kafka-console-producer.sh --topic test2 --bootstrap-server <broker-ip>

 

 

 

 

Consumer 테스트 해보기


./kafka-console-consumer.sh --topic test2 --from-beginning  --bootstrap-server <broker-ip>

 

반응형