刚接触一些Apache Kafka的内容,用了两天时间研究了一下,仅以此文做相关记录,以供学习交流。
一.配置
克隆出三台虚拟机,我这三台虚拟机的ip分别为
192.168.128.129
192.168.128.132
192.168.128.133
在129这个服务器上找到 kafka目录/config/server.properties文件,做如下修改
broker.id=129
host.name=192.168.128.129
zookeeper.connection=192.168.128.129:2181
这里只用到了一个zookeeper,并部署到了129上,没有用集群,当然也可以部署到其他机器上。
132上的kafka配置
</pre><pre code_snippet_id="398663" snippet_file_name="blog_20140619_3_238600" name="code" class="html">broker.id=132
host.name=192.168.128.132
zookeeper.connection=192.168.128.129:2181
133上的kafka配置
broker.id=133
host.name=192.168.128.133
zookeeper.connection=192.168.128.129:2181
二.测试
在129上启动zookeeper服务器
bin/zkServer.sh start conf/zoo.cfg
启动129,132,133上的kafka服务
[root@bogon kafka_2.8.0-0.8.1]# nohup bin/kafka-server-start.sh config/server.properties &
在任意机器上建一个topic,因为有三个kafka服务,所以这里replication-factor设为3
停掉132的kafka,再次查看topics,此时可用的Isr为129和133,leader依然为129,因为129的kafka没有被停过,所以没有重新选举leader
bin/kafka-topics.sh --create --zookeeper 192.168.128.129:2181 --replication-factor 3 -partitions 1 --topic 3test
Created topic "3test".
查看topic,此时的leader kafka为129,repicas:集群里有三个kafka,Isr:正常使用的kafka
bin/kafka-topics.sh --describe --zookeeper 192.168.128.129:2181
Topic:3test PartitionCount:1 ReplicationFactor:3 Configs:
Topic: 3test Partition: 0 Leader: 129 Replicas: 129,132,133 Isr: 129,132,133
在133这台机器上开启一个producer,往132这个kafka发消息
[root@slave-03 kafka_2.8.0-0.8.1]# bin/kafka-console-producer.sh --broker-list 192.168.128.132:9092 --topic 3test
this is a message to 132 broker
re?
[root@slave-02 kafka_2.8.0-0.8.1]# bin/kafka-topics.sh --describe --zookeeper 192.168.128.129:2181
Topic:3test PartitionCount:1 ReplicationFactor:3 Configs:
Topic: 3test Partition: 0 Leader: 129 Replicas: 129,132,133 Isr: 129,133
在129上开启一个consumer
[root@bogon kafka_2.8.0-0.8.1]# bin/kafka-console-consumer.sh --zookeeper 192.168.128.129:2181 --topic 3test --from-beginning
this is a message to 132 broker
re?
kafka集群测试通过