Flume-NG指令集和第一個簡單的案例

# 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

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


# 查看hdfs
$ hadoop fs -ls /flume
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章