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