오늘 공부한 내용
카프카 커맨드 라인 툴
- 커맨드 라인 툴을 통해 카프카 브로커 운영에 필요한 다양한 명령을 내릴 수 있따.
토픽
- 토픽이란 카프카에서 데이터를 구분하는 가장 기본적인 개념.
토픽에는 파티션이 존재하는데, 파티션을 통해 데이터를 처리하는듯 (파티션 갯수는 최소 1개 이상)
토픽생성
kafka-topics.sh를 통해 토픽 관련 명령을 실행할 수 있음.
실습내용
EC2
주키퍼 실행
[ec2-user@ip-172-31-7-55 kafka_2.12-2.5.0]$ sh bin/zookeeper-server-start.sh -daemon config/zookeeper.properties
카프카 서버 실행
[ec2-user@ip-172-31-7-55 kafka_2.12-2.5.0]$ sh bin/kafka-server-start.sh -daemon config/server.properties
실행중인 인스턴스 확인
6658 Jps -m
5829 QuorumPeerMain config/zookeeper.properties
6603 Kafka config/server.properties
LOCAL
토픽 생성
1)hello.kafka 토픽생성
(토픽을 생성할 카프카 클러스터를 구성하는 브로커 3.35.229.118:9092에 hello.kafka란 이름의 토픽 생성)
ubuntu@DESKTOP-0VPC2Q6:~/kafka_2.12-2.5.0$ bin/kafka-topics.sh --create --bootstrap-server 3.35.229.118:9092 --topic hello.kafka
WARNING: Due to limitations in metric names, topics with a period ('.') or underscore ('_') could collide. To avoid issues it is best to use either, but not both.
Created topic hello.kafka.
2)hello.kafka.2 토픽 생성
(파티션3개, 파티션복제갯수 1개[복제하지않는다는뜻], 데이터 유지기간설정 172800000ms는 2일을 뜻함)
ubuntu@DESKTOP-0VPC2Q6:~/kafka_2.12-2.5.0$ ▶bin/kafka-topics.sh --create --bootstrap-server 3.35.229.118:9092 --partitions 3 --replication-factor 1 --config etention.ms=172800000 --topic hello.kafka.2
WARNING: Due to limitations in metric names, topics with a period ('.') or underscore ('_') could collide. To avoid issues it is best to use either, but not both.
Created topic hello.kafka.2.
카프카 리스트 조회
kafka-topics.sh --bootstrap-server ip:port --list
ubuntu@DESKTOP-0VPC2Q6:~/kafka_2.12-2.5.0$ bin/kafka-topics.sh --bootstrap-server 3.35.229.118:9092 --list
hello.kafka
hello.kafka.2
카프카 리스트 상세 조회
--describe 옵션을 통해 상세조회를 할 수 있다.
ubuntu@DESKTOP-0VPC2Q6:~/kafka_2.12-2.5.0$ bin/kafka-topics.sh --bootstrap-server 3.35.229.118:9092 --describe --topic hello.kafka.2
Topic: hello.kafka.2 PartitionCount: 3 ReplicationFactor: 1 Configs: segment.bytes=1073741824,retention.ms=172800000
Topic: hello.kafka.2 Partition: 0 Leader: 0 Replicas: 0 Isr: 0
Topic: hello.kafka.2 Partition: 1 Leader: 0 Replicas: 0 Isr: 0
Topic: hello.kafka.2 Partition: 2 Leader: 0 Replicas: 0 Isr: 0
토픽 수정
kafka-topics.sh 또는 kafka-configs.sh를 이용해서 토픽의 설정을변경할 수 있다.
1) hello.kafka의 파티션 수를 1개->4개로 변경하고 상세조회하기 (kafka-topics.sh 사용)
--topic 토픽이름 --alter --partitions 갯수
(브로커 ip는 계속 사용할 것 같아 hosts에 my-kafka로 추가했다)
ubuntu@DESKTOP-0VPC2Q6:~/kafka_2.12-2.5.0$ bin/kafka-topics.sh --bootstrap-server my-kafka:9092 --topic hello.kafka --alter --partitions 4
ubuntu@DESKTOP-0VPC2Q6:~/kafka_2.12-2.5.0$ bin/kafka-topics.sh --bootstrap-server my-kafka:9092 --topic hello.kafka --describe
Topic: hello.kafka PartitionCount: 4 ReplicationFactor: 1 Configs: segment.bytes=1073741824
Topic: hello.kafka Partition: 0 Leader: 0 Replicas: 0 Isr: 0
Topic: hello.kafka Partition: 1 Leader: 0 Replicas: 0 Isr: 0
Topic: hello.kafka Partition: 2 Leader: 0 Replicas: 0 Isr: 0
Topic: hello.kafka Partition: 3 Leader: 0 Replicas: 0 Isr: 0
2) hello.kafka의 데이터 유지기간을 추가하고 상세조회하기
--entity-type topics --entity-name 토픽이름 --alter --ad-config retention.ms=시간(ms)
ubuntu@DESKTOP-0VPC2Q6:~/kafka_2.12-2.5.0$ bin/kafka-configs.sh --bootstrap-server my-kafka:9092 --entity-type topics --entity-name hello.kafka --alter --add-config retention.ms=86400000
Completed updating config for topic hello.kafka.
ubuntu@DESKTOP-0VPC2Q6:~/kafka_2.12-2.5.0$ bin/kafka-configs.sh --bootstrap-server my-kafka:9092 --entity-type topics --entity-name hello.kafka --describe
Dynamic configs for topic hello.kafka are:
retention.ms=86400000 sensitive=false synonyms={DYNAMIC_TOPIC_CONFIG:retention.ms=86400000}
반응형