How to install GoAccess in CentOS 7

To install GoAccess in CentOS 7

GoAccess is an open source interactive web server log analyzer which means it helps you to quickly view and analyze traffic metrics in real time. You can perform this action by making use of a command line dashboard in Unix/Linux operating systems. It runs entirely in a terminal with statistics organized into separate panels on one dashboard which is scrollable. It generates a brief and beneficial HTTP (web server) statistics report for Linux administrators in a jiff. It can also be used to generate web traffic reports of HTML, JSON, and CSV. It is so simple to install GoAccess and this tutorial demonstrates the method to install GoAccess.

Installing GoAccess

In order to install GoAccess, you are required to install all the necessary development tools. Run the following command for the same purpose.

[root@localhost ~]# yum groupinstall " Development Tools" 
Loaded plugins: fastestmirror, langpacks
There is no installed groups file.
Resolving Dependencies
-->  Running transaction check
--->  Package autoconf.noarch 0:2.69-11.el7 will be installed
-->  Processing Dependency: m4 > = 1.4.14 for package: autoconf-2.69-11.el7.noarch
-->  Processing Dependency: perl(Data::Dumper) for package: autoconf-2.69-11.el7.noarch
--->  Package automake.noarch 0:1.13.4-3.el7 will be installed
-->  Processing Dependency: perl(Thread::Queue) for package: automake-1.13.4-3.el7.noarch
-->  Processing Dependency: perl(TAP::Parser) for package: automake-1.13.4-3.el7.noarch
--->  Package bison.x86_64 0:3.0.4-1.el7 will be installed
.
.
.
Dependency Updated:
boost-system.x86_64 0:1.53.0-27.el7 dyninst.x86_64 0:9.3.1-1.el7
gettext.x86_64 0:0.19.8.1-2.el7 gettext-libs.x86_64 0:0.19.8.1-2.el7
glibc.x86_64 0:2.17-196.el7 glibc-common.x86_64 0:2.17-196.el7
libgcc.x86_64 0:4.8.5-16.el7 libgomp.x86_64 0:4.8.5-16.el7
libstdc++.x86_64 0:4.8.5-16.el7 rpm.x86_64 0:4.11.3-25.el7
rpm-build-libs.x86_64 0:4.11.3-25.el7 rpm-libs.x86_64 0:4.11.3-25.el7
rpm-python.x86_64 0:4.11.3-25.el7 systemtap-runtime.x86_64 0:3.1-3.el7

Complete!

When it is done, you should install ncurses and geoip library packages as follows.

[root@localhost ~]# yum install ncurses-devel GeoIP-devel GeoIP-data
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: centos.mirror.snu.edu.in
* extras: centos.mirror.snu.edu.in
* updates: centos.mirror.snu.edu.in
Resolving Dependencies
-->  Running transaction check
--->  Package GeoIP-data.noarch 0:1.5.0-11.el7 will be installed
-->  Processing Dependency: GeoIP = 1.5.0-11.el7 for package: GeoIP-data-1.5.0-11.el7.noarch
--->  Package GeoIP-devel.x86_64 0:1.5.0-11.el7 will be installed
--->  Package ncurses-devel.x86_64 0:5.9-14.20130511.el7_4 will be installed
-->  Processing Dependency: ncurses-libs(x86-64) = 5.9-14.20130511.el7_4 for package: ncurses-devel-5.9-14.20130511.el7_4.x86_64
-->  Running transaction check
--->  Package GeoIP.x86_64 0:1.5.0-11.el7 will be installed
.
.
.
Installed:
GeoIP-data.noarch 0:1.5.0-11.el7 GeoIP-devel.x86_64 0:1.5.0-11.el7
ncurses-devel.x86_64 0:5.9-14.20130511.el7_4

dependency Installed:
GeoIP.x86_64 0:1.5.0-11.el7


Dependency Updated:

ncurses.x86_64 0:5.9-14.20130511.el7_4 ncurses-base.noarch 0:5.9-14.20130511.el7_4

ncurses-libs.x86_64 0:5.9-14.20130511.el7_4


Complete!

Once it is done, you shall download goaccess by running the following command. You can execute this action by running the following command.

[root@localhost opt]# wget http://tar.goaccess.io/goaccess-1.2.tar.gz
--2017-11-22 17:40:06-- http://tar.goaccess.io/goaccess-1.2.tar.gz
Resolving tar.goaccess.io (tar.goaccess.io)... 107.170.196.4
Connecting to tar.goaccess.io (tar.goaccess.io)|107.170.196.4|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 423103 (413K) [application/x-gzip]
Saving to: ‘ goaccess-1.2.tar.gz’ 

100%[=========================================================> ] 4,23,103 --.-K/s in 0.03s

2017-11-22 17:40:09 (11.5 MB/s) - ‘ goaccess-1.2.tar.gz’  saved [423103/423103]

And then, you should extract downloaded tar file. Later you should enter into the extracted directory as follows.

[root@localhost opt]# tar -zxf goaccess-1.2.tar.gz
[root@localhost opt]# cd goaccess-1.2/

Once it is done, you should run “ ./configure” for preparing for the installation.

[root@localhost goaccess-1.2]# ./configure --enable-utf8 --enable-geoip=legacy
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /usr/bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
.
.
.
config.status: creating src/config.h
config.status: executing depfiles commands

Your build configuration:

Prefix : /usr/local
Package : goaccess
Version : 1.2
Dynamic buffer : no
Geolocation : GeoIP Legacy
Storage method : In-memory Hash Database (Default)
TLS/SSL : no
Compiler flags : -pthread
Linker flags : -lnsl -lncursesw -lGeoIP -lpthread
Bugs : goaccess@prosoftcorp.com

You shall now run the make command which is essential for the installation.

[root@localhost goaccess-1.2]# make
depbase=`echo src/bin2c.o | sed ' s|[^/]*$|.deps/& | s|.o$||' ` 
gcc -DHAVE_CONFIG_H -I. -I./src -O2 -DSYSCONFDIR=" /usr/local/etc"  -Wno-long-long -Wall -W -Wnested-externs -Wformat=2 -Wmissing-prototypes -Wstrict-prototypes -Wmissing-declarations -Wwrite-strings -Wshadow -Wpointer-arith -Wsign-compare -Wbad-function-cast -Winline -Wcast-align -Wextra -Wdeclaration-after-statement -Wno-missing-field-initializers -pthread -MT src/bin2c.o -MD -MP -MF $depbase.Tpo -c -o src/bin2c.o src/bin2c.c & & 
mv -f $depbase.Tpo $depbase.Po
gcc -O2 -DSYSCONFDIR=" /usr/local/etc"  -Wno-long-long -Wall -W -Wnested-externs -Wformat=2 -Wmissing-prototypes -Wstrict-prototypes -Wmissing-declarations -Wwrite-strings -Wshadow -Wpointer-arith -Wsign-compare -Wbad-function-cast -Winline -Wcast-align -Wextra -Wdeclaration-after-statement -Wno-missing-field-initializers -pthread -rdynamic -o bin2c src/bin2c.o -lnsl -lncursesw -lGeoIP -lpthread
./bin2c resources/tpls.html src/tpls.h tpls
./bin2c resources/css/bootstrap.min.css src/bootstrapcss.h bootstrap_css
.
.
.
gcc -O2 -DSYSCONFDIR=" /usr/local/etc"  -Wno-long-long -Wall -W -Wnested-externs -Wformat=2 -Wmissing-prototypes -Wstrict-prototypes -Wmissing-declarations -Wwrite-strings -Wshadow -Wpointer-arith -Wsign-compare -Wbad-function-cast -Winline -Wcast-align -Wextra -Wdeclaration-after-statement -Wno-missing-field-initializers -pthread -rdynamic -o goaccess src/base64.o src/browsers.o src/color.o src/commons.o src/csv.o src/error.o src/gdashboard.o src/gdns.o src/gholder.o src/gmenu.o src/goaccess.o src/gslist.o src/gstorage.o src/gwsocket.o src/json.o src/opesys.o src/options.o src/output.o src/parser.o src/settings.o src/sha1.o src/sort.o src/ui.o src/util.o src/websocket.o src/xmalloc.o src/gkhash.o src/geoip.o -lnsl -lncursesw -lGeoIP -lpthread
make[1]: Leaving directory `/opt/goaccess-1.2' 

Once it is done, follow it up by running the make install command for preparing the stage for installation of GoAccess.

[root@localhost goaccess-1.2]# make install
./bin2c resources/tpls.html src/tpls.h tpls
./bin2c resources/css/bootstrap.min.css src/bootstrapcss.h bootstrap_css
./bin2c resources/css/fa.min.css src/facss.h fa_css
./bin2c resources/css/app.css src/appcss.h app_css
./bin2c resources/js/d3.v3.min.js src/d3js.h d3_js
./bin2c resources/js/hogan.min.js src/hoganjs.h hogan_js
./bin2c resources/js/charts.js src/chartsjs.h charts_js
./bin2c resources/js/app.js src/appjs.h app_js
make install-am
.
.
.
/usr/bin/mkdir -p ' /usr/local/share/doc/goaccess' 
/usr/bin/install -c -m 644 resources/tpls.html resources/css/app.css resources/css/bootstrap.min.css resources/css/fa.min.css resources/js/app.js resources/js/charts.js resources/js/d3.v3.min.js resources/js/hogan.min.js ' /usr/local/share/doc/goaccess' 
/usr/bin/mkdir -p ' /usr/local/share/man/man1' 
/usr/bin/install -c -m 644 goaccess.1 ' /usr/local/share/man/man1' 
make[2]: Leaving directory `/opt/goaccess-1.2' 
make[1]: Leaving directory `/opt/goaccess-1.2' 

And also install the httpd as follows.

[root@localhost goaccess-1.2]# yum install httpd
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: centos.mirror.snu.edu.in
* extras: centos.mirror.snu.edu.in
* updates: centos.mirror.snu.edu.in
Resolving Dependencies
-->  Running transaction check
--->  Package httpd.x86_64 0:2.4.6-67.el7.centos.6 will be installed
-->  Processing Dependency: httpd-tools = 2.4.6-67.el7.centos.6 for package: httpd-2.4.6-67.el7.centos.6.x86_64
.
.
.
Verifying : httpd-2.4.6-67.el7.centos.6.x86_64 2/3
Verifying : httpd-tools-2.4.6-67.el7.centos.6.x86_64 3/3

Installed:
httpd.x86_64 0:2.4.6-67.el7.centos.6

Dependency Installed:
httpd-tools.x86_64 0:2.4.6-67.el7.centos.6 mailcap.noarch 0:2.1.41-2.el7

Complete!

Once httpd is installed, you shall start the httpd service.

[root@localhost goaccess-1.2]# systemctl start httpd

Next create analysed html file for httpd access log, by using goaccess command.

[root@localhost goaccess-1.2]# goaccess /var/log/httpd/access_log --log-format=COMBINED -a -o /var/www/html/report.html
/var/log/httpd/access_log
[root@localhost goaccess-1.2]#

Once it is done, you shall now go to your browser and type your ip address with html file name http://192.168.7.203/report.html

FAQ
Q
Where is the configuration file located?
A
The configuration file is located under ~/.goaccessrc or %sysconfdir%/goaccess.conf where %sysconfdir% is either /etc/, /usr/etc/ or /usr/local/etc/. You can find the default configuration file here.
Q
How fast is GoAccess when parsing a log file?
A
Keep in mind that many factors can influence the parsing time, including processor, ram, log, etc. however, generally we could derive the following table
Q
What's the memory footprint of GoAccess?
A
GoAccess should not leak any memory, (tested with Valgrind), so mostly it will depend on the log size and features enabled. For a 3,397,814 parsed lines is ~134.1 MiB (full features enabled).
Q
How can I configure the log/date/time format for Apache or Nginx?
A
There are several ways to set the log format. If you are outputting to a terminal (ncurses), the easiest is to run GoAccess with -c.

# goaccess access.log -c
You could also specify the log format in the command line, so for the standard Apache/Nginx format, you could run:

# goaccess access.log --log-format=COMBINED
Q
What are the alternative for this tool?
A
You can try Matomo, AWStats, The Webalizer