← 返回首页
Flume安装
发表时间:2023-08-26 13:28:04
Flume安装

1.去官网下载flume

去apache的官网下载flume,网站如下: https://flume.apache.org/

这里我们选中下载安装的版本是apache-flume-1.9.0-bin.tar.gz

2.解压安装

#解压apache-flume-1.9.0-bin.tar.gz至/usr/loca
tar -zxvf apache-flume-1.9.0-bin.tar.gz -C /usr/local
cd /usr/local

#更改flume安装路径名称
mv apache-flume-1.9.0-bin flume

#修改默认配置文档
cd /usr/local/flume/conf
mv flume-env.sh.template flume-env.sh

3.Flume的HelloWorld案例

创建一个名字叫example.conf的配置文档,把这个配置文件放到conf/ 目录下。

# 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
a1.sources.r1.type = netcat
#ip默认是localhost推荐使用0.0.0.0,这样无论内网还是外网都可以连接
a1.sources.r1.bind = 0.0.0.0
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

启动Flume的Agent。

cd /usr/local/flume

bin/flume-ng agent --name a1 --conf conf --conf-file conf/example.conf -Dflume.root.logger=INFO,console

使用telnet测试连接。

#如果客户端没有安装telnet,先使用yum安装。
yum install -y telnet

[root@bigdata04 ~]# telnet localhost 44444
-bash: telnet: command not found
[root@bigdata04 ~]# yum install -y telnet
[root@bigdata04 ~]# telnet localhost 44444
Trying ::1...
telnet: connect to address ::1: Connection refused
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
hello world!
OK

回到Agent所在的窗口,可以看到下面多了一行日志,就是我们在telnet中输入的内容:

2020-05-02 10:22:30,562 (SinkRunner-PollingRunner-DefaultSinkProcessor) [INFO - org.apache.flume.sink.LoggerSink.process(LoggerSink.java:95)] Event: { headers:{} body: 68 65 6C 6C 6F 20 77 6F 72 6C 64 21 0D          hello world!. }

使用后台进程启动Agent.

[root@localhost flume]# nohup  bin/flume-ng agent --name a1 --conf conf --conf-file conf/example.conf >example.log  2>&1  &

[2] 13373

使用telnet测试连接。

[root@localhost ~]# telnet localhost 44444
Trying ::1...
Connected to localhost.
Escape character is '^]'.
hello,world!
OK
welcome to linux!
OK

回到Agent所在的窗口,查看日志后十条输出记录:

[root@localhost flume]# tail -10  logs/flume.log  

26 八月 2023 21:22:50,050 INFO  [lifecycleSupervisor-1-0] (org.apache.flume.instrumentation.MonitoredCounterGroup.register:119)  - Monitored counter group for type: CHANNEL, name: c1: Successfully registered new MBean.
26 八月 2023 21:22:50,050 INFO  [lifecycleSupervisor-1-0] (org.apache.flume.instrumentation.MonitoredCounterGroup.start:95)  - Component type: CHANNEL, name: c1 started
26 八月 2023 21:22:50,051 INFO  [conf-file-poller-0] (org.apache.flume.node.Application.startAllComponents:196)  - Starting Sink k1
26 八月 2023 21:22:50,053 INFO  [conf-file-poller-0] (org.apache.flume.node.Application.startAllComponents:207)  - Starting Source r1
26 八月 2023 21:22:50,054 INFO  [lifecycleSupervisor-1-0] (org.apache.flume.source.NetcatSource.start:155)  - Source starting
26 八月 2023 21:22:50,064 INFO  [lifecycleSupervisor-1-0] (org.apache.flume.source.NetcatSource.start:166)  - Created serverSocket:sun.nio.ch.ServerSocketChannelImpl[/0:0:0:0:0:0:0:0:44444]
26 八月 2023 21:23:29,163 INFO  [SinkRunner-PollingRunner-DefaultSinkProcessor] (org.apache.flume.sink.LoggerSink.process:95)  - Event: { headers:{} body: 77 65 6C 63 6F 6D 65 20 74 6F 20 6C 6E 08 0D    welcome to ln.. }
26 八月 2023 21:23:35,151 INFO  [SinkRunner-PollingRunner-DefaultSinkProcessor] (org.apache.flume.sink.LoggerSink.process:95)  - Event: { headers:{} body: 77 65 6C 63 6F 6D 65 20 74 6F 20 6C 69 6E 75 78 welcome to linux }
26 八月 2023 21:26:06,347 INFO  [SinkRunner-PollingRunner-DefaultSinkProcessor] (org.apache.flume.sink.LoggerSink.process:95)  - Event: { headers:{} body: 68 65 6C 6C 6F 2C 77 6F 72 6C 64 21 0D          hello,world!. }
26 八月 2023 21:26:15,356 INFO  [SinkRunner-PollingRunner-DefaultSinkProcessor] (org.apache.flume.sink.LoggerSink.process:95)  - Event: { headers:{} body: 77 65 6C 63 6F 6D 65 20 74 6F 20 6C 69 6E 75 78 welcome to linux }