Chinaunix首页 | 论坛 | 博客
  • 博客访问: 7400575
  • 博文数量: 1756
  • 博客积分: 18684
  • 博客等级: 上将
  • 技术积分: 16232
  • 用 户 组: 普通用户
  • 注册时间: 2010-06-02 10:28
个人简介

啥也没写

文章分类

全部博文(1756)

文章存档

2024年(2)

2023年(44)

2022年(39)

2021年(46)

2020年(43)

2019年(27)

2018年(44)

2017年(50)

2016年(47)

2015年(15)

2014年(21)

2013年(43)

2012年(143)

2011年(228)

2010年(263)

2009年(384)

2008年(246)

2007年(30)

2006年(38)

2005年(2)

2004年(1)

分类: LINUX

2011-12-07 16:00:19

转:http://blog.nosqlfan.com/html/3521.html

是一个日志收集系统,它的特点在于其各部分均是可定制化的,你可以通过简单的配置,将日志收集到不同的地方。

目前开源社区已经贡献了下面一些存储插件:, , ,, , , , , ,  等等。

本文要介绍的是在Fluentd的最新版中已经内置的MongoDB支持。主要通过一个收集Apache日志的例子来说明其使用方法:

机制图解
tumblr_lvpwxvhWvL1r2sums安装

为了完成相关的测试,需要安装下面一些组件:

  • Fluentd with MongoDB Plugin
  • MongoDB
  • Apache (with the Combined Log Format)

在Fluentd的最新安装包中已经包含了MongoDB插件,你也可以用命令

gem install fluent-plugin-mongo

来进行安装

配置

如果你是使用上面的deb/rpm包安装的Fluentd,那么配置文件位置在:/etc/td-agent/td-agent.conf,否则其位置应该在:/etc/fluentd/fluentd.conf

首先我们编辑配置文件中的source来设置日志来源

type tail format apache path /var/log/apache2/access_log tag mongo.apache

其中:

  1. type tail: tail方式是 Fluentd 内置的输入方式,其原理是不停地从源文件中获取新的日志。
  2. format apache: 指定使用 Fluentd 内置的 Apache 日志解析器。
  3. path /var/log/apache2/access_log: 指定日志文件位置。
  4. tag mongo.apache指定tag,tag被用来对不同的日志进行分类

下面再来编辑输出配置,配置日志收集后存储到MongoDB中

# plugin type type mongo # mongodb db + collection database apache collection access # mongodb host + port host localhost port 27017 # interval flush_interval 10s

match标签后面可以跟正则表达式以匹配我们指定的tag,只有匹配成功的tag对应的日志才会运用里面的配置。配置中的其它项都比较好理解,看注释就可以了,其中flush_interval是用来控制多长时间将日志写入MongoDB一次。

测试

用ab工具对Apache进行访问,以产生相应的访问日志以供收集

$ ab -n 100 -c 10

然后我们在MongoDB中就能看到收集到的日志了

$ mongo > use apache > db.access.find() { "_id" : ObjectId("4ed1ed3a340765ce73000001"), "host" : "127.0.0.1", "user" : "-", "method" : "GET", "path" : "/", "code" : "200", "size" : "44", "time" : ISODate("2011-11-27T07:56:27Z") } { "_id" : ObjectId("4ed1ed3a340765ce73000002"), "host" : "127.0.0.1", "user" : "-", "method" : "GET", "path" : "/", "code" : "200", "size" : "44", "time" : ISODate("2011-11-27T07:56:34Z") }




安装:
wget ftp://ftp.ruby-lang.org//pub/ruby/1.9/ruby-1.9.2-p0.tar.gz
tar -zxvf ruby-1.9.2-p0.tar.gz
cd ruby-1.9.2-p0
./configure
make && make install
cd ..

export PATH=/usr/local/bin:$PATH
ruby -v

wget
unzip rubygems-1.8.10.tgz
tar -zxvf rubygems-1.8.10.tgz
cd rubygems-1.8.10
ruby setup.rb
cd ..




gem install fluentd
# install sample configuration file to the directory
fluentd -s
fluentd &
echo '{"json":"message"}' | fluent-cat debug.test

gem install fluent-plugin-mongo
gem install bson_ext

vim  /etc/yum.repos.d/10gen.repo

[10gen]
name=10gen Repository
baseurl=
gpgcheck=0



yum install mongo-10gen mongo-10gen-server
/etc/init.d/monod start


#mongo 进入SHELL


vim /etc/fluentd/fluentd.conf

  type tail
  format apache
  path /var/log/httpd//access_log
  tag mongo.apache

  # plugin type
  type mongo

  # mongodb db + collection
  database apache
  collection access

  # mongodb host + port
  host localhost
  port 27017

  # interval
  flush_interval 10s


ab -n 100 -c 10

mongo
use apache
db.access.find()

查看数据

yum install td-agent[treasuredata] name=TreasureData baseurl= gpgcheck=0
阅读(1458) | 评论(0) | 转发(0) |
0

上一篇:win自动登录

下一篇:google函数搜索!

给主人留下些什么吧!~~