Skip to content

kafka简单安装

Jaimin Pan edited this page Jan 14, 2016 · 5 revisions

kafka简单安装

kafka下载:https://www.apache.org/

分别在三台服务器上安装kafka: tar zxvf kafka_2.10-0.8.1.tgz

修改每台服务器的config/server.properties
broker.id: 唯一,填数字,本文中分别为132/133/134
host.name:唯一,填服务器IP

zookeeper.connect=192.168.40.134:2181,192.168.40.132:2181,192.168.40.133:2181

先启动zookeeper服务: bin/zkServer.sh start (本文中zookeeper为独立安装,具体过程在此不细述) 再在每台机器上执行: bin/kafka-server-start.sh config/server.properties

创建topic:

bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 3 --partitions 1 --topic mykafka

查看Topic:

bin/kafka-topics.sh --list --zookeeper localhost:2181

显示Topic:mykafka

查看详细信息:

bin/kafka-topics.sh --describe --zookeeper 192.168.40.132:2181

  Topic:mykafka	PartitionCount:1	ReplicationFactor:3	Configs:
  Topic: mykafka	Partition: 0	Leader: 133	Replicas: 133,134,132	Isr: 134

发送消息:

bin/kafka-console-producer.sh --broker-list 192.168.40.134:9092 --topic mykafka
23423
^C
bin/kafka-console-producer.sh --broker-list 192.168.40.134:9092 --topic mykafka
4533

接收消息:

bin/kafka-console-consumer.sh --zookeeper 192.168.40.133:2181 --topic mykafka --from-beginning

注意事项

config/server.properties 中的 host.name 如果没有显示指定,在consumer使用的时候会报 kafka.common.FailedPayloadsError 错误

Clone this wiki locally