公式のquickstartに書かれている通りやります。
https://kafka.apache.org/quickstart
それだけだとあれなので、日本語のメモを残しておきます。
Kafkaを取得する
最新のKafkaリリースをダウンロードして展開します。
$ tar -xzf kafka_2.13-3.2.0.tgz
$ cd kafka_2.13-3.2.0
Zookeeperを起動する
NOTE: ローカルの環境にJava 8以上がインストールされていなければいけません。
以下のコマンドを実行して、Zookeeperサービスを起動します。
# Note: Soon, ZooKeeper will no longer be required by Apache Kafka.
$ bin/zookeeper-server-start.sh config/zookeeper.properties
Kafka brokerを起動する
以下のコマンドを実行して、Kafka brokerサービスを起動します。
$ bin/kafka-server-start.sh config/server.properties
おまけ 2つ目のクラスタを起動する
--- config/zookeeper.properties 2022-05-03 21:52:46.000000000 +0900
+++ config/zookeeper2.properties 2022-05-20 14:16:29.000000000 +0900
@@ -13,9 +13,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.
# the directory where the snapshot is stored.
-dataDir=/tmp/zookeeper
+dataDir=/tmp/zookeeper2
# the port at which the clients will connect
-clientPort=2181
+clientPort=2182
# disable the per-ip limit on the number of connections since this is a non-production config
maxClientCnxns=0
# Disable the adminserver by default to avoid port conflicts.
--- config/server.properties 2022-05-03 21:52:46.000000000 +0900
+++ config/server2.properties 2022-05-20 14:24:06.000000000 +0900
@@ -31,7 +31,7 @@
# listeners = listener_name://host_name:port
# EXAMPLE:
# listeners = PLAINTEXT://your.host.name:9092
-#listeners=PLAINTEXT://:9092
+listeners=PLAINTEXT://:9093
# Listener name, hostname and port the broker will advertise to clients.
# If not set, it uses the value for "listeners".
@@ -59,7 +59,7 @@
############################# Log Basics #############################
# A comma separated list of directories under which to store log files
-log.dirs=/tmp/kafka-logs
+log.dirs=/tmp/kafka-logs2
# The default number of log partitions per topic. More partitions allow greater
# parallelism for consumption, but this will also result in more files across
@@ -122,7 +122,7 @@
# server. e.g. "127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002".
# You can also append an optional chroot string to the urls to specify the
# root directory for all kafka znodes.
-zookeeper.connect=localhost:2181
+zookeeper.connect=localhost:2182
# Timeout in ms for connecting to zookeeper
zookeeper.connection.timeout.ms=18000
# Zookeeper起動
$ bin/zookeeper-server-start.sh config/zookeeper2.properties
# Kafka broker起動
$ bin/kafka-server-start.sh config/server.properties