注意:前提是安装好了 kafka 请看另一篇docker 安装 zk 和 kafka
1. 下载flume
地址:http://flume.apache.org/ 版本:apache-flume-1.9.0-bin.tar.gz
2. 解压及移动
tar zxvf apache-flume-1.8.0-bin.tar.gz
sudo mv apache-flume-1.8.0-bin /usr/local
3. 创建文件log-kafka.properties
cd flume/conf
touch log-kafka.properties
4. 配置文件
agent.sources = exectail
agent.channels = memoryChannel
agent.sinks = kafkasink
# For each one of the sources, the type is defined
agent.sources.exectail.type = exec
agent.sources.exectail.command = tail -f
/home/bigdata/cluster/apache-tomcat-8.5.23/logs/save.log #日志保存地址
agent.sources.exectail.interceptors=i1
agent.sources.exectail.interceptors.i1.type=regex_filter
agent.sources.exectail.interceptors.i1.regex=.+USER_TEST_PRE.+ #自定义样式#
# The channel can be defined as follows.
agent.sources.exectail.channels = memoryChannel
# Each sink's type must be defined
agent.sinks.kafkasink.type = org.apache.flume.sink.kafka.KafkaSink
agent.sinks.kafkasink.kafka.topic = log
agent.sinks.kafkasink.kafka.bootstrap.servers =localhost:9092 #kafka 地址
agent.sinks.kafkasink.kafka.producer.acks = 1
agent.sinks.kafkasink.kafka.flumeBatchSize = 20
#Specify the channel the sink should use
agent.sinks.kafkasink.channel = memoryChannel
# Each channel's type is defined.
agent.channels.memoryChannel.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.memoryChannel.capacity = 10000
5. 启动
./bin/flume-ng agent -c ./conf/ -f ./conf/log-kafka.properties -n agent -Dflume.root.logger=INFO,console