首页 > 代码库 > flume收集tomcat日志保存到本地目录

flume收集tomcat日志保存到本地目录

下载flume和jdk

flume下载地址:

wget https://mirrors.cnnic.cn/apache/flume/1.6.0/apache-flume-1.6.0-src.tar.gz

技术分享


解压文件

tar zxvf apache-flume-1.6.0-src.tar.gz

移动指定目录

mv apache-flume-1.6.0-src.tar.gz /usr/local


进入/etc/profile.d目录,添加java.sh文件,添加环境变量

JAVA_HOME=/usr/local/java
JAVA_BIN=/usr/local/java/bin
JRE_HOME=/usr/local/java/jre
FLUME_HOME=/usr/local/flume
CATALINA_HOME=/usr/local/tomcat
CLASS_PATH="$JAVA_HOME/lib:$JRE_HOME/lib:$JRE_HOME/lib/charsets.jar"
export PATH=$PATH:$JAVA_HOME/bin:$CATALINA_HOME/bin:$FLUME_HOME/bin


让环境变量生效

source /etc/profile


创建vim /usr/local/flume/conf/tomcat.conf

a1.sources = s1

a1.sources.s1.type = exec

a1.sources.s1.command = tail -F /usr/local/tomcat/logs/catalina.out

a1.sources.s1.channels = m1

a1.channels = m1

a1.channels.m1.type = memory

a1.channels.m1.capacity = 1000

a1.channels.m1.transactionCapacity = 100

   

a1.sinks = LocalOut

a1.sinks.LocalOut.type = file_roll

a1.sinks.LocalOut.sink.directory = /opt/data

a1.sinks.LocalOut.sink.rollInterval = 0

a1.sinks.LocalOut.channel = m1


进入flume目录

cd /usr/local/flume/conf

执行

flume-ng agent -c . -f /usr/local/flume/conf/exec_tail.conf -n a1 -Dflume.root.logger=INFO,console



查看保存目录,已保存

ll /opt/data

技术分享

flume收集tomcat日志保存到本地目录