kafka 동작에 필요한 명령어


  1. 토픽 관련

    • 토픽 리스팅
        $ ./bin/kafka-topics.sh --zookeeper localhost:2181 --list
      
    • 토픽 생성
        $ ./bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 3 --partitions 10 --topic test
      
    • 토픽 삭제
        $ ./bin/kafka-topics.sh --zookeeper localhost:2181 --delete --topic test
      
    • 토픽 재분배
      • partition 이 클수록 토픽 처리가 좋다?
        • 파티션이 클수록 throughput 이 증가한다
        • 그러나 Open File Handles, Unavailability 도 함께 증가한다
      • partition - replica 계수의 관계
        • 더 나은 로드 밸런싱을 위해, replica 이상의 partition 을 유지해야 한다
        • 복제 매커니즘
          • 브로커 목록과 파티션 목록을 정렬한다.
          • n 개의 브로커가 있는 경우 i 번째 파티션을 (i mod n) 번째 브로커에 할당한다.
          • 이 파티션의 첫 번째 복제본이 할당 된 브로커에 상주하며이 파티션의 기본 복제본(leader)이라고힌다.
          • 브로커가 다운되면 부하가 하나의 브로커가 아닌 모든 살아남은 브로커에게 균등하게 분산되도록 다른 복제본을 배치하려고 한다.
          • 이를 달성하기 위해 브로커 i에 m 개의 파티션이 할당되어 있다고 가정합니다.
          • 파티션 k의 j 번째 복제본은 브로커 (i + j + k) mod n에 할당됩니다.
          • Zookeeper에 ach 파티션에 대한 복제본 할당에 대한 정보를 저장합니다.
      • 명령어
        $ ./bin/kafka-reassign-partitions.sh --zookeeper localhost:2181 --execute --reassignment-json-file b.json
        $ cat b.json
          {
              "version": 1,
              "partitions": [{
                  "topic": "sample-topic",
                  "partition": 1,
                  "replicas": [1,2,3]
              },
              {
                  "topic": "sample-topic",
                  "partition": 2,
                  "replicas": [2,3,4]
              },
              {
                  "topic": "sample-topic",
                  "partition": 3,
                  "replicas": [3,4,5]
              },
              {
                  "topic": "sample-topic",
                  "partition": 4,
                  "replicas": [4,5,1]
              },
              {
                  "topic": "sample-topic",
                  "partition": 5,
                  "replicas": [5,1,2]
              }]
          }
        
    • 파티션 변경
        $ ./bin/kafka-topics.sh --alter --partitions 10 --topic {토픽명} --zookeeper localhost:2181
      
  2. 복제 관련 상태를 확인하기

    • “isr” is the set of “in-sync” replicas
    • isr 복제현황
        $ ./bin/kafka-topics.sh --describe --zookeeper localhost:2181
        Topic:__consumer_offsets        PartitionCount:200      ReplicationFactor:3     Configs:segment.bytes=104857600,cleanup.policy=compact
        Topic: __consumer_offsets       Partition: 0    Leader: 4       Replicas: 4,5,1 Isr: 1,5,4
        Topic: __consumer_offsets       Partition: 1    Leader: 5       Replicas: 5,1,2 Isr: 1,2,5
        Topic: __consumer_offsets       Partition: 2    Leader: 1       Replicas: 1,2,3 Isr: 1,2,3
        Topic: __consumer_offsets       Partition: 3    Leader: 2       Replicas: 2,3,4 Isr: 2,3,4
        Topic: __consumer_offsets       Partition: 4    Leader: 3       Replicas: 3,4,5 Isr: 5,4,3
        Topic: __consumer_offsets       Partition: 5    Leader: 4       Replicas: 4,1,2 Isr: 1,4,2
        Topic: __consumer_offsets       Partition: 6    Leader: 5       Replicas: 5,2,3 Isr: 2,5,3
      
    • 강제 리더 선정
        $ ./bin/kafka-preferred-replica-election.sh --zookeeper localhost:2181
      
  3. consumer 처리 확인

    • consumer group 별 처리량 확인(deprecated 명령어 0.8 대에만 사용가능):

            $ ./bin/kafka-consumer-offset-checker.sh --zookeeper localhost:2181 --group group_name
        Group           Topic                          Pid Offset          logSize         Lag             Owner
        group_name      test_topic                      0   28696375242     28710228588     13853346        group_name_consumer001-1494565379967-138e5755-0
        group_name      test_topic                      1   32507090475     32525260714     18170239        group_name_consumer001-1494565379967-427a12a1-0
        group_name      test_topic                      2   22142323        37202882        15060559        group_name_consumer001-1494565379967-6017c0a1-0
        group_name      test_topic                      3   29872001299     29887377264     15375965        group_name_consumer001-1494565379967-be0b8719-0
        group_name      test_topic                      4   28412645478     28426057279     13411801        group_name_consumer002-1494565379967-fc2942ba-0
        group_name      test_topic                      5   28165720144     28178485586     12765442        group_name_consumer00-1494565918010-3f468782-0
      
        # Offset: 처리된
        # Lag: 남은
        # logSize: total size = Offset + Lag
      
        ex) 토픽 유입량 대비 처리정도를 판단하고 싶을 때
            $ ./bin/kafka-consumer-offset-checker.sh --zookeeper localhost:2181 --group group_name  | grep -v "Group" | awk '{ topic=$2; topicLogSize[topic]+=$5; topicOffSetSum[topic]+=$4}END{for(x in topicLogSize) print x": "topicOffSetSum[x]/topicLogSize[x]*100}'


'BigData > Kafka' 카테고리의 다른 글

kafka 모니터링 도구  (0) 2017.03.16
Kafka Multi Cluster broker 구성하기  (0) 2017.02.22
Kafka 소개  (0) 2017.02.16
Posted by 감각적신사
,