Kafka安装使用指南

Kafka是一种高吞吐量的分布式发布订阅消息系统。
Kafka启动方式有Zookeeper和Kraft,两种方式只能选择其中一种启动,不能同时使用。

【Kafka安装】
Kafka下载 https://downloads.apache.org/kafka/3.7.1/kafka_2.13-3.7.1.tgz
Kafka解压 tar -xzf kafka_2.13-3.7.1.tgz

【Kafka启动】
启动Kafka本地环境需Java 8+以上, (yum安装Java,sudo yum install java-1.8.0-openjdk)
Kafka依赖Zookeeper,本文使用kafka自带Zookeeper进行启动。

1、启动Zookeeper 
nohup ./zookeeper-server-start.sh ../config/zookeeper.properties &
(停止命令:./zookeeper-server-stop.sh ../config/zookeeper.properties )

2、启动Kafka
nohup ./kafka-server-start.sh ../config/server.properties &
(停止命令:./kafka-server-stop.sh ../config/server.properties )

3、查看端口启动
netstat -tpln


Zookeeper默认启动2181端口,可修改配置文件config/zookeeper.properties。

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

同时修改配置文件config/server.properties。
############################# Zookeeper #############################

# Zookeeper connection string (see zookeeper docs for details).
# This is a comma separated host:port pairs, each corresponding to a zk
# 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

Kafka默认启动9092端口(需要耐心等待数分钟),可修改配置文件config/server.properties。
############################# Socket Server Settings #############################

# The address the socket server listens on. If not configured, the host name will be equal to the value of
# java.net.InetAddress.getCanonicalHostName(), with PLAINTEXT listener name, and port 9092.
#   FORMAT:
#     listeners = listener_name://host_name:port
#   EXAMPLE:
#     listeners = PLAINTEXT://your.host.name:9092
#listeners=PLAINTEXT://:9092


【Kafka使用】
进入kafka服务的bin目录执行创建topic主题
(老版本)./kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic topic1
报错如下:
zookeeper is not a recognized option joptsimple.UnrecognizedOptionException: zookeeper is not a recognized option
kafka2.2+=的版本,已经不需要依赖zookeeper来查看/创建topic,新版本使用 --bootstrap-server替换老版本的 --zookeeper-server。

创建topic
./kafka-topics.sh --create --bootstrap-server localhost:9092 --replication-factor 1 --partitions 1 --topic topic1

查看topic列表
./kafka-topics.sh --list --bootstrap-server 127.0.0.1:9092
查特定topic
./kafka-topics.sh --describe --topic TestTopic --bootstrap-server localhost:9092

生产者
./kafka-console-producer.sh --broker-list 127.0.0.1:9092 --topic topic1

消费者
./kafka-console-consumer.sh --bootstrap-server 127.0.0.1:9092 --topic topic1 --from-beginning

相关推荐

  1. 使用Docker安装Kafka

    2024-07-10 12:10:02       39 阅读
  2. Ruby安装使用指南

    2024-07-10 12:10:02       54 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-10 12:10:02       99 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-10 12:10:02       107 阅读
  3. 在Django里面运行非项目文件

    2024-07-10 12:10:02       90 阅读
  4. Python语言-面向对象

    2024-07-10 12:10:02       98 阅读

热门阅读

  1. 认字之 刬

    2024-07-10 12:10:02       19 阅读
  2. lvs集群

    lvs集群

    2024-07-10 12:10:02      28 阅读
  3. AUTOSAR:汽车软件架构的未来

    2024-07-10 12:10:02       26 阅读
  4. 相机光学(二十九)——显色指数(Ra)

    2024-07-10 12:10:02       23 阅读
  5. 贪心算法合集一

    2024-07-10 12:10:02       26 阅读
  6. 索引知识总结

    2024-07-10 12:10:02       28 阅读
  7. Oracle怎么实现RSA加密解密

    2024-07-10 12:10:02       29 阅读
  8. 前端判断场景和方式

    2024-07-10 12:10:02       23 阅读