kafka下载地址:http://mirror.bit.edu.cn/apache/kafka/2.1.0/kafka_2.12-2.1.0.tgz
解压:tar -xzvf kafka_2.12-2.1.0.tgz
cd kafka_2.12-2.1.0/config
vim server.propertis
kafka server.propertis配置文件添加一下配置项 注意要把里面默认的跟如下 相同的配置项删掉(注意节点id不同的机器不能一样)
######################################
#当前节点id
broker.id=2
#监听端口
listeners=PLAINTEXT://192.168.25.102:9092
host.name=localhost
port=9092
#zk集群信息
zookeeper.connect=47.12.124.186:2181,47.12.124.186:2182,47.12.124.186:2183
zookeeper.connection.timeout.ms=6000
#控制设定几个备份
default.replication.factor=3
#控制设定几个分区
num.partitions=1
#日志文件
log.dirs=/usr/local/kafka_2.12-2.1.0/kafka-logs
######################################
#启动kafka
./kafka-server-start.sh -daemon …/config/server.properties
#查看kafka所有topic
./kafka-topics.sh -list -zookeeper 47.12.124.186:2181,47.12.124.186:2182,47.12.124.186:2183
#创建topic
./kafka-topics.sh --create --zookeeper 47.12.124.186:2181,47.12.124.186:2182,47.12.124.186:2183 --replication-factor 3 --partitions 3 --topic test(rf参数副本数,par参数分区数,xxx是topic的名称)创建topic
#查看topic描述
./kafka-topics.sh --describe --zookeeper 47.12.124.186:2181,47.12.124.186:2182,47.12.124.186:2183 --topic test
#发送一条消息
./kafka-console-producer.sh --broker-list 192.168.25.100:9092 --topic test #192.168.25.100为listeners配置的ip
#启动命令行消费者,将消息转储到标准输出
./kafka-console-consumer.sh --bootstrap-server 192.168.25.100:9092 --topic test --from-beginning