Skapa och hantera Kafka-kluster

Introduktion till Apache Kafka

Mike Metzger

Data Engineering Consultant

Vad är ZooKeeper?

  • ZooKeeper är ett ramverk för att hantera information och tillhandahålla tjänster för distribuerade system
  • Används främst av utvecklare för att skapa distribuerade applikationer
    • Användare interagerar med ZooKeeper
  • Exempelapplikationer
    • Kafka
    • Hadoop
    • Neo4j

Apache_ZooKeeper_logo.svg.png

Introduktion till Apache Kafka

Vad gör ZooKeeper?

  • ZooKeeper tillhandahåller tjänster för att köra distribuerade applikationer
    • Konfigurationshantering
    • Systemnamngivning
    • Synkronisering mellan system
    • Tjänster för grupper av system
  • Utformat som ett ramverk för att undvika att enskilda distribuerade applikationer implementerar egna versioner av tjänster.
    • Som en gemensam kontakt, till exempel ett eluttag eller en slanganslutning
Introduktion till Apache Kafka

ZooKeeper och Kafka

  • Kafka använder ZooKeeper för klusterhantering
    • Nyare versioner av Kafka kan använda KRaft
  • Två filer används
    • config/zookeeper.properties
    • config/server.properties
# zookeeper.properties

# The directory where the 
# snapshot is stored.
dataDir=/tmp/zookeeper

# The port at which the clients 
# will connect
clientPort=2181

...
Introduktion till Apache Kafka

config/server.properties

  • Hanterar specifik Kafka-konfiguration
    • Brokerinformation
    • Nätverkskonfiguration
    • Lagringsplats för händelser
    • Grundläggande ämneskon­figurationer, inklusive replikering
...
# A comma separated list of directories under which to store log files
log.dirs=/tmp/kafka-logs
# The default number of log partitions per topic.
num.partitions=1
Introduktion till Apache Kafka

Starta ett Kafka-kluster

  • Kafka-kluster startas i två steg
$ bin/zookeeper-server-start.sh config/zookeeper.properties
...
INFO   ______                  _                                           (org.apache.zookeeper.server.ZooKeeperServer)
INFO  |___  /                 | |                                          (org.apache.zookeeper.server.ZooKeeperServer)
INFO     / /    ___     ___   | | __   ___    ___   _ __     ___   _ __    (org.apache.zookeeper.server.ZooKeeperServer)
INFO    / /    / _ \   / _ \  | |/ /  / _ \  / _ \ | '_ \   / _ \ | '__| (org.apache.zookeeper.server.ZooKeeperServer)
INFO   / /__  | (_) | | (_) | |   <  |  __/ |  __/ | |_) | |  __/ | |     (org.apache.zookeeper.server.ZooKeeperServer)
INFO  /_____|  \___/   \___/  |_|\_\  \___|  \___| | .__/   \___| |_| (org.apache.zookeeper.server.ZooKeeperServer)
INFO                                               | |                      (org.apache.zookeeper.server.ZooKeeperServer)
INFO                                               |_|                      (org.apache.zookeeper.server.ZooKeeperServer)
INFO  (org.apache.zookeeper.server.ZooKeeperServer)
...
Introduktion till Apache Kafka

Starta ett Kafka-kluster (forts.)

$ bin/kafka-server-start.sh config/server.properties
INFO Awaiting socket connections on 0.0.0.0:9092. (kafka.network.DataPlaneAcceptor)
INFO Kafka version: 3.7.0 (org.apache.kafka.common.utils.AppInfoParser)
INFO Kafka commitId: 2ae524ed625438c5 (org.apache.kafka.common.utils.AppInfoParser)
INFO Kafka startTimeMs: 1717502877829 (org.apache.kafka.common.utils.AppInfoParser)
INFO [KafkaServer id=0] started (kafka.server.KafkaServer)
INFO [zk-broker-0-to-controller-forwarding-channel-manager]: Recorded new controller, 
     from now on will use node 815f25786085:9092 (id: 0 ra
Introduktion till Apache Kafka

Stoppa ett Kafka-kluster

  • bin/kafka-server-stop.sh
  • bin/zookeeper-server-stop.sh
  • Observera den omvända avstängningsordningen
Introduktion till Apache Kafka

Nu kör vi en övning!

Introduktion till Apache Kafka

Preparing Video For Download...