CentOS7安装kafka2.13

538 阅读2分钟

开始

点击- 官网,点击- DOWNLOAD KAFKA,点击- DOCS进入官方文档

image.png

点击- 1.3 Quick Start

安装JDK

NOTE: Your local environment must have Java 8+ installed.

安装zookeeper

kafka下载地址- Download

解压

tar -xzf kafka_2.13-3.1.0.tgz -C /usr/local/

修改配置

#进入到kafka目录
cd /usr/local/kafka_2.13-3.1.0/

#创建日志目录
mkdir logs

#编辑配置文件
vim config/server.properties
 
#修改以下配置

broker.id=1
listeners=PLAINTEXT://你的kafka服务ip:9092
log.dirs=/usr/local/kafka_2.13-3.1.0/logs
zookeeper.connect=你的zk服务ip:2181

#保存退出

启动

[root@localhost kafka_2.13-3.1.0]# bin/kafka-server-start.sh config/server.properties

xxx
[2022-01-26 15:05:12,502] INFO Kafka version: 3.1.0 (org.apache.kafka.common.utils.AppInfoParser)
[2022-01-26 15:05:12,502] INFO Kafka commitId: 37edeed0777bacb3 (org.apache.kafka.common.utils.AppInfoParser)
[2022-01-26 15:05:12,502] INFO Kafka startTimeMs: 1643180712498 (org.apache.kafka.common.utils.AppInfoParser)
[2022-01-26 15:05:12,503] INFO [KafkaServer id=1] started (kafka.server.KafkaServer)
[2022-01-26 15:05:12,588] INFO [BrokerToControllerChannelManager broker=1 name=forwarding]: Recorded new controller, from now on will use broker 192.168.0.162:9092 (id: 1 rack: null) (kafka.server.BrokerToControllerRequestThread)
[2022-01-26 15:05:12,626] INFO [BrokerToControllerChannelManager broker=1 name=alterIsr]: Recorded new controller, from now on will use broker 192.168.0.162:9092 (id: 1 rack: null) (kafka.server.BrokerToControllerRequestThread)


#后台启动
[root@localhost kafka_2.13-3.1.0]# nohup bin/kafka-server-start.sh config/server.properties >/dev/null 2>&1 &
[1] 5993



测试

若配置了listeners=PLAINTEXT://你的kafka服务ip:9092,那么localhost换成‘你的kafka服务ip’


#创建主题
[root@localhost kafka_2.13-3.1.0]# bin/kafka-topics.sh --create --topic quickstart-events --bootstrap-server localhost:9092
Created topic quickstart-events.


#查看主题
[root@localhost kafka_2.13-3.1.0]# bin/kafka-topics.sh --describe --topic quickstart-events --bootstrap-server localhost:9092
Topic: quickstart-events        TopicId: iWAnFNq2T4y1xaTn0UWSGw PartitionCount: 1       ReplicationFactor: 1    Configs: segment.bytes=1073741824
        Topic: quickstart-events        Partition: 0    Leader: 1       Replicas: 1     Isr: 1

#向主题写数据 You can stop the producer client with Ctrl-C at any time
[root@localhost kafka_2.13-3.1.0]# bin/kafka-console-producer.sh --topic quickstart-events --bootstrap-server localhost:9092
>This is my first event
>This is my first event2                           

#监听 You can stop the producer client with Ctrl-C at any time
>^C[root@localhost kafka_2.13-3.1.0bin/kafka-console-consumer.sh --topic quickstart-events --from-beginning --bootstrap-server localhost:9092
This is my first event
This is my first event2
^CProcessed a total of 2 messages

可视化管理工具

CentOS7安装kafka2.13集群