安装配置Kafka
2017-07-03 本文已影响77人
kker
安装Java
- 下载JDK http://www.oracle.com/technetwork/java/javase/downloads/index.html
- chmod +x jdk-8u131-linux-x64.rpm
- cd /usr/java (进入要将Java安装到的目录,如果没有请自己创建)
- rpm -ivh ~/jdk-8u131-linux-x64.rpm
- echo "export JAVA_HOME=/usr/java/jdk1.8.0_131" >> /etc/profile
安装Kafka
- 下载 https://www.apache.org/dyn/closer.cgi?path=/kafka/0.11.0.0/kafka_2.11-0.11.0.0.tgz
- tar xzf kafka_2.11-0.11.0.0.tgz, mv kafka_2.11-0.11.0.0 /opt/
- export KAFKA_HOME=/opt/kafka_2.11-0.11.0.0
- export PATH=$PATH:$KAFKA_HOME/bin
创建一个单节点单broker集群
- 启动zookeeper服务:bin/zookeeper-server-start.sh config/zookeeper.properties
- 启动Kafka Broker:bin/kafka-server-start.sh config/server.properties
测试
- 创建一个Topic: bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic kafkatopic
- 查看topic列表: bin/kafka-topics.sh --list --zookeeper localhost:2181
- 起一个发往 kafkatopic 的生产者:bin/kafka-console-producer.sh --broker-list localhost:9092 --topic kafkatopic,随便输入写数据作为消息发送
- 起一个消费者:bin/kafka-console-consumer.sh --zookeeper localhost:2181 --topic kafkatopic --from-beginning