# example.conf: A single-node Flume configuration# Name the components on this agent #給那三個組件取個名字 a1.sources = r1 a1.sinks = k1 a1.channels = c1# Describe/configure the source #類型, 從網絡端口接收數據,在本機啟動, 所以localhost, type=spoolDir采集目錄源,目錄里有就采 a1.sources.r1.type = netcat a1.sources.r1.bind = localhost a1.sources.r1.port = 44444# Describe the sink a1.sinks.k1.type = logger# Use a channel which buffers events in memory #下沉的時候是一批一批的, 下沉的時候是一個個eventChannel參數解釋: #capacity:默認該通道中最大的可以存儲的event數量 #trasactionCapacity:每次最大可以從source中拿到或者送到sink中的event數量 a1.channels.c1.type = memory a1.channels.c1.capacity = 1000 a1.channels.c1.transactionCapacity = 100# Bind the source and sink to the channel a1.sources.r1.channels = c1 a1.sinks.k1.channel = c1啟動命令: #告訴flum啟動一個agent,指定配置參數, --name:agent的名字, $ bin/flume-ng agent --conf conf --conf-file conf/netcat-logger.conf --name a1 -Dflume.root.logger=INFO,console
首先要啟動hdfs,
使用telnet通信就可以做測試,如果是其他機器訪問的那么netcat要配置成ip而不是localhost,netcat默認讀取字符長度是16個數字,可以設置更大
?啟動flume 之后?telnet mini2 44444?
文件系統 到hdfs
agent1.sources=source1 agent1.sinks=sink1 agent1.channels=channel1 #source1 agent1.sources.source1.type=spooldir agent1.sources.source1.spoolDir=/home/hadoop/flume/test/logs agent1.sources.source1.channels=channel1 agent1.sources.source1.fileHeader=false agent1.sources.source1.interceptors?=?i1 agent1.sources.source1.interceptors.i1.type?=?timestamp #sink1 agent1.sinks.sink1.type=hdfs agent1.sinks.sink1.hdfs.path=hdfs://mini1:9000/flume/data agent1.sinks.sink1.hdfs.fileType=DataStream agent1.sinks.sink1.hdfs.writeFormat=TEXT agent1.sinks.sink1.hdfs.rollInterval=1 agent1.sinks.sink1.hdfs.useLocalTimeStamp = true agent1.sinks.sink1.channel=channel1 agent1.sinks.sink1.hdfs.filePrefix=%Y-%m-%d #配置channel1 agent1.channels.channel1.type=file agent1.channels.channel1.checkpointDir=/home/hadoop/flume/channel_data.backup agent1.channels.channel1.dataDirs=/home/hadoop/flume/channel_data
?