File-Settings-Tool-External Tools
show byte code
$JDKPath$\bin\javap.exe
-c $FileClass$
$OutputPath$
/********************** kafka **********************/
Kafka cluster集群
点对点模式,需要线程监控
发布/订阅,推送速度与客户端速度不一致
对消息保存根据topic进行归类。
发送者 producer
接受者 consumer
多实例,每个实例(server)称为broker
kafka依赖zookeeper集群保存meta信息,保证系统可用性。客户端请求只能Leader处理
partition:分区
Kafka Cluster集群:
Broker1 :
TopcicA(partition0) Leader
TopcicA(partition1) Follower
Broker2 :
TopcicA(partition0) Follower
TopcicA(partition1) Leader
Broker3 :
Partition0(message0、message1) topic分一个区
Follower不做任何操作
消费者组不能同时消费同一分区
ConsumerA
Consumer group
ConsumerB
一个消费者可以消费多个topic
mkdir logs
cd config
搭建集群,修改: server.properties
broker.id=0
delete.topic.enable=true
log.dirs=/opt/module
zookeeper.connect=hadoop102:2181,hadoop103:2181,hadoop104:2181
cd ..
xsync kafka/
vi server.properties
broker.id=1
broker.id=2
启动kafka之前先启动Zookeeper:
zkstart.sh
查看启动是否成功:
/opt/module/zookeeper-3.4.10/bin/zkServer.sh status
Mode:follower 说明启动成功。
启动kafka:
机器1:bin/kafka-server-start.sh config/server/properties
机器2:bin/kafka-server-start.sh config/server/properties
机器3:bin/kafka-server-start.sh config/server/properties
每台机器需单独启动
util.sh 查看三台机器启动进程
创建 分区数2个 副本数2个 topic名称
bin/kafka-topics.sh --create --zookeeper hadoop102:2181 --partitions 2 -- replication-factor 2 --topic first
查看
bin/kafka-topics.sh --list --zookeeper hadoop102:2181
查看日志
cd logs
三台机器,副本数设置5,会报错,提示最多副本3。
创建 分区2 副本5 topic名称
bin/kafka-topics.sh --create --zookeeper hadoop102:2181 --partitions 2 -- replication-factor 5 --topic second
启动生产者: 往哪个topic发送
bin/kafka-console-producer.sh --broker -list hadoop102:9092 --topic first
>hello
>yz
启动消费者(集群) 在103机器启动
消费哪个topic,获取最新的数据 从一开始进行消费
bin/kafka-console-consumer.sh --zookeeper hadoop102:2181 --topic first --from-beginning
使用bootstrap-server代替zookeeper以消除警告
消费哪个topic,获取最新的数据 从一开始进行消费
bin/kafka-console-consumer.sh --bootstrap-server hadoop102:2181 --topic first --from-beginning
数据存在topic,使用机器104查看有多少个topic
bin/kafka-topics.sh --list --zookeeper hadoop102:2181
__consumer_offsets 解释:系统自动创建,这是应为使用bootstrap后,保存到本地的topic
first
查看topic详情 描述指定topic
bin/kafka-topics.sh --zookeeper hadoop102:2181 --describeopic first
分区 Leader机器 副本 选举用
Topic:first Partition: 0 Leader: 0 Replicas: 0,2 Isr: 0,2
Topic:first Partition: 1 Leader: 1 Replicas: 1,0 Isr: 1,0
Isr: 0,2(这两副本和leader最相近,往前排,leader挂掉后,采用下一个代替Leader)
机器 是否Leader,Leader只负责生产者写数据,Follower主动从Leader拉取数据。
0 Leader
1 Follower
2 Follower
删除topic,会提示设置为true
bin/kafka-topics.sh --delete --zookeeper hadoop102:2181 -topic first
从新创建topic
分区1个 副本3个 指定topic名称
bin/kafka-topics.sh --create --zookeeper hadoop102:2181 --partitions 1 --replication-factro 3 --topic first