It’s no secret that Apache is the most popular web server in use today. Netcraft has Apache usage at 47.8% as of February 2015, and according to w3techs, Apache is used by 55% of all of the websites they monitor (with NGINX trailing behind at 27%).
Why is Apache so popular? It’s free and open source – and open source is becoming vastly more popular than proprietary software. It’s maintained by a bunch of dedicated developers, it provides security and is well suited for small and large websites alike, and it can be easily set up on all major operating systems and is extremely powerful and flexible. Does that sound about right?
The big “but” here is that this popularity does not necessarily reflect the challenges facing organizations running business-critical apps on Apache, one of these being log analytics. Being able to gain insight into Apache access and error logs is crucial for analyzing crashes, load times, and other data on app performance. But in production environments in which huge amounts of requests are sent to the web server every second, extracting actionable data from thousands of log files is virtually impossible.
This tutorial will show you one easy way to do just that — by describing how to ship and analyze Apache logs using Logz.io, our predictive, cloud-based log management platform that’s built on top of the open-source ELK Stack (Elasticsearch, Logstash, Kibana). This tutorial can be used with any on-premise installation of the ELK Stack. I’ll just use Logz.io for simplicty’s sake.
This guide will take you through the steps of using our service on a vanilla Linux environment (Ubuntu 12.04) — setting up your environment, shipping logs, and then creating visualizations in Kibana.
Let’s get started!
PrerequisitesTo complete the steps below, you’ll need the following:
A common Linux distribution with TCP traffic allowed to port 5000 An active Logz.io account. If you don’t have one yet, you can create a free account here. 5 minutes of free time! Step 1: Setting up your environmentThe first step will help you install the various prerequisites required for shipping logs to Logz.io.
Installing ApacheIf you’ve already got Apache up and running, great! You can skip to the next step.
If you’re not sure (yes, this happens!), use the next command to see a list of all your Apache packages:
dpkg --get-selections | grep apache
If Apache is not installed, enter the following commands:
$ sudo apt-get update $ sudo apt-get install apache2
This may take a few seconds as Apache and its required packages are installed. Once done, apt-get will exit and Apache will be installed.
By default, Apache listens on port 80, so to test if it’s installed correctly, simply point your browser to: http://localhost:80.
Installing RsyslogLogz.io uses Rsyslog for shipping logs. If you already have Rsyslog installed, excellent. Before skipping to the next step, however, make sure your installed version complies with Logz.io’s minimal requirement (version 5.8.0 and above):
$ rsyslogd -version
If Rsyslog is not installed, use:
$ sudo apt-get install rsyslog
Another good option for shipping logs to Logz.io is Filebeat. A dedicated tutorial on installing and using Filebeat is forthcoming.
Installing CurlAs the Logz.io automatic installation script uses cURL, you will need to install it before continuing on:
$ sudo apt-get install curlStep 2: Shipping Apache logs to Logz.io
There are two ways to configure the shipping of your Apache logs to Logz.io — one uses an automated cURL script and the other necessitates some manual spooling and configurations and is better in case you’re shipping larger chunks of data.
In this tutorial, though, we won’t be handling large amounts of data and the automatic script will do us just fine:
curl -sLO https://github.com/logzio/logzio-shipper/raw/master/dist/logzio-rsyslog.tar.gz && tar xzf logzio-rsyslog.tar.gz && sudo rsyslog/install.sh -t apache -a "<token>"
Next, restart Rsyslog:
ship-apache-log-filesStep 3: Verifying the shipping pipeline
Our next step is to make sure our log pipeline is configured correctly.
Place a new HTML file called ‘hello.html’ in the web server’s root directory (Apache’s root directory varies according to your Linux distribution) with some simple static code:
<html> <h1>Watch out sir! Logs on the way!</h1> </html>
To make things interesting, let’s simulate some load on the server using ApacheBench (which is bundled with Apache):
$ sudo ab -k -c 350 -n 1000 localhost/hello.html
This will simulate some traffic and create a batch of log entries.
Wait a minute or two, access the Logz.io interface, and open the Kibana dashboard. Then, select the Discover tab and enter ‘200’ in the search field at the top of the page.
Apache access logs are displayed for any request returning a 200 response code.
If you want to play around with more complex data, you can download some sample access logs and upload them to Logz.io using the following cURL command. Be sure to replace the placeholders with your info — the full path to the file and your Logz.io token (which can be found in the Logz.io user settings):
curl -T <Full path to file> http://listener.logz.io:8021/file_upload/<Token>/apache_accessStep 4: Visualizing Apache logs in Kibana
Now that our pipeline is up and running, it’s time to have some fun.
You can begin to use Kibana to search for specific data strings. You can search for specific fields, use logical statements, or perform proximity searches — Kibana’s search options are varied and are covered extensively in our Kibana tutorial.
But how about taking these searches to an entirely new level? Kibana allows you to create visualizations from your search results, meaning that the data you’re interested in is reflected in easy-to-use, easy-to-create, and shareable graphical dashboards.
To create a new visualization from a custom search, first save the search by clicking the “Save Search” icon in the top-right corner in the Kibana “Discover” tab.
Once saved, select the Visualize tab:
You have a variety of dashboard types to select from including pie charts, line charts, and gauge graphs.
You then need to select a data source to use for the visualization. You can choose a new or saved search to serve as the data source. Go for the ‘From a saved search’ option and select the search you saved just a minute ago.
Please note that the search you selected is now bound to this specific visualization, so when you make changes to this search from now on, the visualization will update automatically (though you can unlink the two, if you like).
You can now use the Visualization Editor to customize your dashboard (more information on this will be published soon) and save the visualization. If you wish, you can also add it to your Kibana Dashboard or even share it by embedding it in HTML or by sharing a public link.
You also have the option of using ELK Apps, which is our free library of pre-made dashboards that have already been fine-tuned by Logz.io to suit specific types of log data.
For Apache logs, there are ten available ELK Apps to use including an “Apache Average Byte”’ app that monitors the average amount of bytes sent from your Apache web server and the extremely popular “Apache Access” app that shows a map of your users, response times and codes, and more.
Installing these visualizations is easy — simply select the ELK Apps tab and search for “Apache” (or click here directly).
To use a specific visualization, simply click the Install button and then the Open button.
The ELK app will then be loaded in the Visualization editor, so you can then fine-tune it to suit your personal needs and preferences and then load it in the Dashboard tab:
What Next?Once you’ve set up your dashboard in Kibana for monitoring and analyzing Apache logs, you can set up an alerting system to notify you (via either email or Slack) when something has occurred in your environment that exceeds your expectations of how Apache and the serviced apps are meant to be performing. Logz.io’s alerting feature allows you to do just that, and we’ll be diving deeper into the rabbit hole in our next tutorial.
Logz.io offers enterprise-grade ELK as a service with alerts, unlimited scalability, and collaborative analytics
Start your free trial!The ELK Stack as an Apache Log Analyzer was first posted on March 7, 2016 at 11:02 am.
©2016 "Logz.io". Use of this feed is for personal non-commercial use only. If you are not reading this article in your feed reader, then the site is guilty of copyright infringement. Please contact me at shani@anymation.co.il