kafka(zk)介绍及使用

1、分布式、高效、高容错的流式平台。

2、作为消息中间件,一般部署在流式组件前一个,业务高峰期,缓冲的作用。

3、消息是存储在zk上

4、zkCli.sh -server host:port 常用命令:(ls,rmr)

5、配置文件/kafka,创建一个文件夹

6、常用命令

./kafka-topics.sh --creat --zookeeper --replication-factor --partition --topic 


 ./kafka-topics.sh --list 


./kafka-topics.sh --delete --zookeeper --topic 

假删除:   delete.topic.enable=true  --不生效
真删除 彻底删除:
kafka元数据在哪? zk 
rmr /config/topics/topic_name
rmr /brokers/topics/topic_name
rmr /admin/delete_topics/topic_name
kafka数据在哪?   磁盘
rm -rf $KAFKA_HOME/logs/topic_name-*


./kafka-topics.sh --alter --zookeeper --partitions 4 --topic 

调整topic分区数(只能调大,不能调小)


./kafka-topics.sh --describe --zookeeper --topic 

Topic: 主题  1----10
partitions:  3个分区  下标是从0开始的   物理上的分区
replication: 3个副本 指的是一个分区被复制3份

Topic:test      PartitionCount:3        ReplicationFactor:3     Configs:
Topic: test     Partition: 0                 Leader: 1                     Replicas: 1,3,2 Isr: 1,3,2
Topic: test     Partition: 1                 Leader: 2                     Replicas: 2,1,3 Isr: 2,1,3
Topic: test     Partition: 2                 Leader: 3                     Replicas: 3,2,1 Isr: 3,2,1

第一行列出了这个topic的总体情况,如topic名称,分区数量,副本数量等。

第二行开始,每一行列出了一个分区的信息,如它是第几个分区,这个分区的leader是哪个broker,副本位于哪些broker,有哪些副本处理同步状态

拿第二行做分析:
Partition: 分区的信息
Leader: 1  指的是broker.id=1  有读写功能
Replicas: 复制该分区数据的节点列表,第一位代表leader  静态表述
Isr: in-sync Replicas 正在复制的副本节点列表                  动态表述
     当leader挂了,会从这个列表选举出leader
        Topic: ruozedata        Partition: 0    Leader: 1       Replicas: 1,3,2 Isr: 1,2
        Topic: ruozedata        Partition: 1    Leader: 2       Replicas: 2,1,3 Isr: 2,1
        Topic: ruozedata        Partition: 2    Leader: 2       Replicas: 3,2,1 Isr: 2,1

一般生产上:--partitions 取决于你的broker数量
--replication-factor 3 --partitions 8
kafka机器8个
It provides simple parallelism, 1:1 correspondence between Kafka partitions and Spark partitions, and access to offsets and metadata. 

7、调优

Producer:(Flume)

acks :all
buffer.memory :缓冲区536870912
compression.type :snappy
retries :重试次数 100
max.in.flight.requests.per.connection =1
batch.size :10000字节
max.request.size = 2097152 请求的最大字节
request.timeout.ms = 360000
metadata.fetch.timeout.ms = 360000
max.block.ms = 1800000
timeout.ms
linger.ms 5s (生产不用)

Broker:(CDH)

message.max.bytes 2560KB  1条消息的大小
zookeeper.session.timeout.ms 180000
replica.fetch.max.bytes 5M   大于message.max.bytes
num.replica.fetchers 6
replica.lag.max.messages 6000
replica.lag.time.max.ms 15000
log.flush.interval.messages 10000
log.flush.interval.ms 5s

Consumer:

https://issues.apache.org/jira/browse/SPARK-22968
, "max.partition.fetch.bytes" -> (5242880: java.lang.Integer) //default: 1048576
, "request.timeout.ms" -> (90000: java.lang.Integer) //default: 60000
, "session.timeout.ms" -> (60000: java.lang.Integer) //default: 30000
, "heartbeat.interval.ms" -> (5000: java.lang.Integer)
, "receive.buffer.bytes" -> (10485760: java.lang.Integer)

猜你喜欢

转载自blog.csdn.net/weixin_39182877/article/details/80075497