1.安装netcat
rpm -ivh ./*.rpm
重启xineted
./etc/rc.d/init.d/xineted restart
2.使用flume命令
$ bin/flume-ng
Usage: bin/flume-ng <command> [options]...
commands:
agent run a Flume agent
global options:
--conf,-c <conf> use configs in <conf> directory
-Dproperty=value sets a Java system property value
agent options:
--name,-n <name> the name of this agent (required)
--conf-file,-f <file> specify a config file (required if -z missing)
>>>>>>>>>>>>>>>>>>>>>>>>>>命令格式
bin/flume-ng agent --conf conf --name agent-test --conf-file test.conf
bin/flume-ng agent -c conf -n agent-test -f test.conf
—————————————————————— **配置文件**—————————
# The configuration file needs to define the sources,
# the channels and the sinks.
### define agent
a1.sources = r1
a1.channels = c1
a1.sinks = k1
### define sources
a1.sources.r1.type = netcat
a1.sources.r1.bind = hadoop-senior-CDH
a1.sources.r1.port = 44444
### define channels
a1.channels.c1.type = memory
a1.channels.c1.capacity = 1000
a1.channels.c1.transactionCapacity = 100
### define sink
a1.sinks.k1.type = logger
a1.sinks.k1.maxBytesToLog = 2014
### bind the soures and sink to the channel
a1.sources.r1.channels = c1
a1.sinks.k1.channel = c1.
3.运行
(1) 在Flume目录执行
bin/flume-ng agent \
-c conf \
-n a1 \
-f conf/a1.conf \
-Dflume.root.logger=DEBUG,console
(2)查看端口,启动了44444端口
netstat -tnlp
tcp 0 0 ::ffff:192.168.88.131:44444 :::* LISTEN 3278/java
(3)通过44444端口发送数据
telnet hadoop-CDH 44444
Trying 192.168.88.131...
Connected to hadoop-CDH.
Escape character is '^]'.
aa
OK
hello flume
OK
hi
OK
(4)收到消息
2017-05-02 04:20:42,369 (SinkRunner-PollingRunner-DefaultSinkProcessor) [INFO - org.apache.flume.sink.LoggerSink.process(LoggerSink.java:70)] Event: { headers:{} body: 68 65 6C 6C 6F 20 66 6C 75 6D 65 0D hello flume. }