Use flume to crawl Tomcat log files and sink to Kafka consumption

Source: Internet
Author: User
Tags zookeeper

Tomcat Production Log

Flume crawl log sinking into Kafka

    1. Package a well-written Web project into a war package, Eclise Direct export Export,idea Add a new Artifact-achieve entry in artifact, select the directory where the Web project resides, and build
    2. In the Linux Tomcat WebApp directory into the war package, when you start Tomcat under the bin, the war package will be automatically decompressed, and then accessed from the browser, note that the form of http://bigdata2:8080/WebAnalysis_war/host : 8080/+ Project file name
    3. Configure the Flume conf file as follows and crawl directly to Kafka

Agent.sinks = K1

Agent.sources = S1

Agent.sources = S1

Agent.channels = C1

Agent.sinks = K1

Agent.sources.s1.type=exec

Agent.sources.s1.command=tail-f/home/bigdata/weblogs/access.log

Agent.sources.s1.channels=c1

Agent.channels.c1.type=memory

agent.channels.c1.capacity=10000

agent.channels.c1.transactioncapacity=100

#设置Kafka接收器

Agent.sinks.k1.type= Org.apache.flume.sink.kafka.KafkaSink

#设置Kafka的broker地址和端口

agent.sinks.k1.brokerlist=bigdata3:9092

#设置Kafka的Topic

Agent.sinks.k1.topic=kafkatest

#设置序列化方式

Agent.sinks.k1.serializer.class=kafka.serializer.stringencoder

Agent.sinks.k1.channel=c1

Start flume

Flume-ng agent-c conf-f/home/bigdata/flumeconf/log_kafka.log-n agent-dflume.root.logger=info,console

    1. Start Kafka

./kafka-server-start.sh-daemon. /config/server.properties

If the topic is not created, the new topic

bin/kafka-topics.sh--create--zookeeper localhost:2181--replication-factor 1--partitions 1--topic kafkatest

Start the consumer

./kafka-console-consumer.sh--zookeeper bigdata3:2181--topic kafkatest--from beginning

    1. Click on the JSP to add log file content, in the Kafka can be consumed in the
    2. Solve Chinese garbled problem

1 modifying Tomcat's Server.xml file:

<connector connectiontimeout= "20000" port= "8080" protocol= "http/1.1" redirectport= "8443" URIEncoding= "UTF-8" Usebodyencodingforuri= "true"/>

2 form Chinese garbled, under <%@ page%> add a sentence <% request.setcharacterencoding ("Utf-8");%>

or add request.setcharacterencoding ("Utf-8") to the servlet

Use flume to crawl Tomcat log files and sink to Kafka consumption

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.