I haven’t installed an ELK stack since CentOS 7 came out, all of the components which go to make up the stack have been updated quite bit since then so I decided to have a go at installing the stack on a clean CentOS 7 installation.

ELK?

ELK is a term used for a combination of three Open Source products from Elastic↗ ;

  • Elasticsearchβ†— β€Šβ€”β€ŠSearch & Analyze Data in Real Time
  • Logstashβ†— β€Šβ€”β€ŠCollect, Parse, & Enrich Data
  • Kibanaβ†— β€Šβ€”β€ŠExplore & Visualize Your Data

All three products can be used independently, but when they are used together you find yourself with both a powerful and scaleable central logging service.

There is a good introduction to the stack on YouTube;

Elasticsearch

The only pre-requisite for Elasticsearch is a recent version of Java, the quickest way to install this is directly from Oracle;

Installing an ELK Stack on CentOS 7 1/11
cwtcrdgahmerotwoxnopβ€”vptf-tnR/ojj-rrrceoeo-o-o8t8k*:*i..etjtsararerβ€”.1.g.gnz8zo*-check-certificateβ€”headerβ€œCookie:gpw_e24=http%3A%2F%2Fwww.oracle.com%2F;oraclelicense=accept-securebackup-cookieβ€β€œhttp://download.oracle.com/otn-pub/java/jdk/8u40-b25/jre-8u40-linux-x64.tar.gz"

Now we have a java Runtime installed in /opt/jre1.8* lets use alternatives to set it so the system uses it by default;

Installing an ELK Stack on CentOS 7 2/11
ajjJJlaaaatvvvveaaaar(nvTHaveMoter)tirsSvsiSpeioEosontnR(β€”β€œuT1nMi.t)n8is.m6t0e4a_-l4EBl0ni”vt/iurSsoernr/mvbeeinrnt/Vj(Mabvu(aiblujdialv1da.82.5o0.p_4t40/0-j-brb2e2515,.)8m*i/xbeidn/mjoadvea)1

So thats Java installed and set as the system default, next up is Elasticsearch itself. There is an official Yum repository so lets use it;

Installing an ELK Stack on CentOS 7 3/11
cat/etc/yum.repos.d/elasticsearch.repo/etc/systemd/system/kibana4.service/etc/nginx/conf.d/kibana.conf

and finally start the services;

Installing an ELK Stack on CentOS 7 4/11
ssyysstteemmccttllsetnaarbtlengnignixnx

Logstash

Like Elasticsearch there is a Yum repository;

Installing an ELK Stack on CentOS 7 5/11
catss}}ItyssNpllPe__UckT=ee/>ryettβ€œi=clf>/oiygcβ€œusa/m”te.etrce=/p>poksβ€œi.//det/tllcso//gppskrtiia/vstahlt.ser//eclpeoorgtsst/als/oheg-tsfcto/arlswohag-rsfdtoearrsw.hak/recdyoe”nrf..cdr/t0”1-lumberjack-input.conf<5000

As we will be shipping syslog data to our ELK stack we need to let Logstash how it will look;

Installing an ELK Stack on CentOS 7 6/11
caa}sdm}}}SaddyaaYtddsttS__lecLffohOiig{Gee_=/llp>eddrti[c==/>>{β€œlso[[}ygssβ€œβ€œltrroaeegscc_heet/iiicvvmoeeenddsf__t.afadtrm/”op1,m”0”,-β€œ,s%β€œy{β€œMs@%Mlt{Moihgmod.escstHot}Hna”:fmmp]m<}:”s{s]β€β€œ,meβ€œsMsMaMged”d=H>H:β€œm%m{:SsYsS”LO]GTIMESTAMP:syslog_timestamp}%{SYSLOGHOST:syslog_hostname}%{DATA:syslog_program}(?:\[%{POSINT:syslog_pid}\])?:%{GREEDYDATA:syslog_message}”}

Finally lets send the data to the Elasticsearch installation on localhost;

Installing an ELK Stack on CentOS 7 7/11
cs}OatUtdToPuUtT{/ectocd/elcog=s>tarsuhb/ycdoenbfu.gd/}30-lumberjack-output.conf<localhost}

So thats Logstash configured, lets start the service;

Installing an ELK Stack on CentOS 7 8/11
scehrkvciocnefilgoglsotgassthasrhesotnart

and thats the main stack installed and configured. You should be able to visit the FQDN you specified in the NGINX configuration and see the Kibana dashboard.

Logstash Forwarder

Now we have our main stack installed, let pump some data into it.

This is all run on the server instances you would to report into your newly configured ELK stack.

First of all, lets import the GPG key for the Forwarder repo;

Installing an ELK Stack on CentOS 7 9/11
rpmβ€”importhttp://packages.elasticsearch.org/GPG-KEY-elasticsearch

Now add the repo;

Installing an ELK Stack on CentOS 7 10/11
Tc{Tβ€œβ€œβ€œβ€œ}hβ€œ{β€œβ€œβ€œβ€œ]β€œ}]}Fahnsts,efp///,fOteeeisiaviRtrmllltaaaeWnwveiehrrrlAeoeocsss///dRtrruat””lllsD/wkst”::ooo”eo”””:oggg:tr:::f[[///ckβ€œmsf{/{[1/feeays5eisciβ€œueβ€œ,tlsultmcecear2y.tl/sgebprikpe”aeeo.kcs,n”pnmio”.:oc/n,lscktfoβ€œ.oeligsdvnsg”y/ed/uslrrcrlosieaogcrtgsnkti”te.soati/n}swolsho:o-r5gfk0so0trc0awo”sanhrf]-di,fegorur.rwraaetrpidooenr.:c)r/te”tc/logstash-forwarder.confFORWARD

as you can see I am shipping /var/log/messages, /var/log/secure and /var/log/fail2ban.log over to my ELK stack.

Finally we need to start the service and configure to start on boot;

Installing an ELK Stack on CentOS 7 11/11
scehrkvciocnefilgoglsotgasstha-sfho-rfwoarrwdaerrderresotnart

and hey presto, we now have data appearing in Kibana;

discover-kibana-4