一、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. 使用云服务器从0开始搭建云端Jupyter Lab|Notebook

    0.购买云服务器 购买服务器我只推荐硅云,因为香港服务器免备案!而且25岁以下仅需10元每月,至少可买3年!每年享有多次原价续费机会,可补价升级配置. 硅云服务器首页:https://www.vpso ...

  2. 技术分享 | 浅谈mysql语法解析调试方法

    欢迎来到 GreatSQL社区分享的MySQL技术文章,如有疑问或想学习的内容,可以在下方评论区留言,看到后会进行解答 本文向您介绍一种利用mysql解析器和bison的调试选项进行sql语法解析跟踪 ...

  3. vscode 源代码不能自动stage change

    前言 vscode的强大不用赘述了,当你开始使用自然就会爱上他.围绕着IDE的编写体验,有很多强大的自带或者第三方插件,可以做到,编码,git管理,甚至部署一条龙[我司就有这样的插件],让大家沉迷其中 ...

  4. Java中list集合自定义排序-2022新项目

    一.业务场景 为了加快首页数据查询的效率,因此将首页查询的数据大多数都放在了缓存中,包括各种list集合数据.对这些 从缓存中获取的数据做了一个兜底处理,如果从缓存中没有获取到数据,则直接从数据库中去 ...

  5. Java学习--流程控制

    Java学习 流程控制 用户交互Scanner Scanner对象 Java通过Scanner类获取用户的输入 基本语法: Scanner scanner = new Scanner(System.i ...

  6. 彩虹女神跃长空,Go语言进阶之Go语言高性能Web框架Iris项目实战-项目入口与路由EP01

    书接上回,我们已经安装好Iris框架,并且构建好了Iris项目,同时配置了fresh自动监控项目的实时编译,万事俱备,只欠东风,彩虹女神蓄势待发.现在我们来看看Iris的基础功能,如何编写项目入口文件 ...

  7. 744. 寻找比目标字母大的最小字母--LeetCode

    来源:力扣(LeetCode) 链接:https://leetcode.cn/problems/find-smallest-letter-greater-than-target 著作权归领扣网络所有. ...

  8. 痞子衡嵌入式:MCUXpresso IDE下设置代码编译优化等级的几种方法

    大家好,我是痞子衡,是正经搞技术的痞子.今天痞子衡给大家分享的是MCUXpresso IDE下设置代码编译优化等级的几种方法. 最近公司芯片设计团队正在开发一款全新的基于 Cortex-M33 内核的 ...

  9. SpringMVC完整版详解

    1.回顾MVC 1.1什么是MVC MVC是模型(Model).视图(View).控制器(Controller)的简写,是一种软件设计规范. 是将业务逻辑.数据.显示分离的方法来组织代码. MVC主要 ...

  10. 使用IntelliJ IDEA新建一个spring boot项目

    好家伙, 使用IntelliJ IDEA新建一个spring boot项目 目的很简单,就是网页上出现一个"hello world" 别的暂时不管 首先关于工具IntelliJ I ...