对于日志系统来讲,常见的需求就是收集、存储、查询、展现,而ELKStack就是这样一个日志系统。 ELKStack是Elasticsearch、Logstash、Kibana技术栈的结合,它的通用架构以下图所示:
安装Elasticsearch和LogStash须要Java环境,因此须要提早安装好JDK,能够直接使用yum安装。也能够从Oracle官网下载JDK进行安装。开始以前要确保JDK正常安装而且环境变量也配置正确:java
[root@linux-node1 ~]# yum install -y java [root@linux-node1 ~]# java -version openjdk version "1.8.0_65" OpenJDK Runtime Environment (build 1.8.0_65-b17) OpenJDK 64-Bit Server VM (build 25.65-b01, mixed mode)
rpm --import https://packages.elastic.co/GPG-KEY-elasticsearch
cat >/etc/yum.repos.d/elasticsearch.repo<<EOF [elasticsearch-2.x] name=Elasticsearch repository for 2.x packages baseurl=http://packages.elastic.co/elasticsearch/2.x/centos gpgcheck=1 gpgkey=http://packages.elastic.co/GPG-KEY-elasticsearch enabled=1 EOF cat >/etc/yum.repos.d/logstash.repo<<EOF [logstash-2.3] name=Logstash repository for 2.3.x packages baseurl=https://packages.elastic.co/logstash/2.3/centos gpgcheck=1 gpgkey=https://packages.elastic.co/GPG-KEY-elasticsearch enabled=1 EOF cat >/etc/yum.repos.d/kibana.repo<<EOF [kibana-4.5] name=Kibana repository for 4.5.x packages baseurl=http://packages.elastic.co/kibana/4.5/centos gpgcheck=1 gpgkey=http://packages.elastic.co/GPG-KEY-elasticsearch enabled=1 EOF
yum install -y elasticsearch logstash kibana
/usr/share/elasticsearch/bin/plugin install mobz/elasticsearch-head /usr/share/elasticsearch/bin/plugin install lmenezes/elasticsearch-kopf [root@linux-node1 plugins]# pwd /usr/share/elasticsearch/plugins [root@linux-node1 plugins]# ls head kopf
/etc/init.d/elasticsearch start /etc/init.d/kibana start
http://IP:9200/_plugin/head http://IP:9200/_plugin/kopf http://IP:5601
Logstash用于收集/发送日志,收集/发送日志的配置文件放置在 /etc/logstash/conf.d/ 下。 Elasticsearch用于存储和查询logstash收集的日志,服务端口为tcp:9200, elasticsearch的插件放置在 /usr/share/elasticsearch/bin/plugin 下。 Kibana用于在web界面展现elasticsearch存储和查询的日志信息,服务端口为tcp:5601, 只需修改配置文件/opt/kibana/config/kibana.yml,使其与elasticsearch联动便可。