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

╄→гoц情女王★ 提交于 2019-11-27 05:09:32

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错误: 

        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,重启服务就好了。

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!