1. 从下载最新的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.1vi config/zookeeper.properties #修改ZooKeeper的数据目录dataDir=/opt/favccxx/db/zookeeper#配置host.name和advertised.host.name为IP地址,防止通过Java客户端连接时解析为localhosthost.name=10.0.10.6advertised.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 testCreated topic "test".#查看刚才的topic./kafka-topics.sh --list --zookeeper localhost:2181test
6. 使用生产者发送消息,每行是一条独立的消息
./kafka-console-producer.sh --broker-list localhost:9092 --topic testThis is a messageThis is My mesage
7. 使用消费者接收消息
./kafka-console-consumer.sh --zookeeper localhost:2181 --topic test --from-beginningThis is a messageThis is My me