`
qingwei201314
  • 浏览: 163297 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

Kafka zookeeper 集群

 
阅读更多

一、部署zookeeper集群

1. 准备三台服务器,IP分别为: 192.168.86.130,192.168.86.131,192.168.86.132.
2.下载zookeeper压缩包,解压,在conf目录下增加zoo.cfg文件,文件内容可参考zoo_sample.cfg. 具体内容如下:

tickTime=2000

dataDir=/usr/local/zookeeper-3.6.2/data

clientPort=2181

initLimit=5

syncLimit=2

server.1=192.168.86.130:2888:3888

server.2=192.168.86.131:2888:3888

 

server.3=192.168.86.132:2888:3888
3. 分别启动三台zookeeper服务器: bin/zkServer.sh start
二、部署kafka集群。
1.kafka集群利用搭建好的zookeeper集群。
2.分别在三台机器上解压kafka的压缩包。
3.修改config/server.properties文件,增加以下容,注意有些属性在文件中已有,不能重复:
broker.id=130 #brokerId 每台机器需要设置不同的值。
offsets.topic.replication.factor=3 transaction.state.log.replication.factor=3 transaction.state.log.min.isr=2

4. 分别启动三台服务器:nohup bin/kafka-server-start.sh config/server.properties &
5. 利用JAVA客户端生产消息:
5.1 在工程的pom.xml文件中加入以下内容:

 

<dependency>
    <groupId>org.apache.kafka</groupId>
    <artifactId>kafka-clients</artifactId>
    <version>2.6.0</version>
</dependency>

5.2 编写生产消息的代码:

public static void main(String[] args) {
    Properties props = new Properties();
props.put("bootstrap.servers", "192.168.86.130:9092,192.168.86.131:9092,192.168.86.132:9092");
props.put("acks", "all");
props.put("key.serializer", "org.apache.kafka.common.serialization.StringSerializer");
props.put("value.serializer", "org.apache.kafka.common.serialization.StringSerializer");

Producer<String, String> producer = new KafkaProducer<>(props);
    for (int i = 120; i < 130; i++)
        producer.send(new ProducerRecord<String, String>("kevin-topic-5", Integer.toString(i), Integer.toString(i)));

producer.close();

}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics