Flume把事件写入多个信宿
来源:互联网 发布:游族网络上班好吗 编辑:程序博客网 时间:2024/05/16 19:22
1.创建agent配置文件
把下列内容存入agent7.conf,并保存到Flume的工作目录/opt/flume/bin下面
agent7.sources = netsource
agent7.sinks = hdfssink filesink
agent7.channels = memorychannel1 memorychannel2
agent7.sources.netsource.type = netcat
agent7.sources.netsource.bind = localhost
agent7.sources.netsource.port = 3000
agent7.sources.netsource.interceptors = ts
agent7.sources.netsource.interceptors.ts.type = org.apache.flume.interceptor.TimestampInterceptor$Builder
agent7.sinks.hdfssink.type = hdfs
agent7.sinks.hdfssink.hdfs.path = /flume2sink/ts-%Y-%m-%d
agent7.sinks.hdfssink.hdfs.filePrefix = log
agent7.sinks.hdfssink.hdfs.rollInterval = 0
agent7.sinks.hdfssink.hdfs.rollCount = 5
agent7.sinks.hdfssink.hdfs.fileType = DataStream
agent7.sinks.filesink.type = FILE_ROLL
agent7.sinks.filesink.sink.directory = /opt/flume/files2sink
agent7.sinks.filesink.sink.rollInterval = 0
agent7.channels.memorychannel1.type = memory
agent7.channels.memorychannel1.capacity = 1000
agent7.channels.memorychannel1.transactionCapacity = 100
agent7.channels.memorychannel2.type = memory
agent7.channels.memorychannel2.capacity = 1000
agent7.channels.memorychannel2.transactionCapacity = 100
agent7.sources.netsource.channels = memorychannel1 memorychannel2
agent7.sinks.hdfssink.channel = memorychannel1
agent7.sinks.filesink.channel = memorychannel2
agent7.sources.netsource.selector.type = replicating
(需要创建信宿目录:caiyong@caiyong:/opt/flume$ mkdir files2sink)
2.启动Flume代理
caiyong@caiyong:/opt/flume/bin$ flume-ng agent --conf conf --conf-file agent7.conf --name agent7
3.在另一个窗口中开启一个远程连接并发送几个事件
caiyong@caiyong:~$ telnet localhost 3000
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
one
OK
source
OK
two
OK
sinks
OK
this
OK
is
OK
a
OK
test
OK
OK,byebye.
OK
4.检查结果
(1)检查file信宿内容
caiyong@caiyong:/opt/flume/files2sink$ ls -alh
总用量 12K
drwxrwxr-x 2 caiyong caiyong 4.0K 3月 14 21:54 .
drwxr-xr-x 10 caiyong root 4.0K 3月 14 15:55 ..
-rw-rw-r-- 1 caiyong caiyong 56 3月 14 21:54 1426341241611-1
caiyong@caiyong:/opt/flume/files2sink$ cat *
one
source
two
sinks
this
is
a
test
OK,byebye.
(2)检查HDFS信宿内容
caiyong@caiyong:/opt/hadoop$ bin/hadoop fs -ls /flume2sink/
Found 1 items
drwxr-xr-x - caiyong supergroup 0 2015-03-14 21:54 /flume2sink/ts-2015-03-14
caiyong@caiyong:/opt/hadoop$ bin/hadoop fs -ls /flume2sink/*
Found 2 items
-rw-r--r-- 1 caiyong supergroup 31 2015-03-14 21:54 /flume2sink/ts-2015-03-14/log.1426341252881
-rw-r--r-- 1 caiyong supergroup 0 2015-03-14 21:54 /flume2sink/ts-2015-03-14/log.1426341252882.tmp
caiyong@caiyong:/opt/hadoop$ bin/hadoop fs -cat /flume2sink/ts*/*2881
one
source
two
sinks
this
caiyong@caiyong:/opt/hadoop$ bin/hadoop fs -cat /flume2sink/ts*/*mp
is
a
test
OK,byebye.
分析:创建的配置文件设置了一个Netcat信源和两个信宿(file信宿和HDFS信宿),设置了两个memory信道分别连接信源和两个信宿。设置信源选择器类型为replicating,这样所有事件都会发送给两个信道。
把下列内容存入agent7.conf,并保存到Flume的工作目录/opt/flume/bin下面
agent7.sources = netsource
agent7.sinks = hdfssink filesink
agent7.channels = memorychannel1 memorychannel2
agent7.sources.netsource.type = netcat
agent7.sources.netsource.bind = localhost
agent7.sources.netsource.port = 3000
agent7.sources.netsource.interceptors = ts
agent7.sources.netsource.interceptors.ts.type = org.apache.flume.interceptor.TimestampInterceptor$Builder
agent7.sinks.hdfssink.type = hdfs
agent7.sinks.hdfssink.hdfs.path = /flume2sink/ts-%Y-%m-%d
agent7.sinks.hdfssink.hdfs.filePrefix = log
agent7.sinks.hdfssink.hdfs.rollInterval = 0
agent7.sinks.hdfssink.hdfs.rollCount = 5
agent7.sinks.hdfssink.hdfs.fileType = DataStream
agent7.sinks.filesink.type = FILE_ROLL
agent7.sinks.filesink.sink.directory = /opt/flume/files2sink
agent7.sinks.filesink.sink.rollInterval = 0
agent7.channels.memorychannel1.type = memory
agent7.channels.memorychannel1.capacity = 1000
agent7.channels.memorychannel1.transactionCapacity = 100
agent7.channels.memorychannel2.type = memory
agent7.channels.memorychannel2.capacity = 1000
agent7.channels.memorychannel2.transactionCapacity = 100
agent7.sources.netsource.channels = memorychannel1 memorychannel2
agent7.sinks.hdfssink.channel = memorychannel1
agent7.sinks.filesink.channel = memorychannel2
agent7.sources.netsource.selector.type = replicating
(需要创建信宿目录:caiyong@caiyong:/opt/flume$ mkdir files2sink)
2.启动Flume代理
caiyong@caiyong:/opt/flume/bin$ flume-ng agent --conf conf --conf-file agent7.conf --name agent7
3.在另一个窗口中开启一个远程连接并发送几个事件
caiyong@caiyong:~$ telnet localhost 3000
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
one
OK
source
OK
two
OK
sinks
OK
this
OK
is
OK
a
OK
test
OK
OK,byebye.
OK
4.检查结果
(1)检查file信宿内容
caiyong@caiyong:/opt/flume/files2sink$ ls -alh
总用量 12K
drwxrwxr-x 2 caiyong caiyong 4.0K 3月 14 21:54 .
drwxr-xr-x 10 caiyong root 4.0K 3月 14 15:55 ..
-rw-rw-r-- 1 caiyong caiyong 56 3月 14 21:54 1426341241611-1
caiyong@caiyong:/opt/flume/files2sink$ cat *
one
source
two
sinks
this
is
a
test
OK,byebye.
(2)检查HDFS信宿内容
caiyong@caiyong:/opt/hadoop$ bin/hadoop fs -ls /flume2sink/
Found 1 items
drwxr-xr-x - caiyong supergroup 0 2015-03-14 21:54 /flume2sink/ts-2015-03-14
caiyong@caiyong:/opt/hadoop$ bin/hadoop fs -ls /flume2sink/*
Found 2 items
-rw-r--r-- 1 caiyong supergroup 31 2015-03-14 21:54 /flume2sink/ts-2015-03-14/log.1426341252881
-rw-r--r-- 1 caiyong supergroup 0 2015-03-14 21:54 /flume2sink/ts-2015-03-14/log.1426341252882.tmp
caiyong@caiyong:/opt/hadoop$ bin/hadoop fs -cat /flume2sink/ts*/*2881
one
source
two
sinks
this
caiyong@caiyong:/opt/hadoop$ bin/hadoop fs -cat /flume2sink/ts*/*mp
is
a
test
OK,byebye.
分析:创建的配置文件设置了一个Netcat信源和两个信宿(file信宿和HDFS信宿),设置了两个memory信道分别连接信源和两个信宿。设置信源选择器类型为replicating,这样所有事件都会发送给两个信道。
0 0
- Flume把事件写入多个信宿
- Flume把网络数据写入HDFS
- Flume把命令执行结果写入平面文件
- 模拟使用Flume监听日志变化,并且把增量的日志文件写入到hdfs中
- C#把错误信息写入到windows事件中
- asp.net中如何把应用程序错误写入事件日志(注册事件源)
- 把图片写入数据库
- flume读取日志数据写入kafka
- flume读取日志数据写入kafka
- Flume-将数据写入动态分区表
- flume 写入hdfs 采用lzo 格式 教程
- 使用Log4j将日志实时写入Flume
- flume使用hive stream写入到hive
- Hive读取Flume正在写入的HDFS
- 写入事件日志中
- 写入log事件
- Flume把网络流量存入日志文件
- 把内容写入硬盘文件
- mysql 子查询与连接
- 【高效算法设计——二分法】UVa 1607 Gates
- linux下双网卡绑定——实现:失效保护(冗余)和双网卡负载均衡
- TCP-IP协议详解(4)地址耗尽危机(IPv4与IPv6地址)
- java开发中的23种设计模式
- Flume把事件写入多个信宿
- 不安装Oracle客户端使用PLSQL
- 设计模式之单例模式
- Machine Learning Trends from NIPS 2014
- 广州笔记本液晶屏维修简介
- Linux ls命令参数详解
- 简单的java缓存实现
- Oracle 多表查询优化
- Response