一、 單節(jié)點(diǎn)1個(gè)broker
- 啟動(dòng)kafka:首先啟動(dòng)zookeeper:
systemctl start zookeeper
笤闯、kafka-server-start.sh $KAFKA_HOME/config/server.properties
- 創(chuàng)建topic:
kafka-topics.sh --create --topic quickstart-events --bootstrap-server localhost:9092
- 查看 topic 信息:
kafka-topics.sh --describe --bootstrap-server localhost:9092 --topic quickstart-events
- 查看所有topic:
kafka-topics.sh --list --zookeeper localhost:2181
- 創(chuàng)建生產(chǎn)者:
kafka-console-producer.sh --topic quickstart-events --bootstrap-server localhost:9092
- 創(chuàng)建消費(fèi)者:
kafka-console-consumer.sh --topic quickstart-events --from-beginning --bootstrap-server localhost:9092
默認(rèn)啟在9092端口
-zookeeper localhost:2181 替換 --bootstrap-server localhost:9092惦银。--bootstrap-server參數(shù),consumer的信息將會(huì)存放在kafka之中咆课,-zookeeper localhost:2181 consumer的信息將會(huì)存放在zookeeper之中。
創(chuàng)建consumer時(shí)會(huì)自動(dòng)創(chuàng)建topic
二扯俱、單節(jié)點(diǎn)多broker书蚪,偽分布式集群
將server.properties
復(fù)制多個(gè),并修改以下配置迅栅,并全部啟動(dòng)(必須得有id=0的broker殊校?)
broker.id=0
listeners=PLAINTEXT://:9092
log.dirs=/tmp/kafka-broker1-logs
- 啟動(dòng)全部broker:
kafka-server-start.sh -daemon $KAFKA_HOME/config/server-1.properties
- 創(chuàng)建主題:
kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 3 --partitions 1 --topic mytopic
或者kafka-topics.sh --create --bootstrap-server localhost:9092 localhost:9093,localhost:9094 --replication-factor 3 --partitions 1 --topic mytopic2
- 查看主題:
kafka-topics.sh --describe -zookeeper localhost:2181 --topic mytopic
- 創(chuàng)建生產(chǎn)者:
kafka-console-producer.sh --broker-list localhost:9093,localhost:9094,localhost:9095 --topic mytopic
- 創(chuàng)建消費(fèi)者:
kafka-console-consumer.sh --bootstrap-server localhost:9093,localhost:9094,localhost:9095 --from-beginning --topic mytopic
三、多主機(jī)集群
待完善读存。