Apache Kafka は、1 日に何兆ものイベントを処理できる強力な分散型イベント ストリーミング プラットフォームです。もともと LinkedIn によって開発され、2011 年初めにオープンソース化された Kafka は、多くの最新のデータ アーキテクチャの中心的なバックボーンに進化しました。このガイドでは、Apache Kafka のアーキテクチャの理解からセットアップ、基本操作の実行まで、Apache Kafka を使い始めるために必要なすべてのことを説明します。
Apache Kafka は、リアルタイムのデータ フィードを処理するように設計されています。データ ストリームを処理するための高スループット、低遅延のプラットフォームとして機能します。 Kafka は、リアルタイム ストリーミング データ パイプラインとデータ ストリームに適応するアプリケーションを構築するためによく使用されます。一般的なユースケースには、ログ集約、リアルタイム分析、ストリーム処理などがあります。
セットアップと操作に入る前に、Kafka のいくつかの重要な概念と用語を理解することが重要です。
前提条件
リーリーJava がインストールされていない場合は、Oracle Web サイトからダウンロードしてインストールするか、Debian ベースのシステムの場合は apt 、macOS の場合は brew などのパッケージ マネージャーを使用できます。
リーリー
Kafka をダウンロードしてインストールする
リーリー
リーリー
リーリーZooKeeper はデフォルトのポート 2181 で起動する必要があります。ZooKeeper が起動して実行中であることを示すログ メッセージが表示されるはずです。
リーリーKafka はデフォルトのポート 9092 で起動する必要があります。Kafka ブローカーが起動して実行中であることを示すログ メッセージが表示されるはずです。
カフカの構成
server.properties
: このファイルには、ブローカー ID、ログ ディレクトリ、リスナーなどの Kafka ブローカーの構成が含まれています。: /etc/systemd/system/ ディレクトリにzookeeper.service という名前のファイルを作成します:
Kafka サービス ファイル
: /etc/systemd/system/ ディレクトリに kafka.service という名前のファイルを作成します:
[Unit] Description=Apache Kafka After=zookeeper.service [Service] Type=simple ExecStart=/path/to/kafka/bin/kafka-server-start.sh /path/to/kafka/config/server.properties ExecStop=/path/to/kafka/bin/kafka-server-stop.sh Restart=on-abnormal [Install] WantedBy=multi-user.target
Enable and Start Services: Enable and start the services using systemctl:
sudo systemctl enable zookeeper sudo systemctl start zookeeper sudo systemctl enable kafka sudo systemctl start kafka
You can now manage ZooKeeper and Kafka using standard systemctl commands (start, stop, status, restart).
To verify that your Kafka setup is working correctly, you can perform some basic operations such as creating a topic, producing messages, and consuming messages.
Creating a Topic:
bin/kafka-topics.sh --create --topic test-topic --bootstrap-server localhost:9092 --partitions 1 --replication-factor 1
You should see a confirmation message indicating that the topic has been created successfully.
Producing Messages:
bin/kafka-console-producer.sh --topic test-topic --bootstrap-server localhost:9092
Type a few messages in the console and press Enter after each message.
Consuming Messages:
Open a new terminal window and run:
bin/kafka-console-consumer.sh --topic test-topic --from-beginning --bootstrap-server localhost:9092
You should see the messages you produced in the previous step.
By following these steps, you should have a fully functional Apache Kafka environment set up on your system. This setup forms the foundation for developing and deploying real-time data streaming applications using Kafka.
Getting started with Apache Kafka can seem daunting, but with the right guidance, you can quickly get up to speed. This guide provided a comprehensive introduction to Kafka, from installation to basic operations and building simple producers and consumers. As you continue to explore Kafka, you will uncover its full potential for building robust, real-time data pipelines.
By following this guide, you’ve taken the first steps in mastering Apache Kafka. Happy streaming!
以上がApache Kafka の入門の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。