1.下载kafka

       进入kafka官网:http://kafka.apache.org/downloads.html

        选择Binary downloads下载【注:Source download需要编译才能使用

        以下用kafka_2.10-0.9.0.0.tgz版本

2.解压

        tar -xzvfkafka_2.10-0.9.0.0.tgz

        cd kafka_2.10-0.9.0.0
        目录:

                /bin 启动和停止命令等。

/config 配置文件 

                /libs 类库

3.启动和停止

        启动Zookeeper server:

                bin/zookeeper-server-start.sh config/zookeeper.properties &

                &是为了能退出命令行

        启动Kafka server:

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

        停止Kafka server:

                bin/kafka-server-stop.sh

        停止Zookeeper server: 

                bin/zookeeper-server-stop.sh

4.单机连通性测试 

        运行producer:

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

                早版本的Kafka,--broker-list localhost:9092需改为--zookeeper localhost:2181 

        运行consumer:

                bin/kafka-console-consumer.sh --zookeeper localhost:2181 --topic test --from-beginning

        在producer端输入字符串并回车,查看consumer端是否显示。

5.分布式连通性测试 

        Zookeeper Server, Kafka Server, Producer都放在服务器server1上,ip地址为192.168.1.10 
Consumer放在服务器server2上,ip地址为192.168.1.12。

        分别运行server1的producer和server2的consumer:

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

                bin/kafka-console-consumer.sh --zookeeper 192.168.1.10:2181 --topic test --from-beginning

        在producer的console端输入字符串,consumer报Connection refused错误: 

【Kafka】Kafka在Linux下安装和测试

        broker, producer和consumer都注册到zookeeper上,producer和consumer的参数明确指定。问题出在broker的配置文件server.properties上:

                # Hostname the broker will bind to. If not set, the server will bind to all interfaces
                #host.name=localhost

        host名称没有指定,就是127.0.0.1,consumer去broker拿数据就有问题。设置为192.168.1.10,重启服务就好了

相关文章:

  • 2021-05-18
  • 2021-10-06
  • 2022-12-23
  • 2021-07-09
  • 2022-01-15
  • 2018-08-15
  • 2018-08-15
猜你喜欢
  • 2022-12-23
  • 2021-12-19
  • 2021-09-05
  • 2021-06-13
  • 2021-07-02
  • 2021-08-15
相关资源
相似解决方案