美文网首页程序员
kafka的使用(单节点多broker)

kafka的使用(单节点多broker)

作者: 匪_3f3e | 来源:发表于2018-10-29 21:38 被阅读0次

    未安装kafka的请先看https://www.jianshu.com/p/2ec901ebf6b4

    官网介绍

    #复制配置文件
    > cp config/server.properties config/server-1.properties
    > cp config/server.properties config/server-2.properties
    
    #修改配置文件中的信息
    `config/server-1.properties:`
    `broker.id=1`
    `listeners=[PLAINTEXT://:9093](plaintext://:9093)`
    `log.dirs=/tmp/kafka-logs-1`
    
    `config/server-2.properties:`
    `broker.id=2`
    `listeners=[PLAINTEXT://:9094](plaintext://:9094)`
    `log.dirs=/tmp/kafka-logs-2`
    
    #启动kafka
    > bin/kafka-server-start.sh config/server-1.properties &
    ...
    > bin/kafka-server-start.sh config/server-2.properties &
    ...
    
    #创建kafka topic
    > bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 3 --partitions 1 --topic my-replicated-topic
    
    #查看kafka topic
    > bin/kafka-topics.sh --describe --zookeeper localhost:2181 --topic my-replicated-topic
    Topic:my-replicated-topic   PartitionCount:1    ReplicationFactor:3 Configs:
        Topic: my-replicated-topic  Partition: 0    Leader: 1   Replicas: 1,2,0 Isr: 1,2,0
    
    #启动生产者
    #--broker-list:应当把所有kafka都配置进去
    > bin/kafka-console-producer.sh --broker-list localhost:9092 --topic my-replicated-topic
    
    #启动消费者
    > bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --from-beginning --topic my-replicated-topic
    
    

    我的实现

    #生成配置文件
    cp $KAFKA_HOME/config/server.properties  $KAFKA_HOME/config/server-1.properties
    cp $KAFKA_HOME/config/server.properties  $KAFKA_HOME/config/server-2.properties
    cp $KAFKA_HOME/config/server.properties  $KAFKA_HOME/config/server-3.properties
    
    #修改以下配置文件
    #server-1.properties
    broker.id=1
    listeners=PLAINTEXT://:9093
    log.dirs=/Users/david/Cores/apache-flume-1.6.0-cdh5.7.0-bin/logs-1
    
    #server-1.properties
    broker.id=2
    listeners=PLAINTEXT://:9094
    log.dirs=/Users/david/Cores/apache-flume-1.6.0-cdh5.7.0-bin/logs-2
    
    #server-3.properties
    broker.id=3
    listeners=PLAINTEXT://:9095
    log.dirs=/Users/david/Cores/apache-flume-1.6.0-cdh5.7.0-bin/logs-3
    
    #启动zookeeper
    cd $ZK_HOME/bin
    ./zkServer.sh start
    #启动kafka
    cd $KAFKA_HOME/bin
     ./kafka-server-start.sh -daemon  $KAFKA_HOME/config/server-1.properties &
     ./kafka-server-start.sh -daemon  $KAFKA_HOME/config/server-2.properties &
     ./kafka-server-start.sh -daemon  $KAFKA_HOME/config/server-3.properties &
    
    #启动生产者
    ./kafka-console-producer.sh --broker-list localhost:9093,localhost:9094,localhost:9095 --topic my-replicated-topic
    #启动消费者
    ./kafka-console-consumer.sh --zookeeper localhost:2181  --topic my-replicated-topic
    

    关闭kafka

    ./kafka-server-stop.sh   $KAFKA_HOME/config/server-1.properties 
    ./kafka-server-stop.sh   $KAFKA_HOME/config/server-2.properties 
    ./kafka-server-stop.sh   $KAFKA_HOME/config/server-3.properties 
    

    相关文章

      网友评论

        本文标题:kafka的使用(单节点多broker)

        本文链接:https://www.haomeiwen.com/subject/nkzbtqtx.html