12 月 052014
 

上次说了大数据的实时分析的架构,但是可能你在的公司没有那么大的需求,大数据的架构分析至少需要3台机器。而且上面还跑了N个应用,那么小数据的话,架构可不可以优化呢?通过最近的研究发现,flume+mongo是个不错的组合。服务器只需要一台。

之前一直想把数据存在mysql上,因为之前自己做日志分析的时候就是这么做的,后来发现这个真是太落伍了。看到网上有flume-mongo去处理json格式的消息。瞬间看到了希望,mongo在处理json格式的数据太强大了。而且以后所有的日志可以定义成json格式,方便了日志的管理和统一。让我看到希望,问题可能就是以后mongo上数据大了,会不会有问题,这个有待测试,下面简单介绍下安装方法把。

1:安装flume

http://flume.apache.org/download.html  下载最新版,我一般就直接安装bin版本,解压,即可使用

还要安装java,否则无法使用,在 /etc/profile配置下环境变量

export JAVA_HOME=/home/jdk6/
export FLUME_HOME=/usr/local/flume
export PATH=.:$PATH::$FLUME_HOME/bin

2:安装flume-mongo

下载 https://github.com/leonlee/flume-ng-mongodb-sink

然后需要安装个Apache-meavn。要编译安装下,生成jar包。然后copy到flume的lib下

还有要记住安装下java-mongo的驱动包,我之前没安装,一直启动不起来。

http://central.maven.org/maven2/org/mongodb/mongo-java-driver/

找个http://central.maven.org/maven2/org/mongodb/mongo-java-driver/2.9.3/mongo-java-driver-2.9.3.jar 即可,放在flume的lib下。

3:配置

flume的配置

[root@localhost ~]# cat /usr/local/flume/conf/flume.conf
a1.sources  = r1

a1.sinks =  k1 k2

a1.channels  = c1 c2
#  Describe/configure the source

a1.sources.r1.type  = exec

a1.sources.r1.command  = tail -F /root/host.access.log

# Describe  the sink
a1.sinks.k1.type = logger
a1.sinks.k2.type = org.riderzen.flume.sink.MongoSink
a1.sinks.k2.host = localhost
a1.sinks.k2.port = 27017
a1.sinks.k2.model = single
a1.sinks.k2.collection = test
a1.sinks.k2.db = test

a1.sinks.k2.batch = 100

# Use a  channel which buffers events in memory

a1.channels.c1.type  = memory

a1.channels.c1.capacity  = 100000

a1.channels.c1.transactionCapacity  = 1000

a1.channels.c2.type  = memory

a1.channels.c2.capacity  = 100000

a1.channels.c2.transactionCapacity  = 1000

# Bind the  source and sink to the channel

a1.sources.r1.channels  = c1 c2
a1.sinks.k1.channel  = c1

a1.sinks.k2.channel  = c2

 

这里面的配置可以按照flume的官网和flume-mongo的说明配置。然后通过

flume-ng agent -c conf -f flume.conf  -n a1  -Dflume.root.logger=INFO,console 启动即可。

遗留的问题:

1:tail –f 的形式读取好像官网说会有丢失的可能。有其他更保险的方法么?

2:mongo存储的日志能不能按日期分割可以再优化?

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

(required)

(required)

这个站点使用 Akismet 来减少垃圾评论。了解你的评论数据如何被处理

This website stores cookies on your computer. These cookies are used to provide a more personalized experience and to track your whereabouts around our website in compliance with the European General Data Protection Regulation. If you decide to to opt-out of any future tracking, a cookie will be setup in your browser to remember this choice for one year.

Accept or Deny