准备工作:安装好zookeeper,kafka,flume
1.首先要有三台zookeeper启动好的zookeeper集群,启动起来
可以自己设置shell脚本一键启动(路径问题自己解决)
cat /export/server/onekey/zk/slave | while read line do { echo $line ssh $line "source /etc/profile;nohup zkServer.sh start >/dev/null 2>&1 &" }& wait done
2.编写日志文件.也是用shell脚本不断更新文件作为flume的采集源
for((i=0;i<=10000;i++)); do echo "hello flume "+$i >>/export/data/flume/click_log/data.log; done
3.写好flume采集配置信息 exec.conf
a1.sources = r1 a1.channels = c1 a1.sinks = k1 a1.sources.r1.type = exec a1.sources.r1.command = tail -F /export/data/flume/click_log/data.log a1.sources.r1.channels = c1 a1.sources.r1.interceptors = i1 a1.sources.r1.interceptors.i1.type = cn.itcast.realtime.flume.AppInterceptor$AppInterceptorBuilder a1.sources.r1.interceptors.i1.appId = 1 a1.channels.c1.type=memory a1.channels.c1.capacity=10000 a1.channels.c1.transactionCapacity=100 a1.sinks.k1.type = org.apache.flume.sink.kafka.KafkaSink a1.sinks.k1.topic = myTest a1.sinks.k1.brokerList = wy-1:9092 a1.sinks.k1.requiredAcks = 1 a1.sinks.k1.batchSize = 20 a1.sinks.k1.channel = c1
4.在kafka中创建conf配置的topic
进入到kafka bin目录,执行:
./kafka-topics.sh --create --zookeeper zk01:2181 --topic myTest --partitions 6 --replication-factor 2
5.创建好topic后,启动kafka服务端,kafka客户端
服务端启动broker, 客户端用来消费broker中的数据
服务端启动命令:
./kafka-server-start.sh /export/servers/kafka/config/server.properties
客户端启动命令:
./kafka-console-consumer.sh --zookeeper wy-1:2181 --from-beginning --topic myTest
6.启动flume服务,开始采集数据
./flume-ng agent -n a1 -c conf -f /export/servers/flume/myconfig/exec.conf -Dflume.root.logger=INFO,console