A Quick Guide to Analyzing Apache Logs on Alibaba Cloud Log Service

简介: This article describes how you can deploy Logstash and Kibana on Alibaba Cloud Log Service to monitor, analyze, and visualize Apache logs.

With Alibaba Cloud Log Service, there are several methods available for you to collect upstream data. You can use the built-in LogSearch and LogAnalytics functions, or you can deploy the more familiar ElasticSearch, Logstash, and Kibana (ELK) stack. In this article, we will discuss how you can build your own ELK stack on Alibaba Cloud Log Service to analyze and monitor Apache logs.

Installing Logstash Within the ECS

First, we need to install and deploy Logstash within the ECS. When you subscribe to the ECS service, be sure to prepare JDK version 1.8 or higher.

wget https://artifacts.elastic.co/downloads/logstash/logstash-5.5.3.tar.gz

Decompress and install

tar -xzvf logstash-5.5.3.tar.gz 

Establishing the Logstash Pipeline

In order to write data to ElasticSearch with Logstash, first we need to establish a Logstash pipeline, which has three parts:

input {   
}
# a note in this section indicates that this filter can be selected
filter {  
}
output {   
}

  • Set input to the data source
  • Set output to the target
  • A filter is optional, you can normally use it to set data filtering logic

Settings for this section are quite simple. Create a .conf file in the Logstash directory, then set input and output according to the following format:

input {
    file {
        path => "/usr/local/demoData/*.log"
        start_position => beginning
    }
}
output {
    ElasticSearch {
        hosts => ["http://*******************:9200"]
        user => "*******"
        password => "***********"
    }
}

Note: Because ElasticSearch is preset with the X-Pack plugin, you must verify all access. This will require you to set a username and password in the output.

Let us take a case where we need to send the Apache log indexing frequently generated by Alibaba Cloud ECS to ElasticSearch. We can deploy Logstash to the ECS on which the web server is running. If there are concerns about this affecting the application running on the web server, you can deploy Logstash to any accessible ECS over the network.

Note: Logstash input can handle different forms of input. If you have deployed a Logstash to a network-accessible ECS, you will need to configure an http template as an input as follows:

input {
 http {
      host => "**********"
   port => "**********"
 }
}

Because ElasticSearch is deployed in a VPC environment, if the ECS on which Logstash is deployed is on a classic network, then the VPC needs to be connected to via the Classiclink method.

Analyzing Apache Logs Using Logstash Filter

Let us now see how one can quickly analyze Apache logs using a Logstash filter. An Apache log typically contains the following information:

1

Table 1

To retrieve user distribution information from the log and make it more intuitive for non-technical users, we can use the Gork filter to analyze the Apache network logs.

filter {
    grok {
        match => { "message" => "%{COMBINEDAPACHELOG}"}
    }
}

We can take the original log information:

66.249.73.135 - - [04/Jan/2015:05:30:06 +0000] "GET /blog/web/firefox-scrolling-fix.html HTTP/1.1" 200 8956 "-" "Mozilla/5.0 (iPhone; CPU iPhone OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A5376e Safari/8536.25 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)"

Then filter it into standard JSON structure:

{
"clientip" : "66.249.73.135",
"ident" : ,
"auth" : ,
"timestamp" : "04/Jan/2015:05:30:06 +0000",
"verb" : "GET",
"request" : "/blog/web/firefox-scrolling-fix.html",
"httpversion" : "HTTP/1.1",
"response" : "200",
"bytes" : "8956",
"referrer" : "http://www.google.com/bot.html",
"agent" : "Mozilla/5.0 (iPhone; CPU iPhone OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A5376e Safari/8536.25"
}

We can then extract the IP to discern the user location using geoip.

filter {
    geoip {
        source => "clientip"
    }
}

Once we have the address information from the IP, we can enter a geoip field into the log information. We can receive the following information by checking an IP with geoip:

"geoip":{
        "timezone":"America/Los_Angeles",
        "ip":"66.249.73.135",
        "latitude":37.419200000000004,
        "continent_code":"NA",
        "city_name":"Mountain View",
        "country_name":"United States",
        "country_code2":"US",
        "dma_code":807,
        "country_code3":"US",
        "region_name":"California",
        "location":{
               "lon":-122.0574,
               "lat":37.419200000000004
        },
        "postal_code":"94043",
        "region_code":"CA",
        "longitude":-122.0574
},

Using Kibana, we can use the coordinate information stored in the location key from geoip. Subsequently, we can then create a visualization of the geographic distribution of users’ access locations.

With the above method, we can analyze ECS logs in batch and complete the configuration in Kibana.

You can get more information on Configuring Logstash here.

Conclusion

You can analyze and monitor logs with the LogSearch and LogAnalytics on Alibaba Cloud Log Service, or deploy your own ElasticSearch, Logstash, and Kibana (ELK) stack. Each option comes with its own set of benefits, and the effectiveness is highly dependent on your application.

I hope this blog helped you understand how you can install Logstash on Alibaba Cloud ECS and use it for analysis of Apache logs. To know more about Alibaba Cloud Log Service, visit the official product page or the official product documentation.

相关实践学习
【涂鸦即艺术】基于云应用开发平台CAP部署AI实时生图绘板
【涂鸦即艺术】基于云应用开发平台CAP部署AI实时生图绘板
目录
相关文章
|
JSON Java API
【干货满满】分享京东API接口到手价,用Java语言实现
本示例使用 Java 调用京东开放平台商品价格及优惠信息 API,通过商品详情和促销接口获取到手价(含优惠券、满减等),包含签名生成、HTTP 请求及响应解析逻辑,适用于比价工具、电商系统集成等场景。
|
人工智能 运维 Prometheus
别等系统“炸了”才慌!聊聊AI搞运维故障检测的那些真香时刻
别等系统“炸了”才慌!聊聊AI搞运维故障检测的那些真香时刻
638 0
|
程序员 编译器 C#
C#语言中使用"using"关键字的介绍
以上就是 C# 中 "using" 关键字的主要用法。了解并熟练应用这个关键字,对于提高代码质量、解决命名冲突、管理资源都有着重要的作用。它是 C# 编程中不可或缺的一部分,无论是对初学者还是有经验的开发者而言,掌握它都是提高编写高效、清晰、可维护代码的关键。
388 7
|
安全 生物认证 数据安全/隐私保护
微信加人频繁怎么快速解除???
微信加人频繁限制的技术分析与解决方案 1. 微信加人限制机制解析
|
设计模式 Java API
Java 高效开发实战之让代码质量飙升的 10 个黄金法则技巧
本文分享了10个提升Java代码质量的黄金法则,涵盖日志优化、集合操作、异常处理、资源管理等方面。通过参数化日志减少性能开销,利用Stream与Guava简化集合操作,采用CompletableFuture优化并发处理,运用Optional避免空指针异常等实战技巧,结合具体案例解析,助你写出高效、高质量的Java代码。
560 1
|
机器学习/深度学习 数据可视化 数据处理
构建可靠的时间序列预测模型:数据泄露检测、前瞻性偏差消除与因果关系验证
在时间序列分析中,数据泄露、前瞻性偏差和因果关系违反是三大常见且严重影响模型有效性的技术挑战。数据泄露指预测模型错误使用了未来信息,导致训练时表现优异但实际性能差;前瞻性偏差则是因获取未来数据而产生的系统性误差;因果关系违反则可能导致虚假相关性和误导性结论。通过严格的时序数据分割、特征工程规范化及因果分析方法(如格兰杰因果检验),可以有效防范这些问题,确保模型的可靠性和实用性。示例分析展示了日本天然气价格数据中的具体影响及防范措施。 [深入阅读](https://avoid.overfit.cn/post/122b36fdb8cb402f95cc5b6f2a22f105)
1067 24
构建可靠的时间序列预测模型:数据泄露检测、前瞻性偏差消除与因果关系验证
|
机器学习/深度学习 数据采集 算法
特征工程与数据预处理全解析:基础技术和代码示例
在机器学习和数据科学的世界里,数据的质量是建模成功与否的关键所在。这就是特征工程和数据预处理发挥作用的地方。本文总结的这些关键步骤可以显著提高模型的性能,获得更准确的预测,我们将深入研究处理异常值、缺失值、编码、特征缩放和特征提取的各种技术。
657 0
|
数据挖掘 C++
使用R语言进行时间序列分析
【4月更文挑战第25天】时间序列分析是一种重要的数据分析方法,广泛应用于经济学、金融学、气象学、生态学等领域。R语言是一种强大的统计分析工具,提供了丰富的函数和包用于时间序列分析。本文将介绍使用R语言进行时间序列分析的基本概念、方法和实例,帮助读者掌握R语言在时间序列分析中的应用。
622 2

热门文章

最新文章