$ cd /opt/kafka/zookeeper-3.4.12/bin $ zkServer.sh start
确认zookeeper是否成功启动:bootstrap
$ netstat -an | grep 2181 tcp6 0 0 :::2181 :::* LISTEN
返回以上结果说明成功启动,接下来就能够启动kafka服务并使用具体的kafka命令来进行相应操做了。服务器
$ cd /opt/kafka/kafka_2.12-1.1.0/bin $ ./kafka-server-start.sh -daemon /opt/kafka/kafka_2.12-1.1.0/config/server.properties
确认kafka服务是否正常启动:架构
$ ps -ef | grep kafka
返回以上结果说明成功启动。tcp
利用kafka指令进行具体的操做。spa
$ cd /opt/kafka/kafka_2.12-1.1.0/bin $ ./kafka-topics.sh --list --zookeeper localhost:2181
$ ./kafka-console-producer.sh --broker-list PLAINTEXT://xx.xx.xx.xx:9092 --topic test-topic
./kafka-console-consumer.sh --zookeeper localhost:2181 --topic test-topic --from-beginning
这样,在2中建立的生产者命令行中发送的消息,3中建立的消费者就能够及时接收到。
注意:上面截图中提示旧的消费者建立方式将会废弃,建议使用bootstrap-server这种新的方式,以下:操作系统
./kafka-console-consumer.sh --bootstrap-server xx.xx.xx.xx:9092 --topic test-topic --from-beginning
./kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic my-test-topic
./kafka-topics.sh --describe --zookeeper localhost:2181 --topic test-topic
# 已经存在topic my-test-topic,且该topic以前分区数为1,如今咱们将该topic的分区数修改为2 ./kafka-topics.sh --zookeeper localhost:2181 --alter --topic my-test-topic --partitions 2
./kafka-topics.sh --zookeeper localhost:2181 --delete --topic my-test-topic
本文到此结束。.net