1、
# 下载kafka
[root@localhost kafka]# tar -xzf kafka_2.11-2.0.0.tgz
[root@localhost kafka]# cd kafka_2.11-2.0.0
[root@localhost kafka_2.11-2.0.0]# pwd
/usr/local/programs/kafka/kafka_2.11-2.0.0
[root@localhost kafka_2.11-2.0.0]# ls
bin config libs LICENSE logs NOTICE site-docs
[root@localhost kafka_2.11-2.0.0]#
# 启动zookeeper
[root@localhost kafka_2.11-2.0.0]# bin/zookeeper-server-start.sh config/zookeeper.properties &
# 启动一个Kafka Server
[root@localhost kafka_2.11-2.0.0]# bin/kafka-server-start.sh config/server.properties
# 创建包含多个broker(Kafka Server)的集群
[root@localhost kafka_2.11-2.0.0]# cp config/server.properties config/server-1.properties
[root@localhost kafka_2.11-2.0.0]# cp config/server.properties config/server-2.properties
[root@localhost kafka_2.11-2.0.0]# vim config/server-1.properties
broker.id=1
listeners=PLAINTEXT://:9093
log.dirs=/tmp/kafka-logs-1
zookeeper.connect=localhost:2181
[root@localhost kafka_2.11-2.0.0]# vim config/server-2.properties
broker.id=2
listeners=PLAINTEXT://:9094
log.dirs=/tmp/kafka-logs-2
zookeeper.connect=localhost:2181
[root@localhost kafka_2.11-2.0.0]# bin/kafka-server-start.sh config/server-1.properties &
[root@localhost kafka_2.11-2.0.0]# bin/kafka-server-start.sh config/server-2.properties &
[root@localhost kafka_2.11-2.0.0]# netstat -tnlp | grep 909
tcp6 0 0 :::9092 :::* LISTEN 18663/java
tcp6 0 0 :::9093 :::* LISTEN 18998/java
tcp6 0 0 :::9094 :::* LISTEN 19332/java
# 创建一个主题
[root@localhost kafka_2.11-2.0.0]# bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test
# 查看主题
[root@localhost kafka_2.11-2.0.0]# bin/kafka-topics.sh --describe --zookeeper localhost:2181 --topic test
Topic:test PartitionCount:1 ReplicationFactor:3 Configs:
Topic: test Partition: 0 Leader: 2 Replicas: 2,0,1 Isr: 2,1,0
# 发送消息
[root@localhost kafka_2.11-2.0.0]# bin/kafka-console-producer.sh --broker-list localhost:9092 --topic test
>Hello World
>Hello Java
>^C
# 接收消息
[root@localhost kafka_2.11-2.0.0]# bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --from-beginning --topic test
Hello World
Hello Java
转https://www.cnblogs.com/cjsblog/p/9409443.html