• kafka安装linux版


    安装实战

    kafka安装包下载(注意:这里选择的安装包是2.11系列的1.1.0版本的)

    wget https://archive.apache.org/dist/kafka/1.1.0/kafka_2.11-1.1.0.tgz

    安装启动服务

    首先,我们需要下载并且安装zk和kafka,并且将这两个服务启动:

    解压缩文件
    tar zxvf kafka_2.11-1.1.0.tgz
    cd kafka_2.11-1.1.0/
    启动zk
    bin/zookeeper-server-start.sh -daemon config/zookeeper.properties
    
    检查zk是否启动成功
    netstat -tunpl|grep 2181
    tcp6       0      0 :::2181                 :::*                    LISTEN      2877/java 
    启动kafka
    常规模式启动kafka
    bin/kafka-server-start.sh -daemon config/server.properties

     进程守护模式启动kafka

     nohup bin/kafka-server-start.sh config/server.properties >/dev/null 2>&1 & 

    检查kafka是否启动成功
    netstat -tunpl|grep 9092
    tcp6       0      0 :::9092                 :::*                    LISTEN      3164/java 

    命令方式验证

    1. 运行 producer

    打开一个窗口,输入如下的指令,启动生产者:

    bin/kafka-console-producer.sh --broker-list localhost:9092 --topic test

    2. 运行 consumer

    新启动一个新的窗口,输入如下的指令,启动消费者:

    bin/kafka-console-consumer.sh --zookeeper localhost:2181 --topic test --from-beginning             (可能不成功,换下面红色的启动方式)

    3. 测试消息传递

    在producer中写信息, 从consumer中可以看到结果, 如下:

    生产者端:

    bin/kafka-console-producer.sh --broker-list localhost:9092 --topic test
    >i like you
    [2018-12-07 01:55:56,427] WARN [Producer clientId=console-producer] Error while fetching metadata with correlation id 1 : {test=LEADER_NOT_AVAILABLE} (org.apache.kafka.clients.NetworkClient)
    [2018-12-07 01:55:56,532] WARN [Producer clientId=console-producer] Error while fetching metadata with correlation id 3 : {test=LEADER_NOT_AVAILABLE} (org.apache.kafka.clients.NetworkClient)
    >hello
    >world
    >hello kafka
    >

    消费者端:

    bin/kafka-console-consumer.sh --zookeeper localhost:2181 --topic test --from-beginning
    Using the ConsoleConsumer with old consumer is deprecated and will be removed in a future major release. Consider using the new consumer by passing [bootstrap-server] instead of [zookeeper].
    i like you
    hello
    world
    hello kafka

    但是这是一种比较老使用zk启动消费端的方式,后序版本会废弃,官方推荐新的使用方式如下:

    bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test --from-beginning
    i like you
    hello
    world
    hello kafka
    hello

    上面的消费方式为从头开始消费的,因此之前生产者发送过的历史消息,后启动的消费者仍然可以接收到。

    这里我们再次测试一下只接收新的消息。

    bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test

    生产者端输入:

    i like you
    hello
    world
    hello kafka
    hello
    -------
    louxj424 #新输入的内容

    消费者端就只查看到一条消息:

    louxj424

     zookeeper和kafka的关闭

    ./bin/zookeeper-server-stop.sh

     bin/kafka-server-stop.sh

    参考:https://www.jianshu.com/p/94349568533c

    https://blog.csdn.net/qq_19524879/article/details/82848556 

  • 相关阅读:
    51nod1376 最长递增子序列的数量
    51nod1201 整数划分
    51nod1202 子序列个数
    51nod 博弈论水题
    51nod1052 最大M子段和
    51nod1678 lyk与gcd
    51nod1262 扔球
    BZOJ2763, 最短路
    吃西瓜 最大子矩阵 三维的。 rqnoj93
    noip2015 信息传递 强连通块
  • 原文地址:https://www.cnblogs.com/51python/p/10870308.html
Copyright © 2020-2023  润新知