• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

kafka 安装和测试

武飞扬头像
_bliu
帮助1

安装

前提: 已经装好 jdk 和 zookeeper

本次使用ubuntu系统

从官网下载: https://kafka.apache.org/downloads
学新通

cd /usr/local
mkdir kafka
curl -o kafka_2.12-3.3.1.tgz  https://downloads.apache.org/kafka/3.3.1/kafka_2.12-3.3.1.tgz
tar -zxvf kafka_2.12-3.3.1.tgz 

学新通
修改配置文件
zookeeper 我使用本机

cd kafka_2.12-3.3.1
vim config/server.properties

host.name=yourhost
listeners=PLAINTEXT://your host:9092
advertised.listeners=PLAINTEXT://your host:9092
zookeeper.connect=localhost:2181 

学新通
学新通
启动服务 后台启动

// bin/zookeeper-server-start.sh -daemon config/zookeeper.properties

bin/kafka-server-start.sh config/server.properties

查看日志

tail -f -n100 logs/server.log
tail -f -n100 logs/kafkaServer.out

查看端口是否启动

netstat -an|grep 9092

测试:

创建一个topic

bin/kafka-topics.sh --bootstrap-server yourhost:9092 --create --topic test

查看刚创建的topic

bin/kafka-topics.sh --bootstrap-server yourhost:9092 --list 

监听

bin/kafka-console-consumer.sh --bootstrap-server yourhost:9092 --topic test --from-beginning

开启另一个窗口, 生产一些消息

bin/kafka-console-producer.sh --broker-list yourhost:9092 --topic test
> hello world
> hello kafka

查看是否成功监听到数据
学新通

由于自己买的服务器内存太小,不得不降低了启动初始内存, 默认为1G, 如果启动失败,可以关注此设置

bin/kafka-server-start.sh
学新通

伪集群

复制 config/server.properties 为 三份
cp config/server.properties server_01.properties
cp config/server.properties server_02.properties
cp config/server.properties server_03.properties

修改: server_01.properties
broker.id=0
log.dirs=/tmp/kafka01/kafka-logs
listeners=PLAINTEXT://:9092
advertised.listeners=PLAINTEXT://124.221.94.153:9092

修改: server_02.properties
broker.id=2
log.dirs=/tmp/kafka01/kafka-logs
listeners=PLAINTEXT://:9093
advertised.listeners=PLAINTEXT://124.221.94.153:9093

修改: server_03.properties
broker.id=3
log.dirs=/tmp/kafka01/kafka-logs
listeners=PLAINTEXT://:9094
advertised.listeners=PLAINTEXT://124.221.94.153:9094

启动:
/kafka-server-start.sh config/server_01.properties
/kafka-server-start.sh config/server_02.properties
/kafka-server-start.sh config/server_03.properties

查看端口是否已经在监听
netstat -an|grep 9092
netstat -an|grep 9093
netstat -an|grep 9094

创建topic

/kafka-topics.sh --bootstrap-server localhost:9092 localhost:9093 localhost:9094 --create --replication-factor 3 --partitions 3 --topic test

查看topic

./kafka-topics.sh --bootstrap-server localhost:9092 localhost:9093 localhost:9094 --list

查看topic详情

./kafka-topics.sh --bootstrap-server localhost:9092 localhost:9093 localhost:9094 --describe --topic test

生产

./kafka-console-producer.sh --broker-list localhost:9092 localhost:9093 localhost:9094 --topic test

消费

./kafka-console-consumer.sh --bootstrap-server localhost:9092 localhost:9093 localhost:9094 --topic test --from-beginning 

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /boutique/detail/tanhghfiji
系列文章
更多 icon
同类精品
更多 icon
继续加载