准备工作
安装Flume服务端
1、安装jdk,配置好环境变量。2、安装hadoop,配置好环境变量
2、解压Flume
tar -zxvf apache-flume-1.3.1-bin.tar.gz3、创建软链接
配置服务端ln -s /root/tools/apache-flume-1.3.1-bin /usr/local/flume
1、配置flume-env.sh文件中的JAVA_HOME2、配置flume-conf.properties文件
启动Flume服务端
agent.sources = avrosrcagent.channels = memoryChannelagent.sinks = hdfsSink
# For each one of the sources, the type is definedagent.sources.avrosrc.type = avroagent.sources.avrosrc.bind = 192.168.75.190agent.sources.avrosrc.port = 41414
# The channel can be defined as follows.agent.sources.avrosrc.channels = memoryChannel
# Each channel's type is defined.agent.channels.memoryChannel.type = memoryagent.channels.memoryChannel.keep-alive = 10agent.channels.memoryChannel.capacity = 100000agent.channels.memoryChannel.transactionCapacity =100000
# Each sink's type must be definedagent.sinks.hdfsSink.type = hdfsagent.sinks.hdfsSink.channel = memoryChannelagent.sinks.hdfsSink.hdfs.path = /logdata/%{hostname}_linux/%Y%m%d_dateagent.sinks.hdfsSink.hdfs.filePrefix = %{datacenter}_agent.sinks.hdfsSink.hdfs.rollInterval = 0agent.sinks.hdfsSink.hdfs.rollSize = 4000000agent.sinks.hdfsSink.hdfs.rollCount = 0agent.sinks.hdfsSink.hdfs.writeFormat = Textagent.sinks.hdfsSink.hdfs.fileType = DataStreamagent.sinks.hdfsSink.hdfs.batchSize = 10
1、启动命令:
/usr/local/flume/bin/flume-ng agent -c /usr/local/flume/conf/ -f /usr/local/flume/conf/flume-conf.properties -n agent&2、查看日志cat /usr/local/flume/logs/flume.log,如果没有错误,则启动成功。
3、 netstat -an|grep 41414,看端口是否启动成功
FlumeSource端配置安装
FlumeSource端配置安装和Flume服务端一样,不做赘述。
1、配置flume-env.sh文件中的JAVA_HOME2、配置flume-conf.properties文件
启动FlumeSource端
agent.sources = tailsourceagent.channels = memoryChannelagent.sinks = remotesink
agent.sources.tailsource.type = execagent.sources.tailsource.command = tail -F /tmp/linux2.logagent.sources.tailsource.channels = memoryChannel
agent.sources.tailsource.interceptors = host_int timestamp_int inter1agent.sources.tailsource.interceptors.host_int.type = hostagent.sources.tailsource.interceptors.host_int.hostHeader = hostname
agent.sources.tailsource.interceptors.timestamp_int.type = org.apache.flume.interceptor.TimestampInterceptor$Builder
#agent.sources.tailsource-1.interceptors = inter1agent.sources.tailsource.interceptors.inter1.type = staticagent.sources.tailsource.interceptors.inter1.key = datacenteragent.sources.tailsource.interceptors.inter1.value = BEIJING
agent.channels.memoryChannel.type = memoryagent.channels.memoryChannel.keep-alive = 10agent.channels.memoryChannel.capacity = 100000agent.channels.memoryChannel.transactionCapacity =100000
agent.sinks.remotesink.type = avroagent.sinks.remotesink.hostname = 192.168.75.190agent.sinks.remotesink.port = 41414agent.sinks.remotesink.channel = memoryChannel
1、创建/tmp/linux2.log测试文件。
2、启动命令:测试Flume/usr/local/flume/bin/flume-ng agent -c /usr/local/flume/conf/ -f /usr/local/flume/conf/flume-conf.properties -n agent&3、查看日志cat /usr/local/flume/logs/flume.log,如果没有错误,则启动成功。
1、FlumeSource端口执行命令:
for i in {1000..1000000}; do echo "LINUX2 PRESS ************* Flume log rotation $i" >> /tmp/linux2.log; sleep 1; done
2、Hadoop端查看hdfs文件是否有文件,文件是否定时接收新数据。