Kakfa在windows上的启动使用教程
Kakfa在windows上的启动使用教程
本教程基于版本kafka_2.11-1.0.0,在windows上操作使用,请使用Git-Bash客户端,演示了Kafka在控制台使用命令完成了一次简单的示例,实现了启动服务器,生产者发送发送消息 ,消费者消费信息等。
1. 启动服务器
启动zookper服务器
bin/windows/zookeeper-server-start.bat config/zookeeper.properties
启动kafka服务器
bin/windows/kafka-server-start.bat config/server.properties
2. 创建主题
创建一个test主题
bin/windows/kafka-topics.bat --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test
查看主题列表
bin/windows/kafka-topics.bat --list --zookeeper localhost:2181
3. 使用生产者发送消息
启动生产者发送消息
bin/windows/kafka-console-producer.bat --broker-list localhost:9092 --topic test
4. 使用消费者获取消息
bin/windows/kafka-console-consumer.bat --bootstrap-server localhost:9092 --topic test --from-beginning
5. 设置多代理群集
首先,我们为每个代理创建一个配置文件(在Windows上使用copy命令代替):
复制一份文件 config/server.properties 到 config/server-1.properties
复制一份文件 config/server.properties 到 config/server-2.properties
我们已经有Zookeeper和我们的单节点了,所以我们只需要启动两个新的节点:
bin/windows/kafka-server-start.bat config/server-1.properties &
bin/windows/kafka-server-start.bat config/server-2.properties &
现在创建一个复制因子为三的新主题:
bin/windows/kafka-topics.bat --create --zookeeper localhost:2181 --replication-factor 3 --partitions 1 --topic my-replicated-topic
查看运行“描述主题”命令:谁是领导
bin/windows/kafka-topics.bat --describe --zookeeper localhost:2181 --topic my-replicated-topic
bin/windows/kafka-topics.bat --describe --zookeeper localhost:2181 --topic test
发送消息 到主题
bin/windows/kafka-console-producer.bat --broker-list localhost:9092 --topic my-replicated-topic
消费消息
bin/windows/kafka-console-consumer.bat --bootstrap-server localhost:9092 --from-beginning --topic my-replicated-topic
现在我们来测试一下容错。broker1是作为领导者,所以让我们杀了它:
wmic process where "caption = 'java.exe' and commandline like '%server-1.properties%'" get processid ProcessId
获取进程id:6016, 替换 6016干掉
taskkill /pid 6016 /f
评论