CentOS 7部署flume
准备工作:##
安装java并设置java环境变量,在`/etc/profile`中加入
export JAVA_HOME=/usr/java/jdk1.8.0_65
export PATH=$PATH:$JAVA_HOME/bin
注意事项
需要启动多个shell脚本交互客户端进行验证,运行中的客户端不要停止。
安装flume
下载:
wget http://mirrors.hust.edu.cn/apache/flume/1.6.0/apache-flume-1.6.0-bin.tar.gz
解压:
tar -zxvf apache-flume-1.6.0-bin.tar.gz
移动到指定目录:
mv apache-flume-1.6.0 /usr/local/flume
配置
source 使用 necat 类型,sink 采用 file_roll 类型, 从监听端口获取数据,保存到本地文件。 拷贝配置模板:
cp conf/flume-conf.properties.template conf/flume-conf.properties
编辑配置如下:
# The configuration file needs to define the sources,
# the channels and the sinks.
# Sources, channels and sinks are defined per agent,
# in this case called 'agent'
agent.sources = r1
agent.channels = c1
agent.sinks = s1
# For each one of the sources, the type is defined
agent.sources.r1.type = netcat
agent.sources.r1.bind = localhost
agent.sources.r1.port = 8888
# The channel can be defined as follows.
agent.sources.r1.channels = c1
# Each sink's type must be defined
agent.sinks.s1.type = file_roll
agent.sinks.s1.sink.directory = /tmp/log/flume
#Specify the channel the sink should use
agent.sinks.s1.channel = c1
# Each channel's type is defined.
agent.channels.c1.type = memory
# Other config values specific to each type of channel(sink or source)
# can be defined as well
# In this case, it specifies the capacity of the memory channel
agent.channels.c1.capacity = 100
功能验证
1.建立输出目录
mkdir -p /tmp/log/flume
2.启动服务
bin/flume-ng agent --conf conf -f conf/flume-conf.properties -n agent&
运行日志位于logs目录,或者启动时添加-Dflume.root.logger=INFO,console 选项前台启动,输出打印日志,查看具体运行日志,服务异常时查原因。
3.发送数据
telnet localhost 8888
输入
hello world!
hello Flume!
4.查看数据文件 查看 /tmp/log/flume 目录文件:###
# 文件名不同,需要根据实际情况修改和查看
cat /tmp/log/flume/1447671188760-2
hello world!
hello Flume!
参考文档: