GoAccess is a free and open-source web log analyzer that allows you to monitor and analyze your web server logs in real-time. In this article, we will learn how to install and configure GoAccess on Rocky Linux 8.
Prerequisites
Before we begin, make sure that you have a clean installation of Rocky Linux 8 and a user with sudo privileges. You will also need to have the following packages installed:
- build-essential: This package includes the tools required to build and compile software from source.
- ncurses: This package provides the curses library, which is required by GoAccess to display the log data on the terminal.
To check if the build-essential
and ncurses
packages are installed, run the following command:
dpkg -s build-essential ncurses
If the packages are installed, you should see a message saying Status: install ok installed
for each package. If the packages are not installed, you will need to install them by running the following command:
sudo apt install build-essential ncurses
Installing GoAccess
To install GoAccess, we will first download the latest version of the GoAccess source code from the official website. You can find the latest version of GoAccess at the following URL:
<https://tar.goaccess.io/goaccess-1.4.tar.gz>
Replace 1.4
with the latest version of GoAccess.
To download the source code, run the following command:
wget <https://tar.goaccess.io/goaccess-1.4.tar.gz>
Next, we will extract the downloaded archive and change into the resulting directory. To do this, run the following commands:
tar xzf goaccess-1.4.tar.gz
cd goaccess-1.4
Now, we can compile and install GoAccess by running the following commands:
./configure
make
sudo make install
The installation process will take a few minutes to complete. Once the installation is finished, you can verify that GoAccess is installed by running the following command:
goaccess --version
You should see a message with the version of GoAccess that is installed on your system.
Configuring GoAccess
Now that GoAccess is installed, we can configure it to analyze our web server logs.
To configure GoAccess, we will need to create a configuration file. This file tells GoAccess where to find the log files and how to parse them.
To create a configuration file, run the following command:
sudo touch /etc/goaccess.conf
This will create an empty configuration file at the specified location.
Next, open the configuration file in a text editor. For example, you can use the nano
editor by running the following command:
sudo nano /etc/goaccess.conf
In the configuration file, add the following lines:
time-format %H:%M:%S
date-format %d/%b/%Y
log-format %h %^[%d:%t %^] "%r" %s %b
These lines specify the format of the log entries in the log files. Make sure to adjust these settings to match the format of your log files.
Next, we will tell GoAccess where to find the log files. To do this, add the following line to the configuration file:
log-file /var/log/nginx/access.log
Replace /var/log/nginx/access.log
with the path to your web server’s access log file. If you are using a different web server, the path to the access log file may be different.
Once you have added the necessary settings to the configuration file, save the file and exit the text editor.
Analyzing Log Files
Now that GoAccess is installed and configured, we can use it to analyze our web server logs.
To analyze a log file, run the following command:
goaccess /var/log/nginx/access.log -c
Replace /var/log/nginx/access.log
with the path to your web server’s access log file.
This will run GoAccess and display the log data on the terminal. The data is grouped by different metrics, such as the number of requests per minute, the top visitors, and the top URLs. You can navigate through the data using the arrow keys and search for specific entries using the /
key.
If you want to generate an HTML report, you can add the --html-report
option to the command. For example:
goaccess /var/log/nginx/access.log -c --html-report
This will generate an HTML report in the current directory. You can open the report in a web browser to view it.
There are many ways that you can use GoAccess to monitor and analyze your web server logs. Some examples include:
- Monitoring the number of requests per minute to identify spikes in traffic and potential performance bottlenecks.
- Analyzing the top visitors to identify the countries and browsers that are most commonly used to access your website.
- Examining the top URLs to see which pages on your website are most popular and which ones have the highest number of errors.
- Generating reports to share with your team or customers to show the performance and usage of your website.
- Setting up alerts to notify you when certain thresholds are reached, such as a high number of errors or slow response times.
These are just a few examples of how you can use GoAccess to monitor and analyze your web server logs. The tool is highly customizable, so you can use it to extract the information that is most relevant to you and your website.
Conclusion
In this article, we learned how to install and configure GoAccess on Rocky Linux 8. We downloaded the source code, compiled and installed GoAccess, and created a configuration file to tell GoAccess how to parse the log files. Finally, we ran GoAccess to analyze the log files and generate an HTML report. GoAccess is a powerful tool that allows you to monitor and analyze your web server logs in real-time.