1、下载二进制安装包
下载地址:http://kafka.apache.org/downloads
wget https://mirrors.tuna.tsinghua.edu.cn/apache/kafka/2.8.0/kafka_2.12-2.8.0.tgz
2、解压安装包
tar -zxvf kafka_2.12-2.8.0.tgz
3、启动zookeeper
cd kafka_2.12-2.8.0/bin/
启动zookeeper
./zookeeper-server-start.sh ../config/zookeeper.properties
启动报错
/usr/local/kafka_2.12-2.8.0/bin/kafka-run-class.sh: line 330: exec: java: not found
解决:安装openjdk
apt install openjdk-11-jdk
再次启动成功!
[2021-08-04 08:05:36,764] INFO Configuring NIO connection handler with 10s sessionless connection timeout, 4 selector thread(s), 96 worker threads, and 64 kB direct buffers. (org.apache.zookeeper.server.NIOServerCnxnFactory)
[2021-08-04 08:05:36,770] INFO binding to port 0.0.0.0/0.0.0.0:2181 (org.apache.zookeeper.server.NIOServerCnxnFactory)
[2021-08-04 08:05:36,788] INFO zookeeper.snapshotSizeFactor = 0.33 (org.apache.zookeeper.server.ZKDatabase)
[2021-08-04 08:05:36,792] INFO Snapshotting: 0x0 to /tmp/zookeeper/version-2/snapshot.0 (org.apache.zookeeper.server.persistence.FileTxnSnapLog)
[2021-08-04 08:05:36,795] INFO Snapshotting: 0x0 to /tmp/zookeeper/version-2/snapshot.0 (org.apache.zookeeper.server.persistence.FileTxnSnapLog)
[2021-08-04 08:05:36,808] INFO PrepRequestProcessor (sid:0) started, reconfigEnabled=false (org.apache.zookeeper.server.PrepRequestProcessor)
[2021-08-04 08:05:36,814] INFO Using checkIntervalMs=60000 maxPerMinute=10000 (org.apache.zookeeper.server.ContainerManager)
4、启动kafka
# -daemon 后台启动
./bin/kafka-server-start.sh -daemon config/server.properties
5、创建消费者
root@devops_web:/usr/local/kafka/bin# ./kafka-topics.sh --create --bootstrap-server 127.0.0.1:9092 --topic test
Created topic test.
发送消息
root@devops_web:/usr/local/kafka/bin# ./kafka-console-producer.sh --broker-list 127.0.0.1:9092 --topic test
>这是一条测试消息
6、消费消息
root@devops_web:/usr/local/kafka/bin# ./kafka-console-consumer.sh --bootstrap-server 127.0.0.1:9092 --topic test --from-beginning
这是一条测试消息
|