핵심부터 말할게.
Kafka에서 기존 토픽의
--replication-factor는 직접 변경 ❌
대신 “파티션 reassignment(재할당)”으로 복제본 수를 늘리거나 줄인다 ⭕토픽 삭제 → 같은 이름으로 재생성은 가능하지만 데이터는 전부 날아감.
아래를 보면 “정석 루트”랑 “테스트용 지름길”이 딱 구분될 거야.
--replication-factor를 바로 못 바꾸나?bin/kafka-topics.sh \
--bootstrap-server localhost:9192 \
--describe \
--topic test
reassign.json 예시:
{
"version": 1,
"partitions": [
{ "topic": "test", "partition": 0, "replicas": [1,2,3] },
{ "topic": "test", "partition": 1, "replicas": [2,3,1] },
{ "topic": "test", "partition": 2, "replicas": [3,1,2] }
]
}
⚠️ 주의
replicas 길이 = 원하는 replication factornode.id 기준bin/kafka-reassign-partitions.sh \
--bootstrap-server localhost:9092,localhost:9093,localhost:9094 \
--reassignment-json-file reassign.json \
--execute
bin/kafka-reassign-partitions.sh \
--bootstrap-server localhost:9092,localhost:9093,localhost:9094 \
--reassignment-json-file reassign.json \
--verify
bin/kafka-topics.sh \
--bootstrap-server localhost:9092,localhost:9093,localhost:9094 \
--describe \
--topic test
Replicas / Isr 가 3개로 나오면 성공.
(환경에 따라 지원)
bin/kafka-reassign-partitions.sh \
--bootstrap-server localhost:9092,localhost:9093,localhost:9094 \
--generate \
--topics-to-move-json-file topics.json \
--broker-list "1,2,3"
topics.json:
{ "topics": [{ "topic": "test" }], "version": 1 }
delete.topic.enable=truebin/kafka-topics.sh \
--bootstrap-server localhost:9092,localhost:9093,localhost:9094 \
--delete \
--topic test
(완전 삭제까지 수 초~수십 초 걸릴 수 있음)
bin/kafka-topics.sh \
--bootstrap-server localhost:9092,localhost:9093,localhost:9094 \
--create \
--topic test \
--partitions 3 \
--replication-factor 3
| 상황 | 추천 |
|---|---|
| 실서비스 / 데이터 유지 | ✅ reassignment |
| 로컬 테스트 / 실험 | ⚠️ 삭제 후 재생성 |
| RF 줄이기 | reassignment (주의) |
| 컨트롤러/브로커 실습 | reassignment 경험 꼭 해볼 것 |
원하면 네 현재 test 토픽 --describe 출력 그대로 붙여줘.
브로커 id 기준으로 딱 맞는 reassignment JSON 바로 만들어줄게.