Flume环境搭建_五种案例
http://flume.apache.org/FlumeUserGuide.html
A simple example
Here, we give an example configuration file, describing a single-node Flume deployment. This configuration lets a user generate events and subsequently logs them to the console.
# 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
a1.sources.r1.bind = localhost
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
This configuration defines a single agent named a1. a1 has a source that listens for data on port 44444, a channel that buffers event data in memory, and a sink that logs event data to the console. The configuration file names the various components, then describes their types and configuration parameters. A given configuration file might define several named agents; when a given Flume process is launched a flag is passed telling it which named agent to manifest.
Given this configuration file, we can start Flume as follows:
$ bin/flume-ng agent --conf conf --conf-file example.conf --name a1 -Dflume.root.logger=INFO,console
Note that in a full deployment we would typically include one more option: --conf=<conf-dir>. The <conf-dir> directory would include a shell script flume-env.sh and potentially a log4j properties file. In this example, we pass a Java option to force Flume to log to the console and we go without a custom environment script.
From a separate terminal, we can then telnet port 44444 and send Flume an event:
$ telnet localhost 44444
Trying 127.0.0.1...
Connected to localhost.localdomain (127.0.0.1).
Escape character is '^]'.
Hello world! <ENTER>
OK
The original Flume terminal will output the event in a log message.
12/06/19 15:32:19 INFO source.NetcatSource: Source starting
12/06/19 15:32:19 INFO source.NetcatSource: Created serverSocket:sun.nio.ch.ServerSocketChannelImpl[/127.0.0.1:44444]
12/06/19 15:32:34 INFO sink.LoggerSink: Event: { headers:{} body: 48 65 6C 6C 6F 20 77 6F 72 6C 64 21 0D Hello world!. }
Congratulations - you’ve successfully configured and deployed a Flume agent! Subsequent sections cover agent configuration in much more detail.
以下为具体搭建流程
Flume搭建_案例一:单个Flume
安装node2上
1. 上传到/home/tools,解压,解压后移动到/home下
2. 重命名,并修改flume-env.sh
![](https://images2015.cnblogs.com/blog/1008304/201703/1008304-20170312171332373-1033999490.png)
![](https://images2015.cnblogs.com/blog/1008304/201703/1008304-20170312171333420-2056360922.png)
![](https://images2015.cnblogs.com/blog/1008304/201703/1008304-20170312171334764-1679491994.png)
![](https://images2015.cnblogs.com/blog/1008304/201703/1008304-20170312171335154-414348343.png)
![](https://images2015.cnblogs.com/blog/1008304/201703/1008304-20170312171335545-188739024.png)
![](https://images2015.cnblogs.com/blog/1008304/201703/1008304-20170312171336045-586481124.png)
![](https://images2015.cnblogs.com/blog/1008304/201703/1008304-20170312171336779-1875391592.png)
![](https://images2015.cnblogs.com/blog/1008304/201703/1008304-20170312171337186-1525639343.png)
![](https://images2015.cnblogs.com/blog/1008304/201703/1008304-20170312171337498-1863615554.png)
![](https://images2015.cnblogs.com/blog/1008304/201703/1008304-20170312171337764-714559925.png)
![](https://images2015.cnblogs.com/blog/1008304/201703/1008304-20170312171338420-1964489688.png)
Flume搭建_案例二:两个Flume做集群
![](https://images2015.cnblogs.com/blog/1008304/201703/1008304-20170312171338842-779676075.png)
MemoryChanel配置
capacity:默认该通道中最大的可以存储的event数量是100,
trasactionCapacity:每次最大可以从source中拿到或者送到sink中的event数量也是100
keep-alive:event添加到通道中或者移出的允许时间
byte**:即event的字节量的限制,只包括eventbody
![](https://images2015.cnblogs.com/blog/1008304/201703/1008304-20170312171339545-2121625829.png)
![](https://images2015.cnblogs.com/blog/1008304/201703/1008304-20170312171340139-18588027.png)
![](https://images2015.cnblogs.com/blog/1008304/201703/1008304-20170312171341029-362349203.png)
![](https://images2015.cnblogs.com/blog/1008304/201703/1008304-20170312171341342-542785759.png)
先启动node02的Flume
flume-ng agent -n a1 -c conf -f avro.conf -Dflume.root.logger=INFO,console
flume-ng agent -n a1 -c conf -f /home/test_flume/flume22 -Dflume.root.logger=INFO,console
再启动node01的Flume
flume-ng agent -n a1 -c conf -f simple.conf2 -Dflume.root.logger=INFO,console
flume-ng agent -n a1 -c conf -f /home/test_flume/flume21 -Dflume.root.logger=INFO,console
![](https://images2015.cnblogs.com/blog/1008304/201703/1008304-20170312171342342-540726591.png)
![](https://images2015.cnblogs.com/blog/1008304/201703/1008304-20170312171349061-1542831900.png)
![](https://images2015.cnblogs.com/blog/1008304/201703/1008304-20170312171351686-831470349.png)
![](https://images2015.cnblogs.com/blog/1008304/201703/1008304-20170312171352264-992996685.png)
![](https://images2015.cnblogs.com/blog/1008304/201703/1008304-20170312171352592-531144860.png)
![](https://images2015.cnblogs.com/blog/1008304/201703/1008304-20170312171352951-467772028.png)
Flume搭建_案例三:如何监控一个文件的变化?
![](https://images2015.cnblogs.com/blog/1008304/201703/1008304-20170312171353732-2077643044.png)
![](https://images2015.cnblogs.com/blog/1008304/201703/1008304-20170312171354311-1159633626.png)
启动Flume
flume-ng agent -n a1 -c conf -f exec.conf -Dflume.root.logger=INFO,console
flume-ng agent -n a1 -c conf -f /home/test_flume/flume3 -Dflume.root.logger=INFO,console
![](https://images2015.cnblogs.com/blog/1008304/201703/1008304-20170312171354826-67133970.png)
![](https://images2015.cnblogs.com/blog/1008304/201703/1008304-20170312171355764-1222013689.png)
Flume搭建_案例四: 如何监控一个文件:目录的变化?
![](https://images2015.cnblogs.com/blog/1008304/201703/1008304-20170312171357139-707861435.png)
![](https://images2015.cnblogs.com/blog/1008304/201703/1008304-20170312171357779-1164906943.png)
![](https://images2015.cnblogs.com/blog/1008304/201703/1008304-20170312171358420-651961015.png)
![](https://images2015.cnblogs.com/blog/1008304/201703/1008304-20170312171359264-449856012.png)
![](https://images2015.cnblogs.com/blog/1008304/201703/1008304-20170312171400201-904671324.png)
![](https://images2015.cnblogs.com/blog/1008304/201703/1008304-20170312171401217-836386773.png)
Flume搭建_案例五: 如何定义一个HDFS类型的Sink?
![](https://images2015.cnblogs.com/blog/1008304/201703/1008304-20170312171402389-1643863675.png)
Flume搭建_案例五_配置项解读
![](https://images2015.cnblogs.com/blog/1008304/201703/1008304-20170312171402779-490011132.png)
![](https://images2015.cnblogs.com/blog/1008304/201703/1008304-20170312171403217-262299378.png)
hdfs.rollInterval | 30 | Number of seconds to wait before rolling current file (0 = never roll based on time interval) |
hdfs.rollSize | 1024 | File size to trigger roll, in bytes (0: never roll based on file size) |
hdfs.rollCount | 10 | Number of events written to file before it rolled (0 = never roll based on number of events) |
4. 多长时间没有操作,Flume将一个临时文件生成新文件?
hdfs.idleTimeout | 0 | Timeout after which inactive files get closed (0 = disable automatic closing of idle files) |
5. 多长时间生成一个新的目录?(比如每10s生成一个新的目录)
四舍五入,没有五入,只有四舍
(比如57分划分为55分,5,6,7,8,9在一个目录,10,11,12,13,14在一个目录)
hdfs.round | false | Should the timestamp be rounded down (if true, affects all time based escape sequences except %t) |
hdfs.roundValue | 1 | Rounded down to the highest multiple of this (in the unit configured using hdfs.roundUnit), less than current time. |
hdfs.roundUnit | second | The unit of the round down value - second, minute or hour. |
![](https://images2015.cnblogs.com/blog/1008304/201703/1008304-20170312171403686-897543608.png)
![](https://images2015.cnblogs.com/blog/1008304/201703/1008304-20170312171404061-525137080.png)
![](https://images2015.cnblogs.com/blog/1008304/201703/1008304-20170312171404576-1181903015.png)
![](https://images2015.cnblogs.com/blog/1008304/201703/1008304-20170312171404889-632396100.png)
![](https://images2015.cnblogs.com/blog/1008304/201703/1008304-20170312171405154-907076073.png)
![](https://images2015.cnblogs.com/blog/1008304/201703/1008304-20170312171405529-1919831721.png)