flume小试牛刀(5)


1:项目背景:我们要做一个搜索框的搜索预测,就像百度的框一样,输出想要查询的内容的时候下面会有提示,我们想要实现这个功能,首先要做的事就是收集到搜索框输入查询HTTP的日志,然后存入redis数据库,我们在这儿实现的就是如何用flume实现收集日志的这个功能。

2:搜索预测项目部署到了tomcat上,先进去到tomcatbin目录里面,

然后执行. /startup.shtomcat服务启起来,这次实际上在更改一下上次的实现方式,前一次是在conf目录下的servce.xml里面配置的:我们配置的是每秒钟产生一次,当我们不从搜索框里键入东西的时候就不会产生文件,同时我们还配置了日志文件的路径,比如:/home/robby/tmp/log/

3:我们现在在/home/robby/tmp/log/目录下建一个叫flumelog的目录,我们把/home/robby/tmp/log/目录下产生的非空的文件放到里面,用一下命令

find /home/robby/tmp/log/localhost*.txt -size +0c -exec mv {} /home/robby/tmp/log/flumelog/ \;

意思:把大小大于零的文件移动到flumelog目录下

然后我们把这条命令写成一个定时任务

crontab -e

* * * * * find /home/robby/tmp/log/localhost*.txt -size +0c -exec mv {} /home/robby/tmp/log/flumelog/ \;

意思:每分钟执行一次这个命令。

/root/.bashrc 里面flume/bin的路径的配置,我们就可以在任意的目录里面使用flume 

4:新建一个目录叫demo

在目录demo 下新建一个目录叫flume

然后把我们的r.sh test.cf的文件放到里面

test.cf的内容如下:

test.sources=so1//我们的agent的名字叫testagentsourceso1

test.sinks=si1//agentsinksi1

test.channels=c1//agentchannelc1

 

#source

test.sources.so1.type=spooldir 

test.sources.so1.spoolDir=/home/robby/tmp/log/flumelog

 

test.sources.so1.interceptors=i1

test.sources.so1.interceptors.i1.type=regex_filter//拦截内容,用正则表达式搞定

test.sources.so1.interceptors.i1.regex=.*sug.jsp?query.*//注意?是由特殊的符号

#sink

test.sinks.si1.type=hdfs

test.sinks.si1.path=/flume/log

test.sinks.si1.hdfs.fileType=DataStream//指定日志格式为文本格式

#channel

test.channels.c1.type=memory

test.channels.c1.capacity=1000

test.channels.c1.transactionCapacity=100

test.sources.so1.channels=c1

test.sinks.si1.channel=c1//把三个关联起来

r.sh的内容如下:

bin/flume-ng agent --conf-file test.cf --name test -Dfluem.root.logger=INFO,console

5:把前面写的关于搜索预测的mapreduce任务的打成jar包,

然后写个执行的脚本文件:

vi mp.sh

hadoop fs -rmr /outout/

hadoop jar mapr.jar org.robby.mr.count.WordCount /flume/log /output

6:同样我们的网站还是发布在tomcat  

Ok了。

 


你可能感兴趣的:(flume小试牛刀(5))