kafka启动(需要先启动zk):
bin/zookeeper-server-start.sh -daemon config/zookeeper.properties bin/kafka-server-start.sh -daemon config/server.properties
kafka停止:
bin/kafka-server-stop.sh
bin/zookeeper-server-stop.sh
把以下内容追加到bashrc中。
以centos为例:
vi ~/.bashrc
追加内容如下:
KAFKA_HOME="/usr/lib/kafka" KAFKA_ADDRESS="192.168.108.136" KAFKA_BIND="${KAFKA_ADDRESS}:9092" ZK_BIND="${KAFKA_ADDRESS}:2181" alias listtopics="${KAFKA_HOME}/bin/kafka-topics.sh --list --zookeeper ${ZK_BIND} " alias createtopic="${KAFKA_HOME}/bin/kafka-topics.sh --create --zookeeper ${ZK_BIND} --replication-factor 1 --partitions 1 --topic " alias kafkaproduce="${KAFKA_HOME}/bin/kafka-console-producer.sh --broker-list ${KAFKA_BIND} --topic " alias kafkaconsume="${KAFKA_HOME}/bin/kafka-console-consumer.sh --zookeeper ${ZK_BIND} --from-beginning --topic " alias kafkaconsumekey="${KAFKA_HOME}/bin/kafka-console-consumer.sh --zookeeper ${ZK_BIND} --from-beginning --property print.key=true --property key.separator=' --- ' --topic " alias kafkaconsumeoffset="${KAFKA_HOME}/bin/kafka-console-consumer.sh --zookeeper ${ZK_BIND} --from-beginning --print-offsets --topic"
保存后使其生效
source ~/.bashrc
查看kafka主题:
listtopics
创建kafka主题parasis:
createtopic parasis
在parasis主题下生产数据,进入命令行后,输入生产数据,以回车结尾:
kafkaproduce parasis
消费parasis主题内数据:
kafkaconsume parasis
消费parasis主题内数据(包含key):
kafkaconsumekey parasis
消费parasis主题内数据(包含offset):
kafkaconsumeoffset parasis