1. 从Kafka官网下载最新的Kafka,目前最新版本为0.9.0.1
2. 下载完毕后,上传到Linux服务器,并解压
tar -xzf kafka_2.11-0.9.0.1.tgz
3. 修改Zookeeper服务器配置,并启动
cd kafka_2.11-0.9.0.1 vi config/zookeeper.properties #修改ZooKeeper的数据目录 dataDir=/opt/favccxx/db/zookeeper #配置host.name和advertised.host.name为IP地址,防止通过Java客户端连接时解析为localhost host.name=10.0.10.6 advertised.host.name=10.0.10.6 #启动Zookeeper服务器 ./zookeeper-server-start.sh /opt/favccxx/kafka_2.11-0.9.0.1/config/zookeeper.properties
4.修改Kafka配置,并启动Kafka服务器
vi config/server.properties log.dirs=/opt/favccxx/kafka/kafka-logs #启动Kafka服务器 ./kafka-server-start.sh /opt/favccxx/kafka_2.11-0.9.0.1/config/server.properties
5.创建并查看Topic
cd /opt/favccxx/kafka_2.11-0.9.0.1/bin/ ./kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test Created topic "test". #查看刚才的topic ./kafka-topics.sh --list --zookeeper localhost:2181 test
6. 使用生产者发送消息,每行是一条独立的消息
./kafka-console-producer.sh --broker-list localhost:9092 --topic test This is a message This is My mesage
7. 使用消费者接收消息
./kafka-console-consumer.sh --zookeeper localhost:2181 --topic test --from-beginning This is a message This is My me