Tomcat Production Log
Flume crawl log sinking into Kafka
- 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
- 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
- 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
- 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
- Click on the JSP to add log file content, in the Kafka can be consumed in the
- 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