铭文一级:
单节点单broker的部署及使用
$KAFKA_HOME/config/server.properties
broker.id=0
listeners
host.name
log.dirs
zookeeper.connect
启动Kafka
kafka-server-start.sh
USAGE: /home/hadoop/app/kafka_2.11-0.9.0.0/bin/kafka-server-start.sh [-daemon] server.properties [--override property=value]*
kafka-server-start.sh $KAFKA_HOME/config/server.properties
创建topic: zk
kafka-topics.sh --create --zookeeper hadoop000:2181 --replication-factor 1 --partitions 1 --topic hello_topic
查看所有topic
kafka-topics.sh --list --zookeeper hadoop000:2181
发送消息: broker
kafka-console-producer.sh --broker-list hadoop000:9092 --topic hello_topic
消费消息: zk
kafka-console-consumer.sh --zookeeper hadoop000:2181 --topic hello_topic --from-beginning
--from-beginning的使用
查看所有topic的详细信息:kafka-topics.sh --describe --zookeeper hadoop000:2181
查看指定topic的详细信息:kafka-topics.sh --describe --zookeeper hadoop000:2181 --topic hello_topic
单节点多broker
server-1.properties
log.dirs=/home/hadoop/app/tmp/kafka-logs-1
listeners=PLAINTEXT://:9093
broker.id=1
server-2.properties
log.dirs=/home/hadoop/app/tmp/kafka-logs-2
listeners=PLAINTEXT://:9094
broker.id=2
server-3.properties
log.dirs=/home/hadoop/app/tmp/kafka-logs-3
listeners=PLAINTEXT://:9095
broker.id=3
kafka-server-start.sh -daemon $KAFKA_HOME/config/server-1.properties &
kafka-server-start.sh -daemon $KAFKA_HOME/config/server-2.properties &
kafka-server-start.sh -daemon $KAFKA_HOME/config/server-3.properties &
kafka-topics.sh --create --zookeeper hadoop000:2181 --replication-factor 3 --partitions 1 --topic my-replicated-topic
kafka-console-producer.sh --broker-list hadoop000:9093,hadoop000:9094,hadoop000:9095 --topic my-replicated-topic
kafka-console-consumer.sh --zookeeper hadoop000:2181 --topic my-replicated-topic
kafka-topics.sh --describe --zookeeper hadoop000:2181 --topic my-replicated-topic
铭文二级:
Kafka版本下载版本为0.9.0.0比较稳定,再选相对应的scala版本(http://kafka.apache.org/downloads)
单节点单broker的部署及使用=>
配置环境变量,修改配置文件:conf/server.properties
broker.id = 0 //唯一id值
listeners = :9092 //监听端口号,发送的内容到broker即为此端口
hostname = hadoop000 //默认localhost也行
log.dirs = /home/app/tmp/kafka-logs //临时文件目录,需建立tmp,kafka-logs可不建立
zookeeper.connect = hadoop000:2181 //创建topic,查询topic,消耗者均为此端口
[num.partitions = 1] //分区
启动kafka:kafka-server-start.sh $KAFKA_HOME/config/server.properties //不知道如何使用就先执行kafka-server-start.sh
创建topic:kafka-topics.sh --create --zookeeper hadoop000:2181 --replication-factor 1 --partitions 1 --topic hello_topic
查询所有topic:kafka-topics.sh --list --zookeeper hadoop000:2181
发送消息:kafka-console-producer.sh --broker-list hadoop000:9092 --topic hello_topic
消费消息:kafka-console-consumer.sh --zookeeper hadoop000:2181 --topic hello_topic //可加 --from-beginning 只从一开始的也消费
查看所有topic的详细信息:kafka-topics.sh --describe --zookeeper hadoop000:2181
查看指定topic的详细信息:kafka-topics.sh --describe --zookeeper hadoop000:2181 --topic hello_topic
详细信息:Replicas:3,1,2 // 副本节点 Isr:3,1,2 //存活节点数
单节点多broker=>