kafka broker集群

进入config目录,修改server.properties

broker.id=0
port=9092
host.name=192.168.0.10
zookeeper.contact=192.168.0.1:2181,192.168.0.2:2181,192.168.0.3:2181
log.dirs=/home/www/kafka-logs

不同集群broker.id 和host.name 不一样,根据实际情况配置。

修改生产者配置

 broker.list=192.168.0.1:9092,192.168.0.2:9092,192.168.0.3:9092
 producer.type=async

修改消费者配置:

zookeeper.contact=192.168.0.1:2181,192.168.0.2:2181,192.168.0.3:2181

启动每台服务器的kafka:

> ./kafka-server-start.sh ../config/server.properties &

测试集群

创建一个topic

> ./kafka-topics.sh --create --zookeeper 192.168.0.1:2181 --replication-factor 3 --partitions 1 --topic test-replicated-topic

查看创建的topic

> bin/kafka-topics.sh --describe --zookeeper 192.168.0.1:2181 --topic test-replicated-topic
Topic:test-replicated-topic	PartitionCount:1	ReplicationFactor:3	Configs:
Topic: test-replicated-topic	Partition: 0	Leader: 1	Replicas: 1,2,0	Isr: 1,2,0

查看集群情况:

>bin/kafka-topics.sh --describe --zookeeper 192.168.0.2:2181 --topic test-replicated-topic
>bin/kafka-topics.sh --describe --zookeeper 192.168.0.3:2181 --topic test-replicated-topic

发现都能看到test-replicated-topic。

启动生产者 发送消息 

kafka-console-producer.sh --broker-list 192.168.0.1:9092 --topic test-replicated-topic

启动消费者 发现都能接收到信息 

kafka-console-consumer.sh --zookeeper 192.168.0.2:2181 --topic test-replicated-topic --from-beginning
kafka-console-consumer.sh --zookeeper 192.168.0.3:2181 --topic test-replicated-topic --from-beginning

 

配置完成。

你可能感兴趣的:(kafka)