How to Install and Use GoAccess on CentOS for Fast Log Analysis

goaccesscentos log analysisnginx log reportautomated html reportcrontab scheduling
Published·Modified·

GoAccess is designed as a fast, terminal-based log analyzer. Its core philosophy is to provide real-time, rapid analysis and viewing of web server statistics. GoAccess can analyze logs from Apache, Nginx, and other web servers, and supports generating reports in HTML, JSON, and CSV formats.

GoAccess Dashboard

Installing GoAccess

GoAccess supports installation via yum. You can simply execute the command yum -y install goaccess. However, for greater flexibility, it is recommended to compile and install it using the following method:

# Install dependencies
yum -y install libmaxminddb-devel ncurses-libs ncurses-devel openssl openssl-devel
# Download source code
wget https://tar.goaccess.io/goaccess-1.2.tar.gz
# Extract archive
tar -xzvf goaccess-1.2.tar.gz
# Enter directory
cd goaccess-1.2/
# Compile and install
./configure --enable-utf8 --enable-geoip=mmdb --with-openssl --with-libmaxminddb-devel
make && make install

If successful, you can check the version by running goaccess -V. For more compilation parameters, refer to the official documentation: https://goaccess.io/download.

Version Check

Running GoAccess

The simplest approach is to run goaccess [log_path] and follow the prompts. If you prefer not to use the terminal interface, you can generate a static HTML report by running the following command:

goaccess xiaoz.me_nginx.log -a -o xxx.html --log-format=COMBINED
  • xiaoz.me_nginx.log: The specific path to the log file.
  • xxx.html: The name of the HTML report, which can be saved to the site directory for direct access.
  • --log-format=: The log file format; COMBINED is the standard format.

Automating HTML Report Generation to Site Directory

Manually generating reports every time can be tedious. A simple shell script can automate this process. Save the following content as goaccess.sh:

#!/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin
export PATH
goaccess xiaoz.me_nginx.log -a -o /xiaoz.me/$(date +%Y-%m-%d).html --log-format=COMBINED
  • xiaoz.me_nginx.log: Path to the log file (please use the absolute path).
  • /xiaoz.me/: Your site's root directory (modify according to your setup).

Don't forget to add executable permissions: chmod u+x goaccess.sh, and then use crontab to generate an HTML report every hour.

# Add scheduled task
crontab -e
# Add the following line, where /root/goaccess.sh is the absolute path to the script above
0 * * * * /root/goaccess.sh > /dev/null
# Reload crontab
service crond reload

With this setup, GoAccess will generate an HTML log report every hour. After waiting a while, visit https://domain.com/[current_date].html (e.g., 2017-07-16) to view the intuitive HTML report.

HTML Report Example

Summary

GoAccess supports additional features, such as analyzing multiple log files simultaneously and IP lookup. For more usage help, you can check goaccess -h. Previously, we also shared a log analysis tool for Windows called 360 Star Map, which is also excellent and features Chinese display for better usability.

GoAccess Official Website: https://goaccess.io/ Demo Address: https://rt.goaccess.io/?20180613194436