Elastic Stack 是原 ELK Stack 在 5.0 版本加入 Beats 套件後的新稱呼,ELK 套件成了開源日誌處理領域的第一選擇;java
從Elasticsearch 5.0版本開始,Elastic公司全線產品升級到5.0版本。並且由於Beats的加入,再也不使用ELK簡稱。
23 Oct 2016 是 5.0GA發佈的日子,因此本次release,也標誌着ELK的結束。之後的更新,將基於Elastic Stack 5.0繼續;node
-- chenrynbootstrap
按照官方 https://www.elastic.co 介紹:vim
Visualize your data. Navigate the Elastic Stack. ------- Kibana瀏覽器
Search, analyze, and store your data. ------- Elasticsearchtomcat
Ingest any data, from any source, in any format ------- Beats 和 Logstashruby
ELasticsearch:5.2.2bash
Logstash:5.2.2服務器
Kibana:5.2.2jvm
jdk:1.8.0_77
官網下載程序包
$ tar xvf elasticsearch-5.2.2.zip $ cd elasticsearch-5.2.2 # elasticsearch 默認是不能用 root 啓動的,須要使用別的用戶啓動 $ su userother
目前仍有許多插件不支持 5.x 版本,好比 mobz/elasticsearch-head 就不支持 5.x,有關插件參考官方文檔
修改配置文件。建立 /tmp/elasticsearch/data /tmp/elasticsearch/logs 文件夾:
# 添加以下配置 cluster.name: es_cluster node.name: node0 path.data: /tmp/elasticsearch/data path.logs: /tmp/elasticsearch/logs network.host: 0.0.0.0 # network.port: 9200 默認
./bin/elasticsearch 啓動報錯:
... Exception in thread "main" java.lang.RuntimeException: bootstrap checks failed initial heap size [268435456] not equal to maximum heap size [2147483648]; this can cause resize pauses and prevents mlockall from locking the entire heap max file descriptors [4096] for elasticsearch process likely too low, increase to at least [65536] please set [discovery.zen.minimum_master_nodes] to a majority of the number of master eligible nodes in your cluster max virtual memory areas vm.max_map_count [65530] likely too low, increase to at least [262144] ... # fix 一、提升 vm.max_map_count $ su root $ sysctl -w vm.max_map_count=262144 $ sysctl -a | grep vm.max_map_count vm.max_map_count = 262144 # 永久修改,須要修改 /etc/sysctl.conf 文件裏面 vm.max_map_count=262144 $ sysctl -p # 生效 二、修改 jvm 內存 $ vim elasticsearch/config/jvm.options 將 -Xms2g -Xmx2g 改成 -Xms256m -Xmx256m 值爲 [268435456] / 1024 / 1024 三、修改系統 limit $ su root $ vim /etc/security/limits.conf 添加(userother 爲啓動 elasticsearch 的用戶) userother hard nofile 65536 userother soft nofile 65536
./bin/elasticsearch 啓動程序,訪問 http://IP:9200
Logstash 其實就是一個收集器,能夠指定 Input 和 Output( Input 和 Output 能夠爲多個)
Logstash 能夠獲取服務器上的日誌,編寫 Logstash 配置文件便可;
# Remember: if a new user has a bad time, it's a bug in logstash
從官網下載二進制包,推薦使用軟件倉庫完成批量安裝(將二進制包打包成 rpm 包,放入自搭建的 yum 庫中,用於服務器批量安裝,避免出現版本而致使的錯誤)
Logstash 是須要 java 環境支持的,從 orecle 下載 java jdk,添加至環境變量 /etc/profile
JAVA_HOME=/usr/lib/jdk1.8.0_77 JAVA_BIN=$JAVA_HOME/bin PATH=$JAVA_BIN:$PATH:. export JAVA_HOME JAVA_BIN PATH
簡單的 Hello World:
$ bin/logstash -e 'input{stdin{}}output{stdout{codec=>rubydebug}}' { "message" => "Hello World", "@version" => "1", "@timestamp" => "2017-03-10T10:30:59.937Z", "host" => "pcdeMacBook-Pro.local", }
Logstash 配置文件中用 {} 來定義區域,區域內能夠包括插件區域的定義,插件區域內則能夠定義鍵值對設置,詳細語法能夠參考官方文檔。
編輯配置文件:
$ cat ./config/tomcat_to_es.conf # 從指定位置讀取日誌,並輸出到 elasticsearch 服務器中 input { file { path => "/usr/tomcat/tomcat-10005/logs/*" exclude => "s10005.log*" start_position => beginning } } filter { } output { elasticsearch { hosts => ["http://10.12.41.127:9200"] index => "tomcats10005" } } # 啓動 Logstash $ ./bin/logstash -f ./config/tomcat_to_es.conf
Logstash 還支持從 syslog 中獲取日誌,從 java log4j 獲取等方式。
filter 區域則能夠配置須要獲取日誌的規則,很強大;
Kibana 安裝僅需從官網下載 Kibana 二進制包,解壓縮便可運行;
修改配置文件,告訴 Kibana 須要搜索哪一個 Elasticsearch 索引
$ cat ./config/kibana.yml # 添加配置 server.port: 5601 server.host: 10.12.41.127 elasticsearch.url: http://localhost:9200 kibana.index: ".kibana" # 啓動 Kibana $ ./bin/kibana
打開瀏覽器,訪問 http://10.12.41.127:5601,配置至少一個 Index 名字或者 Pattern,用於在分析時肯定 ES 中的 Index,輸入以前在 Logstash 中配置的 Index 名字,Kibana 會自動加載該 Index 下的 doc 的 field,並自動選擇合適的 field 用於圖標中的時間字段;
至此,簡單的 ELK 日誌平臺部署基本完成了;