コレクション・フレームワークの水路をログに記録
水路の紹介
アウトライン
水路は、分散、信頼性、及び可用性の高い大規模なログ収集、凝集及び伝送システムです。
データ(シンクシンク)水路ファイルを収集することができ、ソケット・パケット・データ、ファイル、フォルダ、カフカとデータ・ソースの他の形態、および取得することができるHDFS、HBaseの、ハイブ、カフカ及び他の外部記憶装置に出力されます。
操作機構
水路は、水路が収集システムの分散システムのエージェントから構成され、最も中心的な役割は、1つのエージェントによって一緒にリンクされています
各エージェントは、データ転送部材として作用し、内部は3つのコンポーネントがあります。
- ソース:データソースとのドッキングの取得コンポーネント、データ収集
- シンク:シンク・アセンブリ、最終的なストレージまたはデータ転送システムまでデータを伝送するための薬剤
- チャンネル:ソースからシンクへデータを送信するためのチャネル伝送アセンブリ
集録システムの構成図。
シンプルな構造
複雑な構造
マルチレベルのエージェントとの間のシリーズ
水路実際のケース
インストールと展開
ステップ1:ダウンロードし、設定ファイルを変更し解凍します
水路インストールはちょうどすることができます、もちろん、そのそこのHadoop環境を解凍し、非常に簡単です
# 上传安装包到数据源所在节点上 这里采用在第三台机器来进行安装 软件目录 => flume-ng-1.6.0-cdh5.14.0.tar.gz tar -zxvf flume-ng-1.6.0-cdh5.14.0.tar.gz -C ../servers/ cd ../servers/apache-flume-1.6.0-cdh5.14.0-bin/conf/ cp flume-env.sh.template flume-env.sh vim flume-env.sh #只添加一个java环境就可以了 export JAVA_HOME=/export/servers/jdk1.8.0_141
ステップ2:プロファイルを開発
# 根据数据采集的需求配置采集方案,描述在配置文件中(文件名可任意自定义) # 配置我们的网络收集的配置文件 # 在flume的conf目录下新建一个配置文件(采集方案) vim /export/servers/apache-flume-1.6.0-cdh5.14.0-bin/conf/netcat-logger.conf # 定义这个agent中各组件的名字 a1.sources = r1 a1.sinks = k1 a1.channels = c1 # 描述和配置source组件:r1 a1.sources.r1.type = netcat a1.sources.r1.bind = 192.168.52.120 a1.sources.r1.port = 44444 # 描述和配置sink组件:k1 a1.sinks.k1.type = logger # 描述和配置channel组件,此处使用是内存缓存的方式 a1.channels.c1.type = memory a1.channels.c1.capacity = 1000 a1.channels.c1.transactionCapacity = 100 # 描述和配置source channel sink之间的连接关系 a1.sources.r1.channels = c1 a1.sinks.k1.channel = c1
スタートアップコンフィギュレーション・ファイル
取得方式指定されたプロファイルは、対応するノードに水路エージェントを開始
cd /export/servers/apache-flume-1.6.0-cdh5.14.0-bin bin/flume-ng agent -c conf -f conf/netcat-logger.conf -n a1 -Dflume.root.logger=INFO,console # -c conf 指定flume自身的配置文件所在目录 # -f conf/netcat-logger.conf 指定所描述的采集方案 # -n a1 指定这个agent的名字
インストールのtelnetは、テストの準備します
アナログデータ伝送とnode02のためのTelnetクライアントにマウント
yum -y install telnet telnet node03 44444 # 使用telnet模拟数据发送
買収ケース
HDFSへのコレクションカタログ
私たちは、特定のディレクトリサーバに新しいファイルを作成していきます、新しいファイルが表示されたときに、あなたが行くHDFSにファイルを収集する必要があります
要件によると、すべての最初は、次の3つの主要な要素を定義します
- データソースコンポーネント、すなわちソース - モニター・ファイルのディレクトリ:spooldirspooldirの特徴:
- 限り、新しいファイルがディレクトリに表示される、それはファイルの内容をキャプチャします、ディレクトリの監視
- 取得ファイルの完了は、自動的にサフィックスエージェントを追加します:完了します
- 監視対象のディレクトリを繰り返し、同じ名前のファイルを許可していません
- 組立、ママシンクシンク - HDFSファイルシステムを:HDFSは沈みます
- チャネルアセンブリ、ママチャンネル - 利用可能なメモリのファイルチャネルのメモリチャネルを使用することもできます
- データソースコンポーネント、すなわちソース - モニター・ファイルのディレクトリ:spooldirspooldirの特徴:
水路プロファイル開発
cd /export/servers/apache-flume-1.6.0-cdh5.14.0-bin/conf mkdir -p /export/servers/dirfile vim spooldir.conf # 定义agent的组件名字 a1.sources=sr1 a1.sinks=sk1 a1.channels=scn1 # 配置数据源source a1.sources.sr1.type=spooldir a1.sources.sr1.spoolDir=/export/servers/dirfile a1.sources.sr1.fileHeader=true # 配置下沉组件sink a1.sinks.sk1.type=hdfs a1.sinks.sk1.channel=scn1 # hdfs目录路径 a1.sinks.sk1.hdfs.path=hdfs://node01:8020/spooldir/files/%y-%m-%d/%H%M/ # 写入hdfs的文件名前缀 可以使用flume提供的日期及%{host}表达式 a1.sinks.sk1.hdfs.filePrefix=events- # 表示到了需要触发的时间时,是否要更新文件夹,true:表示要 a1.sinks.sk1.hdfs.round=true # 表示每隔value分钟改变一次(在0~24之间) a1.sinks.sk1.hdfs.roundValue=10 # 切换文件的时候的时间单位是分钟 a1.sinks.sk1.hdfs.roundUnit=minute # 多久时间后close hdfs文件。单位是秒,默认30秒。设置为0的话表示不根据时间close hdfs文件 a1.sinks.sk1.hdfs.rollInterval=3 # 文件大小超过一定值后,close文件。默认值1024,单位是字节。设置为0的话表示不基于文件大小,134217728表 示128m,决定了多大块可以切一个文件。 a1.sinks.sk1.hdfs.rollSize=134217728 # 写入了多少个事件后close文件。默认值是10个。设置为0的话表示不基于事件个数 a1.sinks.sk1.hdfs.rollCount=0 # 批次数,HDFS Sink每次从Channel中拿的事件个数。默认值100 a1.sinks.sk1.hdfs.batchSize=100 # 使用本地时间戳 a1.sinks.sk1.hdfs.useLocalTimeStamp=true #生成的文件类型默认是 Sequencefile,可用DataStream则为普通文本 a1.sinks.sk1.hdfs.fileType=DataStream # 配置通道channel a1.channels.scn1.type=memory a1.channels.scn1.capacity=1000 a1.channels.scn1.transactionCapacity=100 bin/flume-ng agent -c ./conf/ -f ./conf/spooldir.conf -n a1 -Dflume.root.logger=INFO,console # 运行flume
HDFSにファイルをキャプチャ
このようなコンテンツが増加しているログによって生成されたLog4jのログを使用して、ビジネス・システムとして、我々は、HDFSにリアルタイムで取得してログファイルにデータを追加する必要があります
- 要件によると、すべての最初は、次の3つの主要な要素を定義します
- 取得源、すなわちsource--モニターファイルのアップデート:幹部「尾部の-Fファイル」
- 目標を沈没、すなわちシンク - HDFSファイルシステムを:HDFSは沈みます
- ソースとシンクとの間の--channel移送通路は、使用可能なメモリ・チャネルものFileChannelを使用することができます
水路プロファイルの定義
cd /export/servers/apache-flume-1.6.0-cdh5.14.0-bin/conf vim tail-file.conf agent1.sources = source1 agent1.sinks = sink1 agent1.channels = channel1 # Describe/configure tail -F source1 agent1.sources.source1.type = exec agent1.sources.source1.command = tail -F /export/servers/taillogs/access_log agent1.sources.source1.channels = channel1 #configure host for source #agent1.sources.source1.interceptors = i1 #agent1.sources.source1.interceptors.i1.type = host #agent1.sources.source1.interceptors.i1.hostHeader = hostname # Describe sink1 agent1.sinks.sink1.type = hdfs #a1.sinks.k1.channel = c1 agent1.sinks.sink1.hdfs.path = hdfs://node01:8020/weblog/flume-collection/%y-%m-%d/%H-%M agent1.sinks.sink1.hdfs.filePrefix = access_log agent1.sinks.sink1.hdfs.maxOpenFiles = 5000 agent1.sinks.sink1.hdfs.batchSize= 100 agent1.sinks.sink1.hdfs.fileType = DataStream agent1.sinks.sink1.hdfs.writeFormat =Text agent1.sinks.sink1.hdfs.rollSize = 102400 agent1.sinks.sink1.hdfs.rollCount = 1000000 agent1.sinks.sink1.hdfs.rollInterval = 60 agent1.sinks.sink1.hdfs.round = true agent1.sinks.sink1.hdfs.roundValue = 10 agent1.sinks.sink1.hdfs.roundUnit = minute agent1.sinks.sink1.hdfs.useLocalTimeStamp = true # Use a channel which buffers events in memory agent1.channels.channel1.type = memory agent1.channels.channel1.keep-alive = 120 agent1.channels.channel1.capacity = 500000 agent1.channels.channel1.transactionCapacity = 600 # Bind the source and sink to the channel agent1.sources.source1.channels = channel1 agent1.sinks.sink1.channel = channel1 bin/flume-ng agent -c conf -f conf/tail-file.conf -n agent1 -Dflume.root.logger=INFO,console #启动Flume # 开发shell脚本定时追加文件内容 mkdir -p /export/servers/shells/ cd /export/servers/shells/ vim tail-file.sh #!/bin/bash while true do date >> /export/servers/taillogs/access_log;
二つのカスケード接続エージェント
収集を担当するエージェントの中から最初のデータファイルは、第二の薬剤にそれらを送信するためにネットワークを経由して、第2の薬剤は、エージェントから送信された最初のデータを受信するための責任がある、HDFS上に行くためにデータを保存
最初のステップ:node02でインストール水路
cd /export/servers
scp -r apache-flume-1.6.0-cdh5.14.0-bin/ node02:$PWD
ステップ2:node02で設定水路プロファイル
cd /export/servers/apache-flume-1.6.0-cdh5.14.0-bin/conf
vim tail-avro-avro-logger.conf
##################
# Name the components on this agent
a1.sources = r1
a1.sinks = k1
a1.channels = c1
# Describe/configure the source
a1.sources.r1.type = exec
a1.sources.r1.command = tail -F /export/servers/taillogs/access_log
a1.sources.r1.channels = c1
# Describe the sink
##sink端的avro是一个数据发送者
a1.sinks = k1
a1.sinks.k1.type = avro
a1.sinks.k1.channel = c1
a1.sinks.k1.hostname = 192.168.52.120
a1.sinks.k1.port = 4141
a1.sinks.k1.batch-size = 10
# Use a channel which buffers events in memory
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
第三段階:node02で開発されたスクリプトファイルは、データファイルに書き込まれます
# 直接把node03的脚本拷贝至node02
cd /export/servers
scp -r shells/ taillogs/ node02:$PWD
開発水路プロファイルnode03の第四段階
# 在node03机器上开发flume的配置文件
cd /export/servers/apache-flume-1.6.0-cdh5.14.0-bin/conf
vim avro-hdfs.conf #配置如下
# Name the components on this agent
a1.sources = r1
a1.sinks = k1
a1.channels = c1
# Describe/configure the source
##source中的avro组件是一个接收者服务
a1.sources.r1.type = avro
a1.sources.r1.channels = c1
a1.sources.r1.bind = 192.168.52.120
a1.sources.r1.port = 4141
# Describe the sink
a1.sinks.k1.type = hdfs
a1.sinks.k1.hdfs.path = hdfs://node01:8020/avro/hdfs/%y-%m-%d/%H%M/
a1.sinks.k1.hdfs.filePrefix = events-
a1.sinks.k1.hdfs.round = true
a1.sinks.k1.hdfs.roundValue = 10
a1.sinks.k1.hdfs.roundUnit = minute
a1.sinks.k1.hdfs.rollInterval = 3
a1.sinks.k1.hdfs.rollSize = 20
a1.sinks.k1.hdfs.rollCount = 5
a1.sinks.k1.hdfs.batchSize = 1
a1.sinks.k1.hdfs.useLocalTimeStamp = true
#生成的文件类型,默认是Sequencefile,可用DataStream,则为普通文本
a1.sinks.k1.hdfs.fileType = DataStream
# Use a channel which buffers events in memory
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
第五ステップシーケンス開始
# node03机器启动flume进程
cd /export/servers/apache-flume-1.6.0-cdh5.14.0-bin
bin/flume-ng agent -c conf -f conf/avro-hdfs.conf -n a1 -Dflume.root.logger=INFO,console
# node02机器启动flume进程
cd /export/servers/apache-flume-1.6.0-cdh5.14.0-bin/
bin/flume-ng agent -c conf -f conf/tail-avro-avro-logger.conf -n a1 -Dflume.root.logger=INFO,console
# node02机器启shell脚本生成文件
cd /export/servers/shells
sh tail-file.sh
以上のソースおよびシンク・アセンブリ
参照してください:http://archive.cloudera.com/cdh5/cdh/5/flume-ng-1.6.0-cdh5.14.0/FlumeUserGuide.html
フルーム-NG、高可用性フェールオーバーの設定の場合
役割の割り当て
名前 ホスト 役割 エージェント1 node01 Webサーバー コレクタ1 node02 AgentMstr1 コレクタ2 node03の AgentMstr2 node01インストール構成水路
# node03机器执行以下命令 cd /export/servers scp -r apache-flume-1.6.0-cdh5.14.0-bin/ node01:$PWD scp -r shells/ taillogs/ node01:$PWD # node01机器配置agent的配置文件 cd /export/servers/apache-flume-1.6.0-cdh5.14.0-bin/conf vim agent.conf #配置如下 #agent1 name agent1.channels = c1 agent1.sources = r1 agent1.sinks = k1 k2 # ##set gruop agent1.sinkgroups = g1 # ##set channel agent1.channels.c1.type = memory agent1.channels.c1.capacity = 1000 agent1.channels.c1.transactionCapacity = 100 # agent1.sources.r1.channels = c1 agent1.sources.r1.type = exec agent1.sources.r1.command = tail -F /export/servers/taillogs/access_log # agent1.sources.r1.interceptors = i1 i2 agent1.sources.r1.interceptors.i1.type = static agent1.sources.r1.interceptors.i1.key = Type agent1.sources.r1.interceptors.i1.value = LOGIN agent1.sources.r1.interceptors.i2.type = timestamp # ## set sink1 agent1.sinks.k1.channel = c1 agent1.sinks.k1.type = avro agent1.sinks.k1.hostname = node02 agent1.sinks.k1.port = 52020 # ## set sink2 agent1.sinks.k2.channel = c1 agent1.sinks.k2.type = avro agent1.sinks.k2.hostname = node03 agent1.sinks.k2.port = 52020 # ##set sink group agent1.sinkgroups.g1.sinks = k1 k2 # ##set failover agent1.sinkgroups.g1.processor.type = failover agent1.sinkgroups.g1.processor.priority.k1 = 10 agent1.sinkgroups.g1.processor.priority.k2 = 1 agent1.sinkgroups.g1.processor.maxpenalty = 10000 #
node02とnode03の構成flumecollection
# node02机器修改配置文件 cd /export/servers/apache-flume-1.6.0-cdh5.14.0-bin/conf vim collector.conf #set Agent name a1.sources = r1 a1.channels = c1 a1.sinks = k1 # ##set channel a1.channels.c1.type = memory a1.channels.c1.capacity = 1000 a1.channels.c1.transactionCapacity = 100 # ## other node,nna to nns a1.sources.r1.type = avro a1.sources.r1.bind = node02 a1.sources.r1.port = 52020 a1.sources.r1.interceptors = i1 a1.sources.r1.interceptors.i1.type = static a1.sources.r1.interceptors.i1.key = Collector a1.sources.r1.interceptors.i1.value = node02 a1.sources.r1.channels = c1 # ##set sink to hdfs a1.sinks.k1.type=hdfs a1.sinks.k1.hdfs.path= hdfs://node01:8020/flume/failover/ a1.sinks.k1.hdfs.fileType=DataStream a1.sinks.k1.hdfs.writeFormat=TEXT a1.sinks.k1.hdfs.rollInterval=10 a1.sinks.k1.channel=c1 a1.sinks.k1.hdfs.filePrefix=%Y-%m-%d # node03机器修改配置文件 cd /export/servers/apache-flume-1.6.0-cdh5.14.0-bin/conf vim collector.conf #set Agent name a1.sources = r1 a1.channels = c1 a1.sinks = k1 # ##set channel a1.channels.c1.type = memory a1.channels.c1.capacity = 1000 a1.channels.c1.transactionCapacity = 100 # ## other node,nna to nns a1.sources.r1.type = avro a1.sources.r1.bind = node03 a1.sources.r1.port = 52020 a1.sources.r1.interceptors = i1 a1.sources.r1.interceptors.i1.type = static a1.sources.r1.interceptors.i1.key = Collector a1.sources.r1.interceptors.i1.value = node03 a1.sources.r1.channels = c1 # ##set sink to hdfs a1.sinks.k1.type=hdfs a1.sinks.k1.hdfs.path= hdfs://node01:8020/flume/failover/ a1.sinks.k1.hdfs.fileType=DataStream a1.sinks.k1.hdfs.writeFormat=TEXT a1.sinks.k1.hdfs.rollInterval=10 a1.sinks.k1.channel=c1 a1.sinks.k1.hdfs.filePrefix=%Y-%m-%d
コマンドシーケンスを開始します
# node03机器上面启动flume cd /export/servers/apache-flume-1.6.0-cdh5.14.0-bin bin/flume-ng agent -n a1 -c conf -f conf/collector.conf -Dflume.root.logger=DEBUG,console # node02机器上面启动flume cd /export/servers/apache-flume-1.6.0-cdh5.14.0-bin bin/flume-ng agent -n a1 -c conf -f conf/collector.conf -Dflume.root.logger=DEBUG,console # node01机器上面启动flume cd /export/servers/apache-flume-1.6.0-cdh5.14.0-bin bin/flume-ng agent -n agent1 -c conf -f conf/agent.conf -Dflume.root.logger=DEBUG,console # node01机器启动文件产生脚本 cd /export/servers/shells sh tail-file.sh
FAILOVERテスト
- コレクタ1のダウンタイムは、コレクタ2は、アップロードする優先権を取得します
- コレクタ1サービスを再起動し、コレクタ1は、優先順位をアップロードする権限を取り戻します
水路ロードバランシングロードバランサ
ロードバランシングは、機械(プロセス)を解決するために使用されるすべての要求生成アルゴリズムを解決することはできません。エージェント1は、ルーティングノード、担当して示すように、シンクプロセッサ負荷バランス機能を負荷分散を実現することができ、
一時的に対応する構成要素のイベントシンク複数に格納されたチャネル等化、及び各成分がシンク別々に接続されている-エージェント、例えば設定は以下のとおりです。
ここでは、3台のマシンによるバランスアナログ水路をロード
次のように3台のマシンが計画しました:
node01:マシンアップとnode02とnode03のに送信データ収集、
node02で:node01のデータ受信部
node03の:node01のデータ受信部
最初のステップ:水路node01サーバー構成の開発
# node01服务器配置: cd /export/servers/apache-flume-1.6.0-cdh5.14.0-bin/conf vim load_banlancer_client.conf #agent name a1.channels = c1 a1.sources = r1 a1.sinks = k1 k2 #set gruop a1.sinkgroups = g1 #set channel a1.channels.c1.type = memory a1.channels.c1.capacity = 1000 a1.channels.c1.transactionCapacity = 100 a1.sources.r1.channels = c1 a1.sources.r1.type = exec a1.sources.r1.command = tail -F /export/servers/taillogs/access_log # set sink1 a1.sinks.k1.channel = c1 a1.sinks.k1.type = avro a1.sinks.k1.hostname = node02 a1.sinks.k1.port = 52020 # set sink2 a1.sinks.k2.channel = c1 a1.sinks.k2.type = avro a1.sinks.k2.hostname = node03 a1.sinks.k2.port = 52020 #set sink group a1.sinkgroups.g1.sinks = k1 k2 #set failover a1.sinkgroups.g1.processor.type = load_balance a1.sinkgroups.g1.processor.backoff = true a1.sinkgroups.g1.processor.selector = round_robin a1.sinkgroups.g1.processor.selector.maxTimeOut=10000
ステップ2:node02でサーバー設定水路を開発
# node02服务器配置: cd /export/servers/apache-flume-1.6.0-cdh5.14.0-bin/conf vim load_banlancer_server.conf # Name the components on this agent a1.sources = r1 a1.sinks = k1 a1.channels = c1 # Describe/configure the source a1.sources.r1.type = avro a1.sources.r1.channels = c1 a1.sources.r1.bind = node02 a1.sources.r1.port = 52020 # Describe the sink a1.sinks.k1.type = logger # Use a channel which buffers events in memory 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
第三段階:開発node03のサーバ構成水路
# node03服务器配置 cd /export/servers/apache-flume-1.6.0-cdh5.14.0-bin/conf vim load_banlancer_server.conf # Name the components on this agent a1.sources = r1 a1.sinks = k1 a1.channels = c1 # Describe/configure the source a1.sources.r1.type = avro a1.sources.r1.channels = c1 a1.sources.r1.bind = node03 a1.sources.r1.port = 52020 # Describe the sink a1.sinks.k1.type = logger # Use a channel which buffers events in memory 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
ステップ4:水路サービスを開始する準備ができて
# 启动node03的flume服务 cd /export/servers/apache-flume-1.6.0-cdh5.14.0-bin bin/flume-ng agent -n a1 -c conf -f conf/load_banlancer_server.conf -Dflume.root.logger=DEBUG,console # 启动node02的flume服务 cd /export/servers/apache-flume-1.6.0-cdh5.14.0-bin bin/flume-ng agent -n a1 -c conf -f conf/load_banlancer_server.conf -Dflume.root.logger=DEBUG,console # 启动node01的flume服务 cd /export/servers/apache-flume-1.6.0-cdh5.14.0-bin bin/flume-ng agent -n a1 -c conf -f conf/load_banlancer_client.conf -Dflume.root.logger=DEBUG,console # node01服务器运行脚本产生数据 cd /export/servers/shells sh tail-file.sh
水路ケースワン
A、B機のaccess.log、nginx.log、web.log機Cを収集は、その後、HDFSに収集統一に集約されます。
しかし、HDFSで必要なディレクトリ:
/ソース/ログ/アクセス/ 20180101 / **
/ソース/ログ/ nginxの/ 20180101 / **
/ソース/ログ/ウェブ/ 20180101 / **
取得側の構成ファイルの開発
# node01与node02服务器开发flume的配置文件 cd /export/servers/apache-flume-1.6.0-cdh5.14.0-bin/conf vim exec_source_avro_sink.conf # Name the components on this agent a1.sources = r1 r2 r3 a1.sinks = k1 a1.channels = c1 # Describe/configure the source a1.sources.r1.type = exec a1.sources.r1.command = tail -F /export/servers/taillogs/access.log a1.sources.r1.interceptors = i1 a1.sources.r1.interceptors.i1.type = static ## static拦截器的功能就是往采集到的数据的header中插入自己定## 义的key-value对 a1.sources.r1.interceptors.i1.key = type a1.sources.r1.interceptors.i1.value = access a1.sources.r2.type = exec a1.sources.r2.command = tail -F /export/servers/taillogs/nginx.log a1.sources.r2.interceptors = i2 a1.sources.r2.interceptors.i2.type = static a1.sources.r2.interceptors.i2.key = type a1.sources.r2.interceptors.i2.value = nginx a1.sources.r3.type = exec a1.sources.r3.command = tail -F /export/servers/taillogs/web.log a1.sources.r3.interceptors = i3 a1.sources.r3.interceptors.i3.type = static a1.sources.r3.interceptors.i3.key = type a1.sources.r3.interceptors.i3.value = web # Describe the sink a1.sinks.k1.type = avro a1.sinks.k1.hostname = node03 a1.sinks.k1.port = 41414 # Use a channel which buffers events in memory a1.channels.c1.type = memory a1.channels.c1.capacity = 20000 a1.channels.c1.transactionCapacity = 10000 # Bind the source and sink to the channel a1.sources.r1.channels = c1 a1.sources.r2.channels = c1 a1.sources.r3.channels = c1 a1.sinks.k1.channel = c1
サーバーの構成ファイルの開発
# 在node03上面开发flume配置文件 cd /export/servers/apache-flume-1.6.0-cdh5.14.0-bin/conf vim avro_source_hdfs_sink.conf a1.sources = r1 a1.sinks = k1 a1.channels = c1 #定义source a1.sources.r1.type = avro a1.sources.r1.bind = 192.168.52.120 a1.sources.r1.port =41414 #添加时间拦截器 a1.sources.r1.interceptors = i1 a1.sources.r1.interceptors.i1.type = org.apache.flume.interceptor.TimestampInterceptor$Builder #定义channels a1.channels.c1.type = memory a1.channels.c1.capacity = 20000 a1.channels.c1.transactionCapacity = 10000 #定义sink a1.sinks.k1.type = hdfs a1.sinks.k1.hdfs.path=hdfs://192.168.52.100:8020/source/logs/%{type}/%Y%m%d a1.sinks.k1.hdfs.filePrefix =events a1.sinks.k1.hdfs.fileType = DataStream a1.sinks.k1.hdfs.writeFormat = Text #时间类型 a1.sinks.k1.hdfs.useLocalTimeStamp = true #生成的文件不按条数生成 a1.sinks.k1.hdfs.rollCount = 0 #生成的文件按时间生成 a1.sinks.k1.hdfs.rollInterval = 30 #生成的文件按大小生成 a1.sinks.k1.hdfs.rollSize = 10485760 #批量写入hdfs的个数 a1.sinks.k1.hdfs.batchSize = 10000 #flume操作hdfs的线程数(包括新建,写入等) a1.sinks.k1.hdfs.threadsPoolSize=10 #操作hdfs超时时间 a1.sinks.k1.hdfs.callTimeout=30000 #组装source、channel、sink a1.sources.r1.channels = c1 a1.sinks.k1.channel = c1
取得側のファイル生成スクリプト
cd /export/servers/shells vim server.sh #!/bin/bash while true do date >> /export/servers/taillogs/access.log; date >> /export/servers/taillogs/web.log; date >> /export/servers/taillogs/nginx.log; sleep 0.5; done
サービスを開始するために
# node03启动flume实现数据收集 cd /export/servers/apache-flume-1.6.0-cdh5.14.0-bin bin/flume-ng agent -c conf -f conf/avro_source_hdfs_sink.conf -name a1 -Dflume.root.logger=DEBUG,console # node01与node02启动flume实现数据监控 cd /export/servers/apache-flume-1.6.0-cdh5.14.0-bin bin/flume-ng agent -c conf -f conf/exec_source_avro_sink.conf -name a1 -Dflume.root.logger=DEBUG,console # node01与node02启动生成文件脚本 cd /export/servers/shells sh server.sh