Voici la documentation d'installation d'un triplet Elk/Rsyslog/Logstash afin d'indexer des logs pour des requêtes plus efficaces.
Installation de Logstash et Elasticsearch
wget -qO - https://packages.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add -
echo "deb http://artifacts.elastic.co/packages/5.x/apt stable main" > /etc/apt/sources.list.d/elk.list
apt update
apt install elasticsearch logstash
Ajoutez les lignes suivantes au fichier /etc/logstash/conf.d/logstash.conf
# This input block will listen on port 10514 for logs to come in.
# host should be an IP on the Logstash server.
# codec => "json" indicates that we expect the lines we're receiving to be in JSON format
# type => "rsyslog" is an optional identifier to help identify messaging streams in the pipeline.
input {
udp {
host => "127.0.0.1"
port => 10514
codec => "json"
type => "rsyslog"
}
}
# This is an empty filter block. You can later add other filters here to further process
# your log lines
filter { }
# This output block will send all events of type "rsyslog" to Elasticsearch at the configured
# host and port into daily indices of the pattern, "rsyslog-YYYY.MM.DD"
output {
if [type] == "rsyslog" {
elasticsearch {
hosts => [ "127.0.0.1:9200" ]
}
}
}
Maintenant nous allons configurer rsyslog pour envoyer a logstash :
Créer un fichier /etc/rsyslogd/01-json-template contenant :
template(name="json-template"
type="list") {
constant(value="{")
constant(value="\"@timestamp\":\"") property(name="timereported" dateFormat="rfc3339")
constant(value="\",\"@version\":\"1")
constant(value="\",\"message\":\"") property(name="msg" format="json")
constant(value="\",\"sysloghost\":\"") property(name="hostname")
constant(value="\",\"severity\":\"") property(name="syslogseverity-text")
constant(value="\",\"facility\":\"") property(name="syslogfacility-text")
constant(value="\",\"programname\":\"") property(name="programname")
constant(value="\",\"procid\":\"") property(name="procid")
constant(value="\"}\n")
}
Puis indiquer a rsyslog qu'il faut envoyer en utilisant le template json a logstash :
Editer /etc/rsyslog.d/50-default et ajoutez la ligne :
*.* @127.0.0.1:10514;json-template
Lancer/Relancer les services :
service elasticsearch start
service logstash start
service rsyslog restart
Maintenant, Kibana !
apt install kibana
service kibana start
Consulter les liens :
Liste des indexes d'ElasticSearch
http://localhost:9200/_cat/indices?v
Kibana
http://localhost:5601/
Bien sur, si vous hébergez votre Elk + Kibana sur une autre machine, il faut changer l'ip dans /etc/rsyslog.d/50-default et localhost dans les urls de consultation et d'interrogation.
Nous avons aussi la possibilité d'avoir un rsyslog local à la machine qui héberge logstash, Elk, et kibana, ou que chaque machine envoie ses logs directement à logstash, ou encore que logstash soit local a chaque machine et envoie a un Elk distant. Multiples combinaisons selon vos besoins architecturaux.