# flume-ng指令
commands:
help display this help text
agent run a Flume agent
avro-client run an avro Flume client
version show Flume version info
global options:
--conf,-c <conf> 使用 <conf> 目录下的配置
--classpath,-C <cp> 添加 classpath
--dryrun,-d 并没有开始Flume,只是打印命令
--plugins-path <dirs> colon-separated list of plugins.d 目录. 查看 plugins.d 用户指南的更多细节. Default: $FLUME_HOME/plugins.d
-Dproperty=value 设置一个Java系统属性的值
-Xproperty=value 设置一个Java -x 选项
agent options:
--name,-n <name> 这个Agent的名称(必需)
--conf-file,-f <file> 指定一个配置文件 (如果有 -z 可以缺失)
--zkConnString,-z <str> 指定使用的ZooKeeper的链接 (如果有 -f 可以缺失)
--zkBasePath,-p <path> 指定agent config 在 ZooKeeper Base Path
--no-reload-conf 如果改变不重新加载配置文件
--help,-h display help text
avro-client options:
--rpcProps,-P <file> 远程客户端与服务器链接参数的属性文件
--host,-H <host> hostname to which events will be sent
--port,-p <port> port of the avro source
--dirname <dir> directory to stream to avro source
--filename,-F <file> text file to stream to avro source (default: std input)
--headerFile,-R <file> 每个新的一行数据都会有的头信息key/value
--help,-h display help text
其中--rpcProps 或 --host 和 --port 必须制定一个。
# 新建hdfs目录并设置权限
sudo -u hdfs hdfs dfs -mkdir /flume
sudo -u hdfs hdfs dfs -chown root:root /flume
# 配置flume.conf, vi ./flume.conf
agent1.sources = tail_source1
agent1.channels = memory_channel1
agent1.sinks = hdfs_sink1
agent1.sources.tail_source1.type = exec
agent1.sources.tail_source1.command = tail -F /var/log/secure
agent1.sources.tail_source1.channels = memory_channel1
agent1.channels.memory_channel1.type = memory
agent1.channels.memory_channel1.capacipy = 1000
agent1.sinks.hdfs_sink1.type = hdfs
agent1.sinks.hdfs_sink1.channel = memory_channel1
agent1.sinks.hdfs_sink1.hdfs.path = hdfs://hadoop201:8020/flume
agent1.sinks.hdfs_sink1.hdfs.filePrefix = events-
agent1.sinks.hdfs_sink1.hdfs.round = true
agent1.sinks.hdfs_sink1.hdfs.roundValue = 10
agent1.sinks.hdfs_sink1.hdfs.roundUnit = minute
# 上面配置详解
Properties Name Description
agent1 用来收集日志信息的 agent 节点名称
agent1.source 需要收集的信息源,名字:tail_source1
agent1.sinks 日志需要被收集到此处,名字:hdfs_sink1。
agent1.channels 日志的收集需要通过此管道,名字:memory_channel1。
tail_source1.type 定义 source 的类型,此处 exec 代表数据源是 exec 命令
tail_source1.command 定义具体命令,此处是对文件/var/log/secure 做 tail
hdfs_sink1.type 数据目的地的类型,此处是将数据存放在 hdfs 中。
hdfs_sink1.channel 定义和 source 相关联的管道。
hdfs_sink1.hdfs.path 数据存放在 hdfs 中的位置。
hdfs_sink1.hdfs.filePrefix 收集到的数据存放的文件以此为前缀。
hdfs_sink1.hdfs.round, 定义在 hdfs 中生成的文件的时间戳。此处代表将 hdfs 中的文件的时间戳,向下取整到上一个十分钟内。
hdfs_sink1.hdfs.roundValue, 比如说,在 2012 年 6 月 12 号上午 11:54:34 生成的事件,在 hdfs 中生成的路径将是/flume/events/2012-06-12/1150/00。
hdfs_sink1.hdfs.roundUnit
# 启动Flume Agent
$ flume-ng agent \
--conf-file ./flume.conf \
--name agent1 \
$ hadoop fs -ls /flume
commands:
help display this help text
agent run a Flume agent
avro-client run an avro Flume client
version show Flume version info
global options:
--conf,-c <conf> 使用 <conf> 目录下的配置
--classpath,-C <cp> 添加 classpath
--dryrun,-d 并没有开始Flume,只是打印命令
--plugins-path <dirs> colon-separated list of plugins.d 目录. 查看 plugins.d 用户指南的更多细节. Default: $FLUME_HOME/plugins.d
-Dproperty=value 设置一个Java系统属性的值
-Xproperty=value 设置一个Java -x 选项
agent options:
--name,-n <name> 这个Agent的名称(必需)
--conf-file,-f <file> 指定一个配置文件 (如果有 -z 可以缺失)
--zkConnString,-z <str> 指定使用的ZooKeeper的链接 (如果有 -f 可以缺失)
--zkBasePath,-p <path> 指定agent config 在 ZooKeeper Base Path
--no-reload-conf 如果改变不重新加载配置文件
--help,-h display help text
avro-client options:
--rpcProps,-P <file> 远程客户端与服务器链接参数的属性文件
--host,-H <host> hostname to which events will be sent
--port,-p <port> port of the avro source
--dirname <dir> directory to stream to avro source
--filename,-F <file> text file to stream to avro source (default: std input)
--headerFile,-R <file> 每个新的一行数据都会有的头信息key/value
--help,-h display help text
其中--rpcProps 或 --host 和 --port 必须制定一个。
# 新建hdfs目录并设置权限
sudo -u hdfs hdfs dfs -mkdir /flume
sudo -u hdfs hdfs dfs -chown root:root /flume
# 配置flume.conf, vi ./flume.conf
agent1.sources = tail_source1
agent1.channels = memory_channel1
agent1.sinks = hdfs_sink1
agent1.sources.tail_source1.type = exec
agent1.sources.tail_source1.command = tail -F /var/log/secure
agent1.sources.tail_source1.channels = memory_channel1
agent1.channels.memory_channel1.type = memory
agent1.channels.memory_channel1.capacipy = 1000
agent1.sinks.hdfs_sink1.type = hdfs
agent1.sinks.hdfs_sink1.channel = memory_channel1
agent1.sinks.hdfs_sink1.hdfs.path = hdfs://hadoop201:8020/flume
agent1.sinks.hdfs_sink1.hdfs.filePrefix = events-
agent1.sinks.hdfs_sink1.hdfs.round = true
agent1.sinks.hdfs_sink1.hdfs.roundValue = 10
agent1.sinks.hdfs_sink1.hdfs.roundUnit = minute
# 上面配置详解
Properties Name Description
agent1 用来收集日志信息的 agent 节点名称
agent1.source 需要收集的信息源,名字:tail_source1
agent1.sinks 日志需要被收集到此处,名字:hdfs_sink1。
agent1.channels 日志的收集需要通过此管道,名字:memory_channel1。
tail_source1.type 定义 source 的类型,此处 exec 代表数据源是 exec 命令
tail_source1.command 定义具体命令,此处是对文件/var/log/secure 做 tail
tail_source1.channels 数据传输的管道,此处的管道名称应该和 sink 相同。从而将 source、sink 通过 channels 进行连接。
memory_channel1.type 管道类型,代表事件存储的方式。source 产生事件,sink 移除事件,以此代表数据传输完成。目前 Flume 支持 6 种 channel。此处是 momery,代表事件是存在内存里
memory_channel1.capacity 管道里可以存放的最多的事件数目。此处代表 memory_channel1 最多可存放 1000 个事件。hdfs_sink1.type 数据目的地的类型,此处是将数据存放在 hdfs 中。
hdfs_sink1.channel 定义和 source 相关联的管道。
hdfs_sink1.hdfs.path 数据存放在 hdfs 中的位置。
hdfs_sink1.hdfs.filePrefix 收集到的数据存放的文件以此为前缀。
hdfs_sink1.hdfs.round, 定义在 hdfs 中生成的文件的时间戳。此处代表将 hdfs 中的文件的时间戳,向下取整到上一个十分钟内。
hdfs_sink1.hdfs.roundValue, 比如说,在 2012 年 6 月 12 号上午 11:54:34 生成的事件,在 hdfs 中生成的路径将是/flume/events/2012-06-12/1150/00。
hdfs_sink1.hdfs.roundUnit
# 启动Flume Agent
$ flume-ng agent \
--conf-file ./flume.conf \
--name agent1 \
-Dflume.root.logger=INFO,cnsole
$ hadoop fs -ls /flume