快速开始
-
下载kafka安装包:http://kafka.apache.org/downloads
-
解压安装包
tar -xzf kafka_2.13-3.0.0.tgz
cd kafka_2.13-3.0.0
-
启动zookeeper
bin/zookeeper-server-start.sh config/zookeeper.properties
-
启动kafka-server
bin/kafka-server-start.sh config/server.properties
- 创建topic
bin/kafka-topics.sh --create --topic quickstart-events --bootstrap-server localhost:9092
- 查看topic信息
bin/kafka-topics.sh --describe --topic quickstart-events --bootstrap-server localhost:9092
- 创建message
bin/kafka-console-producer.sh --topic quickstart-events --bootstrap-server localhost:9092
- 读取message
bin/kafka-console-consumer.sh --topic quickstart-events --from-beginning --bootstrap-server localhost:9092
kafka集群
- 将conf/server.properties 复制两份,设置属性:
broker.id=1
listeners=PLAINTEXT://:9093
log.dir=/tmp/kafka-logs-1
- 启动三个kafka服务
bin/kafka-server-start.sh config/server.properties
bin/kafka-server-start.sh config/server-1.properties &
bin/kafka-server-start.sh config/server-2.properties &
-
创建一个包含2个分区,每个分区有三个副本的主题
bin/kafka-topics.sh --create --topic test3 --replication-factor=3 --partitions=2 --bootstrap-server localhost:9092
-
查看有topic列表
bin/kafka-topics.sh --list --bootstrap-server localhost:9092
-
查看topic信息
bin/kafka-topics.sh --describe --topic test3 --bootstrap-server localhost:9092
- 当kill掉集群中的某个broker后,kafka集群会更新leader以及分区的isr信息
导入导出
-
echo -e "foo\nbar" >test.txt
-
bin/connect-standalone.sh config/connect-standalone.properties config/connect-file-source.properties config/connect-file-sink.properties