這篇文章主要介紹“Flume的Sink怎么使用”,在日常操作中,相信很多人在Flume的Sink怎么使用問題上存在疑惑,小編查閱了各式資料,整理出簡(jiǎn)單好用的操作方法,希望對(duì)大家解答”Flume的Sink怎么使用”的疑惑有所幫助!接下來,請(qǐng)跟著小編一起來學(xué)習(xí)吧!
創(chuàng)新互聯(lián)是一家專業(yè)提供萬寧企業(yè)網(wǎng)站建設(shè),專注與成都網(wǎng)站建設(shè)、成都網(wǎng)站制作、H5場(chǎng)景定制、小程序制作等業(yè)務(wù)。10年已為萬寧眾多企業(yè)、政府機(jī)構(gòu)等服務(wù)。創(chuàng)新互聯(lián)專業(yè)的建站公司優(yōu)惠進(jìn)行中。
Logger Sink
Logs會(huì)輸出到console,是為了debug用的。
[root@hftest0001 conf]# pwd /opt/apache-flume-1.6.0-bin/conf [root@hftest0001 conf]# vi s-exec_c-m_s-logger.conf agent.sources = exec_tail agent.channels = memoryChannel agent.sinks = loggerSink agent.sources.exec_tail.type = exec agent.sources.exec_tail.command = tail -F /opt/flume-data/exec-tail.log agent.sources.exec_tail.channels = memoryChannel agent.sinks.loggerSink.type = logger agent.sinks.loggerSink.channel = memoryChannel agent.channels.memoryChannel.type = memory agent.channels.memoryChannel.capacity = 100 [root@hftest0001 apache-flume-1.6.0-bin]# pwd /opt/apache-flume-1.6.0-bin [root@hftest0001 opt]# mkdir -p /opt/flume-data/ [root@hftest0001 opt]# touch /opt/flume-data/exec-tail.log [root@hftest0001 apache-flume-1.6.0-bin]# flume-ng agent -n agent -c conf/ -f conf/s-exec_c-m_s-logger.conf .... .... [root@hftest0001 opt]# echo "Hello Flume" >> /opt/flume-data/exec-tail.log 觀察console,類似于 Event:{headers{} bodys: xxx xx x x x x Hello Flume }
HDFS Sink
[root@hftest0001 conf]# pwd /opt/apache-flume-1.6.0-bin/conf [root@hftest0001 conf]# vi s-exec_c-m_s-hdfs.conf agent.sources = exec_tail agent.channels = memoryChannel agent.sinks = hdfs_sink agent.sources.exec_tail.type = exec agent.sources.exec_tail.command = tail -F /opt/flume-data/exec-tail.log agent.sources.exec_tail.interceptors = i1 agent.sources.exec_tail.interceptors.i1.type = org.apache.flume.interceptor.TimestampInterceptor$Builder agent.sources.exec_tail.channels = memoryChannel agent.sinks.hdfs_sink.type = hdfs agent.sinks.hdfs_sink.hdfs.path = hdfs://10.224.243.124:9000/flume/events/%y-%m-%d =>寫入hdfs的路徑 # #roll file的三個(gè)策略,(避免生成大量的空文件,或者小文件) #agent.sinks.hdfs_sink.hdfs.rollInterval = 30 =>基于時(shí)間:default 30s,設(shè)置為0,則disable #agent.sinks.hdfs_sink.hdfs.rollSize = 1024 =>基于文件大小:default 1024bytes,設(shè)置為0,則disable #agent.sinks.hdfs_sink.hdfs.rollCount = 10 =>基于文件消息的數(shù)量:default 10個(gè),設(shè)置為0,則disable agent.sinks.hdfs_sink.hdfs.fileType = DataStream =>flume寫入hdfs的文件類型 default:SequenceFile #SequenceFile => 類似于hadoop.io.LongWritable "ora.apache.hadoop.io.ByteWritable..."... #DataStream => 不會(huì)對(duì)輸出進(jìn)行壓縮,即不能再設(shè)置hdfs.codeC #CompressedStream =>就會(huì)對(duì)輸出進(jìn)行壓縮,并要求設(shè)置可用的hdfs.codeC #agent.sinks.hdfs_sink.hdfs.codeC agent.sinks.hdfs_sink.hdfs.writeFormat = Text agent.sinks.hdfs_sink.hdfs.filePrefix = flume #agent.sinks.hdfs_sink.hdfs.hdfs.callTimeout = 10000 => flume對(duì)Hdfs的操作如open,write,flush等等,對(duì)network不佳的系統(tǒng),可以適當(dāng)?shù)恼{(diào)大該參數(shù) agent.sinks.hdfs_sink.channel = memoryChannel agent.channels.memoryChannel.type = memory agent.channels.memoryChannel.capacity = 100
File Roll Sink
[root@hftest0001 conf]# pwd /opt/apache-flume-1.6.0-bin/conf [root@hftest0001 conf]# vi s-exec_c-m_s-file-roll.conf agent.sources = exec_tail-1 agent.channels = memoryChannel agent.sinks = file_roll-1 agent.sources.exec_tail-1.type = exec agent.sources.exec_tail-1.command = tail -F /opt/flume-data/exec-tail.log agent.sources.exec_tail-1.channels = memoryChannel agent.sinks.file_roll-1.type = file_roll agent.sinks.file_roll-1.sink.directory= /opt/flume-data/file-roll-1 #agent.sinks.file_roll-1.sink.rollInterval= 30 => roll file策略,default:30s 生成一個(gè)新的文件。設(shè)置為0,則disable roll file,即會(huì)全部寫入單一的文件中 agent.sinks.file_roll-1.channel = memoryChannel agent.channels.memoryChannel.type = memory agent.channels.memoryChannel.capacity = 100
到此,關(guān)于“Flume的Sink怎么使用”的學(xué)習(xí)就結(jié)束了,希望能夠解決大家的疑惑。理論與實(shí)踐的搭配能更好的幫助大家學(xué)習(xí),快去試試吧!若想繼續(xù)學(xué)習(xí)更多相關(guān)知識(shí),請(qǐng)繼續(xù)關(guān)注創(chuàng)新互聯(lián)網(wǎng)站,小編會(huì)繼續(xù)努力為大家?guī)砀鄬?shí)用的文章!