對於日誌系統來講,常見的需求就是收集、存儲、查詢、展現,而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聯動便可。