Flume入门教程-简单案例
1.下载安装
- 官方网站:http://flume.apache.org/
- http://mirror.bit.edu.cn/apache/flume/1.6.0/apache-flume-1.6.0-bin.tar.gz
- tar -zxvf apache-flume-1.6.0-bin.tar.gz
2.修改配置
重命名flume-conf.properties.template文件为simple.conf,并修改为以下内容
- Agent名称定义为agent.
- Source:可以理解为输入端,定义名称为s1
- channel:传输频道,定义为c1,设置为内存模式
- sinks:可以理解为输出端,定义为sk1,
- agent.sources = s1
- agent.channels = c1
- agent.sinks = sk1
- #设置Source的内省为netcat 端口为5678,使用的channel为c1
- agent.sources.s1.type = netcat
- agent.sources.s1.bind = localhost
- agent.sources.s1.port = 5678
- agent.sources.s1.channels = c1
- #设置Sink为logger模式,使用的channel为c1
- agent.sinks.sk1.type = logger
- agent.sinks.sk1.channel = c1
- #设置channel信息
- agent.channels.c1.type = memory #内存模式
- agent.channels.c1.capacity = 1000
- agent.channels.c1.transactionCapacity = 100 #传输参数设置。
3.启动Agent
- bin/flume-ng agent -c conf -f conf/simple.conf --name agent -Dflume.root.logger=INFO,console
4.发送测试数据
- telnet localhost 5678
- hello,world.
5.验证数据接收
验证flume是否接收到了数据
6.简单优化配置:
修改flume-env.sh,设置JDK版本,Flume1.6.0需要JDK1.6+
export JAVA_HOME=/opt/jdk1.7/jdk1.7.0_45/
设置内存相关参数
JAVA_OPTS="-Xms8192m -Xmx8192m -Xss256k -Xmn2g -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -XX:-UseGCOverheadLimit"
7.其他配置案例
使用命令行模式Tail读取日志文件配置
- agent.sources = s1
- agent.channels = c1
- agent.sinks = sk1
- #设置Tail方式跟踪日志内容
- agent.sources.s1.type = exec
- agent.sources.s1.command = tail -F /usr/local/logstash-1.4.2/new_log.2015-03-26.txt
- agent.sources.s1.channels = c1
- agent.sinks.sk1.type = logger
- agent.sinks.sk1.channel = c1
- #In Memory !!!
- agent.channels.c1.type = memory
- agent.channels.c1.capacity = 10004
- agent.channels.c1.transactionCapacity = 100
设置跟踪目录方式
- agent.sources = s1
- agent.channels = c1
- agent.sinks = sk1
- #设置spooldir
- agent.sources.s1.type = spooldir
- agent.sources.s1.spoolDir = /usr/local/logstash-1.4.2/logs
- agent.sources.s1.fileHeader = true
- agent.sources.s1.channels = c1
- agent.sinks.sk1.type = logger
- agent.sinks.sk1.channel = c1
- #In Memory !!!
- agent.channels.c1.type = memory
- agent.channels.c1.capacity = 10004
- agent.channels.c1.transactionCapacity = 100