Qadry
unixcop Admin

How To Install GoAccess On Linux

Introduction

GoAccess is an open source real-time web log analyzer and interactive viewer that runs in a terminal in *nix systems or through your browser.

It provides fast and valuable HTTP statistics for system administrators that require a visual server report on the fly.

GoAccess was designed to be a fast, terminal-based log analyzer. Its core idea is to quickly analyze and view web server statistics in real time without needing to use your browser (great if you want to do a quick analysis of your access log via SSH, or if you simply love working in the terminal).

While the terminal output is the default output, it has the capability to generate a complete, self-contained real-time HTML report (great for analytics, monitoring and data visualization), as well as a JSON, and CSV report.

INSTALLATION

Installing GoAccess is pretty easy. Just download, extract and compile it

We will illustrate how to install it on most common different linux distributions.

Install GoAccess on RHEL/CentOS 8

Method 1:

Build from goaccess site

Follow these steps and run commands below to get start with the installation.

First, you should install epel repo and update the system packages.

dnf -y install epel-release
dnf -y update
shutdown -r now

GoAccess is written in the C programming language. Hence, the only required dependency is the ncurses library and gcc. To install the ncurses and gcc, run:

dnf -y install ncurses-devel gcc

Install the optional packages by running:

dnf -y install geoip-devel tokyocabinet-devel

You also may need to install build tools like autoconf and gettext

dnf install -y autoconf gettext 

Download goaccess tarball with:

[root@unixcop ~]# wget https://tar.goaccess.io/goaccess-1.5.1.tar.gz
--2021-09-14 09:43:47--  https://tar.goaccess.io/goaccess-1.5.1.tar.gz
Resolving tar.goaccess.io (tar.goaccess.io)... 67.205.130.138
Connecting to tar.goaccess.io (tar.goaccess.io)|67.205.130.138|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 642860 (628K) [application/x-gzip]
Saving to: 'goaccess-1.5.1.tar.gz'

goaccess-1.5.1.tar.gz                 100%[=======================================================================>] 627.79K   395KB/s    in 1.6s    

2021-09-14 09:43:51 (395 KB/s) - 'goaccess-1.5.1.tar.gz' saved [642860/642860]

[root@unixcop ~]# 

Then extract and compile it with below commands:

[root@unixcop ]# tar -xzvf goaccess-1.5.1.tar.gz
[root@unixcop ]# cd goaccess-1.5.1/
[root@unixcop goaccess-1.5.1]# ./configure --enable-utf8 
[root@unixcop goaccess-1.5.1]# make
[root@unixcop goaccess-1.5.1]# make install

Method 2:

Build from GitHub (Development)

Just run below commands to start the installation from GitHub:

$ git clone https://github.com/allinurl/goaccess.git
$ cd goaccess
$ autoreconf -fi
$ ./configure --enable-utf8 --enable-geoip=mmdb
$ make
$ make install
				

Install GoAccess on the other Distributions

Fedora

# yum install goaccess		

Arch Linux

# pacman -S goaccess		

Gentoo

# emerge net-analyzer/goaccess

OS X / Homebrew

# brew install goaccess	

FreeBSD

# pkg install sysutils/goaccess		

OpenBSD

# pkg_add goaccess	

OpenSUSE

# zypper ar -f obs://server:http http
# zypper in goaccess

pkgsrc (NetBSD, Solaris, SmartOS)

# pkgin install goaccess	

Slackware

# curl https://slackbuilds.org/slackbuilds/14.1/system/goaccess.tar.gz | tar xvz
# cd goaccess/
# GEOIP=yes ./goaccess.SlackBuild

How to use GoAccess from Terminal

Choose the log file based on your operating system and web server used. On Debian based systems log are generated under /var/log/apache2 directory and Redhat based system Apache create logs under /var/log/httpd directory. Use -f option to define the log file with goaccess command.

goaccess -f /var/log/httpd/access_log

Then select the log format.

NOTE: Default Apache log format is COMBINED.

The GoAccess also allows you to define the log format with using –log-format command options. For example, to use COMBINED log format the command will be:

goaccess /var/log/httpd/access_log --log-format=COMBINED

You will see the output on system console like below:

You may noticed that there is no any requests in the logs

Let’s do some requests.

The output of goaccess on the system console should be changed like that:

If you scroll down you will notice information about Operating systems and Browsers that request the webpage as shown below.

You can press ‘q’ to exit out of the GoAccess terminal viewer.

View GoAccess Output in Web Dashboard

GoAccess allows users to generate reports in various formats like HTML, JSON and CSV. We can generate the report by using the following command in to a html file.

[root@unixcop ~]# goaccess /var/log/httpd/access_log --log-format=COMBINED -a -o /var/www/html/report.html
 [PARSING /var/log/httpd/access_log] {0} @ {0/s}
[root@unixcop ~]#
  • -a – Enable a list of user-agents by host
  • -o – Used to define output file
  • Output format is automatically selected based on output filename extension

Next, access report.html using server ip address or domain name as shown below:

Use crond Service To Update Web Dashboard File

You can schedule goaccess command to update html report .

Just create a shell script

vim /mnt/goaccess.sh

Then add the following :

!/bin/bash
goaccess /var/log/httpd/access_log --log-format=COMBINED -a -o /var/www/html/report.html

Then schedule the above script with crontab:

crontab -e

Add the following content to end of file

#Cron job to update Goaccess HTML repot
* * * * * /mnt/goaccess.sh

Conclusion

In this guide, you explained how to install and use GoAccess to view web server logs in visual formats.

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest articles

x