kafuka学习之路(一)kafuka安装和简单使用

kafuka学习之路(一)kafuka安装和简单使用一,安装环境与软件版本linux centOs664 jdk jdk-8u191-linux-x64.tar.gz zookeeper zookeeper-3.4.10.tar.gz kafuka kafka_2.11-0.11.0.2 二,安装##解压-rwxrw-rw-.1rootroot42136632Jun11…

大家好,又见面了,我是你们的朋友全栈君。

一,安装环境与软件版本

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
[root@localhost module]# tar -xvf kafka_2.11-0.11.0.2.tgz 
[root@localhost 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

##添加日志文件夹
[root@localhost kafka_2.11-0.11.0.2]# mkdir logs
[root@localhost kafka_2.11-0.11.0.2]# ll

#修改配文件
[root@localhost kafka_2.11-0.11.0.2]# cd config/
[root@localhost 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集群启动正常的前提下

#启动
[root@localhost kafka_2.11-0.11.0.2]# bin/kafka-server-start.sh config/server.properties &

#关闭
[root@localhost kafka_2.11-0.11.0.2]# bin/kafka-server-stop.sh stop

##创建topic
#topic 定义topic名
#replication-factor  定义副本数
#partitions  定义分区数
[root@localhost 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 列表
[root@localhost kafka_2.11-0.11.0.2]# bin/kafka-topics.sh --zookeeper localhost:2181 --list
test

##查看详情
[root@localhost 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
[root@localhost 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 ,
#则不会删除,需要全部重新启动后,再删除才可
#删除成功后的标记
[root@localhost 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

#生产
[root@localhost 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
[root@localhost 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,中途退出后在进来,前期的消息会乱序
[root@localhost 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.net/131623.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 【FAQ】SpingMVC实现集合參数(Could not instantiate bean class [java.util.List])

    【FAQ】SpingMVC实现集合參数(Could not instantiate bean class [java.util.List])

    2021年12月7日
    65
  • Mysql清空表中数据「建议收藏」

    Mysql清空表中数据「建议收藏」常用的清空数据表的SQL语句有如下两种deletefrom表名;truncatetable表名第一种方法是删除表中数据且主键ID是继续顺序排下去第二种方法是彻底清空表中数据把数据结构恢复至刚建表的时候数据全部清空从性能上讲测试了三千条数据deletefromtable比truncatetable表名效率要慢上一点。truncate清除数…

    2022年6月2日
    36
  • 杭州的旅游景点与民间传说故事「建议收藏」

    杭州的旅游景点与民间传说故事「建议收藏」 杭州的旅游景点与民间传说故事虎跑梦泉虎跑泉是一处以“泉”为主题的观泉、听泉、品泉、试泉的泉源景观,又是以性空、济公、弘一法师传奇故事为特色的人文景观,坐落位于西湖之南的大慈山定慧禅寺内。民间传说唐代性空大师游历此山,这里风景优美,只是无水源,决定去别处,忽然有神人告诉他即将有二只老虎会来挖泉,翌日,果然有二虎跑山出泉,甘冽醇厚,纯净无菌,从此“龙井茶叶虎跑泉”被称为“西湖双绝”。

    2022年5月31日
    34
  • EasyTouch基本用法

    EasyTouch基本用法EasyTouch基本用法本文提供全流程,中文翻译。Chinar坚持将简单的生活方式,带给世人!(拥有更好的阅读体验——高分辨率用户请根据需求调整网页缩放比例)1hierarchy(层次面板)

    2022年8月2日
    5
  • linux网卡的fec功能,网络控制器驱动程序学习记录fec(1)

    linux网卡的fec功能,网络控制器驱动程序学习记录fec(1)1,首先从模块加载函数module_init(fec_enet_module_init);staticint__initfec_enet_module_init(void){structnet_device*dev;inti,j,err;DECLARE_MAC_BUF(mac);printk(“FECENETVersion0.2\n”);for(i=0;(i<…

    2022年8月11日
    6
  • python连接远程服务器_windows收不到组播

    python连接远程服务器_windows收不到组播C/C++code//MulticastSocket.cpp:implementationfile//#include”stdafx.h”#include”MulticastSocket.h”#include”HuanRemoteServiceDlg.h”#include”atlconv.h”#ifdef_DEBUG#definenewDEBUG_NEW#undefTHI…

    2022年10月1日
    2

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号