前期准备
- centos7 操作系统
- 安装kafka需要jdk,故需要先安装java
- 本文仅做测试阶段使用,下一章节讲解详细配置
kafka下载
官网下载地址:http://kafka.apache.org/downloads
kafka下载.png
wget https://www.apache.org/dyn/closer.cgi?path=/kafka/2.2.0/kafka_2.11-2.2.0.tgz
解压
tar -zxvf kafka_2.11-2.2.0.tgz
mv kafka_2.11-2.2.0 /usr/local/kafka
cd /usr/local/kafka
启动
启动zookeeper:
bin/zookeeper-server-start.sh config/zookeeper.properties
启动kafka:
bin/kafka-server-start.sh config/server.properties
消息测试
创建一个topic叫test:
bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test
查看topic :
bin/kafka-topics.sh -list -zookeeper localhost:2181
开启一个shell启动生产者:
bin/kafka-console-producer.sh --broker-list localhost:9092 --topic test
生产者.png
开启一个shell启动一个消费者:
bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test --from-beginning
消费者.png
kafka远程连接
- 修改配置文件 (位置 ./config/server.properties)
- 31行的注释去掉 -> listeners=PLAINTEXT://:9092
- 36行的注释去掉 -> 把advertised.listeners值改为PLAINTEXT://运行kafka的服务器ip:9092
30 # listeners = PLAINTEXT://your.host.name:9092
31 listeners=PLAINTEXT://:9092
32
33 # Hostname and port the broker will advertise to producers and consumers. If not set,
34 # it uses the value for "listeners" if configured. Otherwise, it will use the value
35 # returned from java.net.InetAddress.getCanonicalHostName().
36 advertised.listeners=PLAINTEXT://192.168.3.213:9092
- 后台运行kafka 与 zookeeper
bin/kafka-server-start.sh config/server.properties 1>/dev/null 2>&1 &
bin/zookeeper-server-start.sh config/zookeeper.properties 1>/dev/null 2>&1 &
网友评论