目录
Flume实战记录-目录:https://blog.csdn.net/weixin_39565597/article/details/104506480
介绍
Flume是一个分布式海量日志采集、聚合、传输的系统。可实时的采集本地服务器磁盘数据,写入其它框架。
Flume的组成:Agent(source输入、channel缓冲、sink输出、event事件)传输的基本单元。
环境准备
官方下载地址:http://archive.apache.org/dist/flume/
官方文档:https://cwiki.apache.org/confluence/display/FLUME/Getting+Started
本文下载apache-flume-1.7.0-bin.tar.gz
安装前准备环境:centos、jdk、telnet
安装位置:/opt/soft/flume-1.7.0
集群安装(3台服务器):
192.168.220.151 node1
192.168.220.152 node2
192.168.220.153 node3
配置文件
# 进入配置文件目录,配置flume的java环境
[root@node1 flume-1.7.0] cd conf
[root@node1 conf] cp flume-env.sh.template flume-env.sh
[root@node1 conf] vim flume-env.sh
export JAVA_HOME=/opt/module/jdk1.8.0_144
# 拷贝至其它服务器
[root@node1 soft] scp -r /opt/soft/flume-1.7.0 root@node2:/opt/soft/
[root@node1 soft] scp -r /opt/soft/flume-1.7.0 root@node3:/opt/soft/
快速入门案例
监听本地服务器8888端口,实时输出(确保8888端口未占用netstat -tunlp | grep 8888)
source:监听8888端口数据作为输入
sink:输出自己输入的数据
# 创建采集任务配置
# 可在官方文档的getting-started查看
[root@node1 flume-1.7.0] mkdir job
[root@node1 flume-1.7.0] touch flume-telnet-test.conf
[root@node1 flume-1.7.0] vim flume-telnet-test.conf
# Name the components on this agent
a1.sources = r1
a1.sinks = k1
a1.channels = c1
# Describe/configure the source
a1.sources.r1.type = netcat
a1.sources.r1.bind = localhost
a1.sources.r1.port = 8888
# 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
基础参数说明:查看详情
a1:agent名称
r1:source,数据源
c1:channels,缓冲区
k1:sink,输出
# 监听8888端口
# --conf:flume配置文件位置
# --name:agent名称
# --conf-file:自定义的采集任务名称
# -Dflume.root.logger:打印日志级别
[root@node1 flume-1.7.0] ./bin/flume-ng agent --conf ./conf/ --name a1 --conf-file ./job/flume-telnet-test.conf -Dflume.root.logger=INFO,console
# 打开新窗口,向端口8888发送数据
# 回到监听8888的窗口,可查看到日志输出。
[root@node1 flume-1.7.0] telnet localhost 8888
Trying :: 1...
telnet: connect to address ::1 Connection refused
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
hello flume1
至此,基础安装部署已完成