一、CentOS 7.9 安装 kafka_2.13

地址

二、安装准备

1 安装JDK

在安装kafka之前必须先安装JDK和zookeeper,如何安装JDK,可以查看:CentOS 7.9 安装 jdk-8u333

2 下载安装zookeeper

如何在CentOS 7 下安装zookeeper,可以查看:CentOS 7.9 安装 zookeeper-3.6.3

二、kafka

1 进入Apache官网 http://kafka.apache.org/downloads.html 选择Binary downloads,选择版本进行下载。

2 wget下载

wget https://archive.apache.org/dist/kafka/3.0.1/kafka_2.13-3.0.1.tgz

3 解压

tar -zxvf /opt/software/kafka_2.13-3.0.1.tgz -C /opt/
ll /opt/kafka_2.13-3.0.1/

4 进入kafka目录

5 启动kafka之前要确保zookeeper已经启动,如果没有启动,执行以下命令

zkServer.sh start

6 修改kafka配置文件中的zookeeper地址,打开配置文件

vim /opt/kafka_2.13-3.0.1/config/server.properties

# The id of the broker. This must be set to a unique integer for each broker.
broker.id=0 ############################# Socket Server Settings ############################# # The address the socket server listens on. It will get the value returned from
# java.net.InetAddress.getCanonicalHostName() if not configured.
# FORMAT:
# listeners = listener_name://host_name:port
# EXAMPLE:
# listeners = PLAINTEXT://your.host.name:9092
listeners=PLAINTEXT://192.168.0...:8091
# Hostname and port the broker will advertise to producers and consumers. If not set,
# it uses the value for "listeners" if configured. Otherwise, it will use the value
# returned from java.net.InetAddress.getCanonicalHostName().
#advertised.listeners=PLAINTEXT://your.host.name:9092 # A comma separated list of directories under which to store log files
log.dirs=/opt/kafka_2.13-3.0.1/logs ############################# 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=192.168.0.98:2181 # Timeout in ms for connecting to zookeeper
zookeeper.connection.timeout.ms=18000

7 新建日志储存路径

mkdir /opt/kafka_2.13-3.0.1/logs

8 启动kafka

./bin/kafka-server-start.sh config/server.properties
# 后台启动
./bin/kafka-server-start.sh -daemon config/server.properties

四、设置开机自动启动

1 切换到/lib/systemd/system/目录,创建自启动文件

vim /lib/systemd/system/kafka.service
[Unit]
Description=kafkaservice
After=network.target [Service]
WorkingDirectory=/opt/kafka_2.13-3.0.1
ExecStart=/opt/kafka_2.13-3.0.1/bin/kafka-server-start.sh /opt/kafka_2.13-3.0.1/config/server.properties
ExecStop=/opt/kafka_2.13-3.0.1/bin/kafka-server-stop.sh
User=root
Group=root
Restart=always
RestartSec=10 [Install]
WantedBy=multi-user.target

2 设置自启动

systemctl enable kafka.service

3 立即启动服务

systemctl start kafka.service

4 查看启动状态

systemctl status kafka.service

五、Kafka命令测试

1 创建topic

./bin/kafka-topics.sh --bootstrap-server 192.168.0.98:8091 --create --topic iyuyixyz --partitions 2 --replication-factor 1

2 列出所有topic

./bin/kafka-topics.sh --bootstrap-server 192.168.0.98:8091 --list

3 列出所有topic的信息

./bin/kafka-topics.sh --bootstrap-server 192.168.0.98:8091 --describe

4 列出指定topic的信息

./bin/kafka-topics.sh --bootstrap-server 192.168.0.98:8091 --describe --topic iyuyixyz

5 生产者(消息发送程序)

./bin/kafka-console-producer.sh --broker-list 192.168.0.98:8091 --topic iyuyixyz

6 消费者(消息接收程序)

./bin/kafka-console-consumer.sh --bootstrap-server 192.168.0.98:8091 --topic iyuyixyz

六、配置系统环境变量

vim /etc/profile
export PATH=$PATH:/opt/kafka_2.13-3.0.1/bin
# 使配置生效
source /etc/profile

七、报错

1 zookeeper is not a recognized option

新版已不支持zookeeper参数,需要换成bootstrap-server参数。

./bin/kafka-topics.sh --create --zookeeper 192.168.0.98:2181 --replication-factor 1 --partitions 1 --topic iyuyixyz

原来新版本的kafka,已经不需要依赖zookeeper来创建topic,新版的kafka创建topic指令为下

./bin/kafka-topics.sh --bootstrap-server 192.168.0.98:8091 --create --topic iyuyixyz --partitions 2 --replication-factor 1

2 节点响应超时(请求超时)

[2022-10-13 01:11:34,670] WARN [AdminClient clientId=adminclient-1] Connection to node -1 (/192.168.0.92:8092) could not be established. Broker may not be available. (org.apache.kafka.clients.NetworkClient)
[2022-10-13 01:11:37,676] WARN [AdminClient clientId=adminclient-1] Connection to node -1 (/192.168.0.92:8092) could not be established. Broker may not be available. (org.apache.kafka.clients.NetworkClient)
[2022-10-13 01:11:40,682] WARN [AdminClient clientId=adminclient-1] Connection to node -1 (/192.168.0.92:8092) could not be established. Broker may not be available. (org.apache.kafka.clients.NetworkClient)
Error while executing topic command : Timed out waiting for a node assignment. Call: createTopics
[2022-10-13 01:11:43,600] ERROR org.apache.kafka.common.errors.TimeoutException: Timed out waiting for a node assignment. Call: createTopics
(kafka.admin.TopicCommand$)

该错误是由于没有用对应版本的命令,访问了错的主机名(或IP)和端口,所以请求失败导致超时。

其中的createTopics、listTopics等都会出现该错误。如果没配置server.properties文件的listeners值,也会报以上错误。

listeners值默认是PLAINTEXT://:9092,要改为PLAINTEXT://localhost:9092或PLAINTEXT://IP:9092等

CentOS 7.9 安装 kafka_2.13的更多相关文章

  1. CentOS 7 下安装 teamviewer 13

    CentOS 版本:centos-release-7-4.1708.el7.centos.x86_64(通过 rpm -q centos-release 查询) teamviewer 版本:teamv ...

  2. 阿里云CentOS服务器下安装Golang1.13并配置代理

    注:root账户或添加sudo命令运行. 下载到/usr/local位置并解压 cd /usr/local wget https://studygolang.com/dl/golang/go1.13. ...

  3. centos使用Yum安装postgresql 13

    rpm源安装 yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat ...

  4. CentOS 6.9安装Python2.7.13

    查看当前系统中的 Python 版本 python --version 返回 Python 2.6.6 为正常. 检查 CentOS 版本 cat /etc/redhat-release 返回 Cen ...

  5. 在Centos 7上安装配置 Apche Kafka 分布式消息系统集群

    Apache Kafka是一种颇受欢迎的分布式消息代理系统,旨在有效地处理大量的实时数据.Kafka集群不仅具有高度可扩展性和容错性,而且与其他消息代理(如ActiveMQ和RabbitMQ)相比,还 ...

  6. Centos 使用YUM安装MariaDB

    1.在 /etc/yum.repos.d/ 下建立 MariaDB.repo,内容如下: [azureuser@mono etc]$ cd /etc/yum.repos.d [azureuser@mo ...

  7. 如何在CentOS 7上安装Percona服务器

    在这篇文章中我们将了解关于 Percona 服务器,一个开源的MySQL,MariaDB的替代品.InnoDB的数据库引擎使得Percona 服务器非常有吸引力,如果你需要的高性能,高可靠性和高性价比 ...

  8. centos下编译安装mysql5.5/5.6

    2013年11月16日 19:39:13 centos 6 mysql 5.5.28 我只说些我出错的地方: cmake后删除的方法是 xargs rm < install_manifest.t ...

  9. CentOS 5.X安装LAMP最高版本环境

    #------------CentOS 5.X安装LAMP最高版本环境------------------#! /bin/sh #安装Apacheyum install httpd -y#1.关闭se ...

随机推荐

  1. @DS("slave") 多数据源兼容事务问题解决方案

    SpringBoot项目中用到多数据源,在方法上又必须加事务处理,此时可以对使用了@DS的方法或类添加@Transactional并添加事务隔离级别 举例: 1.这是一个方法,方法内需要实现多数据源查 ...

  2. 年度开源盛会 ApacheCon 首发中文盛宴来临,欢迎报名!

    ApacheCon 是久负盛名的开源盛宴,为开源界备受关注的会议之一,也是开源运动早期的知名活动之一,其最早的一期要追溯 1998 年,也是在这一届上,开发 HTTPD 服务的开发者们欢聚一堂,并决定 ...

  3. Luogu2251 质量检测 (ST表)

    我怎么开始划水了... #include <iostream> #include <cstdio> #include <cstring> #include < ...

  4. 面试突击77:Spring 依赖注入有几种?各有什么优缺点?

    IoC 和 DI 是 Spring 中最重要的两个概念,其中 IoC(Inversion of Control)为控制反转的思想,而 DI(Dependency Injection)依赖注入为其(Io ...

  5. 【Java】学习路径57-TCP协议客户端与服务器端的关闭

    在TCP协议中,如果发送端(客户端)关闭了,那么接收端(服务器端)端就会收到这个消息. 那么接收端(服务器端)怎么知道的呢? 我们进行实验: 首先在发送端中编写一段程序,当用户输入"end& ...

  6. 手把手教你搭建JAVA分布式爬虫

    在工作中,我们经常需要去获取一些数据,但是这些数据可能需要从第三方平台才可以获取到.这个时候,爬虫系统就可以帮助我们来完成这些事情. 提到爬虫系统,很多人都会想到使用python.但实际上,语言只是一 ...

  7. KingbaseES时间函数的比较

    KingbaseES提供了多种的时间函数,这些函数在使用过程中存在哪些不同? **同一事务** test=# begin test-# for i in 1.. 10 loop test-# rais ...

  8. Springboot mybatis总结

    mybatis 总结 属性配置 1. mybatis.configuration.mapUnderscoreToCamelCase=true mapUnderscoreToCamelCase用于映射表 ...

  9. 目标检测-SSD算法从零实现

    1. 几个工具函数 def box_corner_to_center(boxes): """从(左上,右下)转换到(中间,宽度,高度)""" ...

  10. Redis变慢?深入浅出Redis性能诊断系列文章(二)

    (本文首发于"数据库架构师"公号,订阅"数据库架构师"公号,一起学习数据库技术) 本篇为Redis性能问题诊断系列的第二篇,本文主要从应用发起的典型命令使用上进 ...