设为首页 收藏本站
查看: 1527|回复: 0

[经验分享] 日志收集框架 Flume 组件之Source使用

[复制链接]

尚未签到

发表于 2019-1-30 09:35:50 | 显示全部楼层 |阅读模式
  上一篇简单介绍了Flume几个组件,今天介绍下组件其一的source,整理这些,也是二次学习的过程,也是梳理知识的过程。
  Source 中文译为来源,源
作用:采集数据,然后把数据传输到channel上。
例如:监控某个文件或者某个端口或某个目录,新增数据,新增文件的变化,然后传输到channel。
  常用的的source类型,也是平常用的比较多的几种类型,如下:


source类型
说明




Avro  Source
支持avro协议,内置支持


Thrift Source
支持Thirft rpc ,内置支持


Exec Source
基于Unix的command在标准输出上采集数据 ,如tail -F


JMS Source
监控JMS系统,比如Activemq,可以


Taildir Source
监听目录或文件(Flume1.8版本支持)


Spooling Directory Source
监听目录下的新增文件


Kafka Source
读取Kafka数据
  下面不多少,简单实战,没安装的可以google一下,好多安装教程,本文是基于Flume 1.8
  Exec Source,前面说过了,exec source 是以tail -F 形式来监听文件的变化的,
flume-exec.conf配置:

#  http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied.  See the License for the
# specific language governing permissions and limitations
# under the License.
# The configuration file needs to define the sources,
# the channels and the sinks.
# Sources, channels and sinks are defined per agent,
# Name the components on this agent
a1.sources = r1
a1.sinks = k1
a1.channels = c1
# # Describe/configure the source
# 配置类型为exec
a1.sources.r1.type = exec
# 路径是自己要监听的日志路径
a1.sources.r1.command = tail -F /usr/local/installed/tomcat/logs/system_app.log
a1.sources.r1.channels = c1
# # Describe the sink
# 下沉sink是以日志的形式来打印
a1.sinks.k1.type = logger
# # Use a channel which buffers events in memory
# channel采用以内存形式来存放上游source传递过来的数据
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

  具体使用步骤:
1、启动
进入到flume安装目录,../bin下,命令如下:

./bin/flume-ng agent -n a1 -c ../conf/ -f ../conf/flume-exec.conf
  缺点:agent挂了,则不会记录上次传递数据的位置,还是以tail -F为准,来重新传递数据。
  Taildir Source 监听目录文件变化,记录上一次同步后的位置,实现断点续传,可以保证没有重复数据的读取。

# The configuration file needs to define the sources,
# the channels and the sinks.
# Sources, channels and sinks are defined per agent,
# Name the components on this agent
a1.sources = r1
a1.sinks = k1
a1.channels = c1
# # Describe/configure the source
a1.sources.r1.type = TAILDIR
# 保存监听文件的读取位置的文件
a1.sources.r1.positionFile = /opt/flume/taildir_position.json
a1.sources.r1.filegroups = f1
a1.sources.r1.filegroups.f1 = /usr/local/installed/tomcat/logs/system_app.log
a1.sources.r1.batchSize = 100
a1.sources.r1.backoffSleepIncrement = 1000
a1.sources.r1.maxBackoffSleep = 5000
#
# # 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

  具体测试,可以往监听的文件里写入数据,看看是否可以监听到数据。
  Spooling Directory Source 监听目录文件的变化,
flume-spooling.conf 配置

# Name the components on this agent
a1.sources = r1
a1.sinks = k1
a1.channels = c1
# # Describe/configure the source
a1.sources.r1.type = spooldir
a1.sources.r1.spoolDir = /usr/local/self
a1.sources.r1.deletePolicy = immediate
a1.sources.r1.fileSuffix = completed
a1.sources.r1.batchSize = 100
# # 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

  备注:注意,只监听新增的文件,这个目录下有新增文件会被监听到。目录下子文件夹也不会被监听到,目录下以有的文件更新了,也不会被监听到。
  Avro Source配置

# 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.bind = 127.0.0.1
a1.sources.r1.port = 44444
#
# # 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

  备注:此文件是监听127.0.0.1:44444端口的数据变化,可以telnet 127.0.0.1:44444,输入数据,看flume是否监听到数据。
  其它的一些类型,可自行测试。
./bin/flume-ng agent -n a1 -c ../conf/ -f ../conf/flume-exec.conf
由于本文是在bin目录下启动的,没有更改flume产生日志的位置,所以会在/bin/logs/ 会有flume日志产生。
  测试的时候,自己开一个窗口,监控日志的变化,由于本文是采用以log日志的形式输出,所以用这个命令tail -f ./bin/logs/flume.log  可以看到是否配置成功。
  连接:
flume 概念以及模型简介地址:
日志收集框架 Flume 简介
http://blog.运维网.com/shangdc/2178127




运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-669449-1-1.html 上篇帖子: flume源码学习10 下篇帖子: Flume NG 学习笔记(二)单机与集群Flume 配置
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表