整个demo流程均在win10操作系统完成,过程中使用的所有组件都以单机模式安装在本地,整个流程可看作flink版本的helloworld。实现基本功能是在kafka生产者输入一串以空格分隔的字符串,最终计算后得到每个字符串的出现频次。
环境准备
- zookeeper安装:
使用的v3.4.13版本,官网下载安装包,解压缩,修改conf下的zoo_sample.cfg文件,主要注意如下所示
# the directory where the snapshot is stored.
# do not use /tmp for storage, /tmp here is just
# example sakes.
dataDir=E:\BigData\zookeeper-data
# the port at which the clients will connect
clientPort=2181
将dataDir指向本地某个目录,设置客户端端口,这里可默认使用2181。修改完成保存后,cmd窗口中进入bin目录执行启动zk。
zkServer.cmd
- kafka安装:
使用的kafka_2.11-2.1.1版本,同样官网下在压缩包后解压缩,默认可不用修改配置。进入bin\windows目录,cmd窗口中依次执行指令:
kafka-server-start.bat ..\..\config\server.properties
kafka-topics.bat --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test
kafka-console-producer.bat --broker-list localhost:9092 --topic test
kafka-console-consumer.bat --bootstrap-server localhost:9092 --topic test --from-beginning
分别表示:启动kafka、创建topic test、发布消息到test、订阅test消息。此时,在打开的生存者窗口中输入一条消息,将会在消费者窗口展示。
- flink安装:
使用flink-1.7.2版本,同样官网下在压缩包后解压缩,默认可不用修改配置。进入bin目录,cmd窗口执行指令启动即可。
start-cluster.sh<