当前位置:网站首页>kafuka学习之路(一)kafuka安装和简单使用
kafuka学习之路(一)kafuka安装和简单使用
2022-07-01 11:11:00 【全栈程序员站长】
大家好,又见面了,我是你们的朋友全栈君。
一,安装环境与软件版本
linux | centOs6 64 |
|---|---|
jdk | jdk-8u191-linux-x64.tar.gz |
zookeeper | zookeeper-3.4.10.tar.gz |
kafuka | kafka_2.11-0.11.0.2 |
二,安装
##解压
-rwxrw-rw-. 1 root root 42136632 Jun 11 01:55 kafka_2.11-0.11.0.2.tgz
drwxr-xr-x. 12 1001 1001 4096 Jun 11 05:35 zookeeper-3.4.10
[[email protected] module]# tar -xvf kafka_2.11-0.11.0.2.tgz
[[email protected] kafka_2.11-0.11.0.2]# ll
total 56
drwxr-xr-x. 3 root root 4096 Nov 10 2017 bin
drwxr-xr-x. 2 root root 4096 Nov 10 2017 config
drwxr-xr-x. 2 root root 4096 Jun 11 20:09 libs
-rw-r--r--. 1 root root 28824 Nov 10 2017 LICENSE
drwxr-xr-x. 2 root root 4096 Jun 11 20:10 logs
-rw-r--r--. 1 root root 336 Nov 10 2017 NOTICE
drwxr-xr-x. 2 root root 4096 Nov 10 2017 site-docs
##添加日志文件夹
[[email protected] kafka_2.11-0.11.0.2]# mkdir logs
[[email protected] kafka_2.11-0.11.0.2]# ll
#修改配文件
[[email protected] kafka_2.11-0.11.0.2]# cd config/
[[email protected] config]# vim server.properties
broker.id=1 #broker的全局唯一编号,不能重复(我的是跟zk的myid一样)
delete.topic.enable=true
listeners=PLAINTEXT://192.168.8.132:9092
log.dirs=/opt/module/kafka_2.11-0.11.0.2/logs
zookeeper.connect=192.168.8.129:2181,192.168.8.132:2181,192.168.8.133:2181三,启动和创建分区使用
注:zookeeper集群启动正常的前提下
#启动
[[email protected] kafka_2.11-0.11.0.2]# bin/kafka-server-start.sh config/server.properties &
#关闭
[[email protected] kafka_2.11-0.11.0.2]# bin/kafka-server-stop.sh stop
##创建topic
#topic 定义topic名
#replication-factor 定义副本数
#partitions 定义分区数
[[email protected] kafka_2.11-0.11.0.2]# bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 3 --partitions 3 --topic test
bin/kafka-topics.sh --zookeeper localhost:2181 --create --replication-factor 3 --partitions 3 --topic test
Created topic "test".
##查看topic 列表
[[email protected] kafka_2.11-0.11.0.2]# bin/kafka-topics.sh --zookeeper localhost:2181 --list
test
##查看详情
[[email protected] kafka_2.11-0.11.0.2]# bin/kafka-topics.sh --zookeeper localhost:2181 --describe --topic test
Topic:test PartitionCount:3 ReplicationFactor:3 Configs: MarkedForDeletion:true
Topic: test Partition: 0 Leader: -1 Replicas: 0,1,2 Isr: 2
Topic: test Partition: 1 Leader: -1 Replicas: 1,2,0 Isr: 2
Topic: test Partition: 2 Leader: -1 Replicas: 2,0,1 Isr: 2
##删除topic
[[email protected] kafka_2.11-0.11.0.2]# bin/kafka-topics.sh --zookeeper localhost:2181 --delete --topic test
Topic test is marked for deletion.
Note: This will have no impact if delete.topic.enable is not set to true.
#如果集群里有某个kafuka没有设置 delete.topic.enable=true ,
#则不会删除,需要全部重新启动后,再删除才可
#删除成功后的标记
[[email protected] kafka_2.11-0.11.0.2]# bin/kafka-topics.sh --zookeeper localhost:2181 --list
test - marked for deletion
#再zk里删除注册的节点
rmr /brokers/topics/【topic name】四,简单使用
##发送消息(localhost 必须是本机的ip)
bin/kafka-console-producer.sh --broker-list localhost:9092 --topic topicTest
##消费消息(localhost 必须是本机的ip)
bin/kafka-console-consumer.sh --zookeeper localhost:2181 --from-beginning --topic topicTest
#生产
[[email protected] kafka_2.11-0.11.0.2]# bin/kafka-console-producer.sh --broker-list 192.168.8.129:9092 --topic test1
>123
>123
>123
>123
>123
>123
>123
>hool^H^H
>holl
>hello
>hello
>
#消费1
[[email protected] kafka_2.11-0.11.0.2]# bin/kafka-console-consumer.sh --zookeeper 192.168.8.132:2181 --from-beginning --topic test1
Using the ConsoleConsumer with old consumer is deprecated and will be removed in a future major release. Consider using the new consumer by passing [bootstrap-server] instead of [zookeeper].
123
123
123
123
123
123
123
hool
holl
hello
hello
#消费2,中途退出后在进来,前期的消息会乱序
[[email protected] kafka_2.11-0.11.0.2]# bin/kafka-console-consumer.sh --zookeeper 192.168.8.133:2181 --from-beginning --topic test1
Using the ConsoleConsumer with old consumer is deprecated and will be removed in a future major release. Consider using the new consumer by passing [bootstrap-server] instead of [zookeeper].
123
123
123
hello
123
123
hool
123
123
holl
hello发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/131623.html原文链接:https://javaforall.cn
边栏推荐
- JS基础--数据类型
- 华泰证券网上开户安全吗?
- Matplotlib data visualization Foundation
- 商汤进入解禁期:核心管理层自愿禁售 强化公司长期价值信心
- LeetCode 438. 找到字符串中所有字母异位词__滑动窗口
- LeetCode.515. 在每个树行中找最大值___逐一BFS+DFS+按层BFS
- "Target detection" + "visual understanding" to realize the understanding and translation of the input image (with source code)
- 金鱼哥RHCA回忆录:DO447使用Ansible与API通信--使用Ansible Tower API启动作业
- Oneconnect plans to be listed in Hong Kong on July 4: a loss of nearly 3 billion in two years, with a market capitalization evaporation of more than 90%
- 英特爾實驗室公布集成光子學研究新進展
猜你喜欢

Infinite innovation in cloud "vision" | the 2022 Alibaba cloud live summit was officially launched

華為設備配置大型網絡WLAN基本業務

商城小程序源码开源版-可二开

Google's new paper Minerva: solving quantitative reasoning problems with language models

TEMPEST HDMI泄漏接收 5

名创拟7月13日上市:最高发行价22.1港元 单季净利下降19%

The first anniversary of the data security law, which four major changes are coming?

2022年6月编程语言排行,第一名居然是它?!

CVPR 2022 | Virtual Correspondence: Humans as a Cue for Extreme-View Geometry

Huawei Equipment configure les services de base du réseau WLAN à grande échelle
随机推荐
商汤进入解禁期:核心管理层自愿禁售 强化公司长期价值信心
名创拟7月13日上市:最高发行价22.1港元 单季净利下降19%
PHP realizes lottery function
证券账户随便哪里开都能使用吗 开户安全吗
Compliance management of fund managers
LeetCode.515. 在每个树行中找最大值___逐一BFS+DFS+按层BFS
Internal control of fund managers
Dotnet console uses microsoft Maui. Getting started with graphics and skia
英特尔实验室公布集成光子学研究新进展
妙啊!MarkBERT
2022年6月编程语言排行,第一名居然是它?!
Exposure:A White-Box Photo Post-Processing Framework阅读札记
索引失效的几种情况
Valgrind usage of memory leak locating tool
价值1000毕业设计校园信息发布平台网站源码
Combinaison Oracle et json
(POJ - 1456) supermarket
Huawei HMS core joins hands with hypergraph to inject new momentum into 3D GIS
The exclusive collection of China lunar exploration project is limited to sale!
The idea runs with an error command line is too long Shorten command line for...