Partition 추가
partition 목록 확인
bin/kafka-topics.sh --list --bootstrap-server localhost:9092
해당 topic의 partition 상태 확인
bin/kafka-topics.sh --describe --topic <topic-name> --bootstrap-server localhost:9092
partition 증가
bin/kafka-topics.sh --alter --topic <topic-name> --partitions 4 --bootstrap-server localhost:9092
운영중인 Kafka Topic 이라면 매우 신중하게 결정해야함
Broker 추가
신규 Broker 의 server3.properties 파일 수정
broker.id=3
listeners=PLAINTEXT://localhost:9095
log.dirs=/tmp/kafka-logs3
신규 Broker 실행
bin/kafka-server-start.sh config/server3.properties &
broker가 새로 추가되어도 기존 broker의 partition들이 새로운 broker로 자동으로 분산 재배치되진 않아서, 운영자가 수동으로 재배치해줘야 한다.
Partition 재배치를 할 Topic 에 대한 json 파일 생성 ex) reassign-topic.json 파일 작성
vi reassign-topic.json
—--------------------------------------------------------------------------
{"topics":[{"topic": "topic5"}],"version":1}
위에서 생성한 reassign-topic.json 파일을 이용하여 최종 Target 구성 json 구조 확인
bin/**kafka-reassign-partitions.sh** **--generate** --topics-to-move-json-file reassign-topics.json --broker-list "1,2,3" --bootstrap-server localhost:9092
추가된 Broker 를 고려해서 균등한 재배치 제안 json 데이터가 생성됨. Proposed~~ 파일을
Current partition replica assignment
{"version":1,"partitions":[{"topic":"topic5","partition":0,"replicas":[0],
"log_dirs":["any"]},{"topic":"topic5","partition":1,"replicas":[0],
"log_dirs":["any"]},{"topic":"topic5","partition":2,"replicas":[0],
"log_dirs":["any"]},{"topic":"topic5","partition":3,"replicas":[3],
"log_dirs":["any"]}]}
Proposed partition reassignment configuration
{"version":1,"partitions":[{"topic":"topic5","partition":0,"replicas":[2],
"log_dirs":["any"]},{"topic":"topic5","partition":1,"replicas":[3],
"log_dirs":["any"]},{"topic":"topic5","partition":2,"replicas":[1],
"log_dirs":["any"]},{"topic":"topic5","partition":3,"replicas":[2],
"log_dirs":["any"]}]}
현재 구조는 하나의 broker에 partition이 몰려 있는데, 제안된 구조에서는 고르게 분포되어 있음
Partition 재배치 실행
bin/**kafka-reassign-partitions.sh** **--execute** --reassignment-json-file new_partition.json --bootstrap-server localhost:9092
Topic 의 Partition 재배치 상태 확인
bin/kafka-topics.sh --describe --topic topic5 --bootstrap-server localhost:9092
Topic: topic5 TopicId: V3BjGO7YS8KIe5xuSyGIdg PartitionCount: 4
ReplicationFactor: 1 Configs: segment.bytes=1073741824
Topic: topic5 Partition: 0 Leader: 2 Replicas: 2 Isr: 2
Topic: topic5 Partition: 1 Leader: 3 Replicas: 3 Isr: 3
Topic: topic5 Partition: 2 Leader: 1 Replicas: 1 Isr: 1
Topic: topic5 Partition: 3 Leader: 2 Replicas: 2 Isr: 2
운영중인 Kafka Cluster 라면