ELK簡單安裝

ELK日誌分析平臺node

1、ELK介紹

ELK是三個開源軟件的縮寫,分別爲:Elasticsearch 、 Logstash以及Kibana,都是開源軟件,新增一個beats,(輕量級日誌處理工具Agent)linux

 

Elasticsearch是開源分佈式搜索引擎,提供搜索、分析、存儲數據三大功能,它的特色有:分佈式,零配置,自動發現,索引自動分片,索引副本機制,restful風格接口,多數據源,自動搜索負載等bootstrap

Logstash 主要是用來日誌的蒐集、分析、過濾日誌的工具,支持大量的數據獲取方式。通常工做方式爲c/s架構,client端安裝在須要收集日誌的主機上,server端負責將收到的各節點日誌進行過濾、修改等操做在一併發往elasticsearch上去。vim

Kibana 也是一個開源和免費的工具,Kibana能夠爲 Logstash 和 ElasticSearch 提供的日誌分析友好的 Web 界面,能夠幫助彙總、分析和搜索重要數據日誌。centos

Beats在這裏是一個輕量級日誌採集器,其實Beats家族有6個成員,早期的ELK架構中使用Logstash收集、解析日誌,可是Logstash對內存、cpu、io等資源消耗比較高。相比 Logstash,Beats所佔系統的CPU和內存幾乎能夠忽略不計。數組

2、elasticsearch搭建

環境介紹:瀏覽器

centos 6.8ruby

JDK 1.8restful

 

1.下載ELK的三大組件

Elasticsearc下載地址: https://www.elastic.co/downloads/elasticsearch架構

 

Logstash下載地址: https://www.elastic.co/downloads/logstash

 

Kibana下載地址: https://www.elastic.co/downloads/kibana

 

2.建立運行elk用戶

groupadd elk

useradd -g elk elk

建立運行目錄:

mkdir elk

chown -R elk:elk /elk

◆關閉防火牆

3.修改配置參數

配置limit相關參數:

vim /etc/security/limits.conf

添加如下內容

* soft nproc 65536

* hard nproc 65536

* soft nofile 65536

* hard nofile 65536

以上均是由root用戶完成

4.安裝ELK

由elk用戶來操做

tar -xvf elasticsearch-6.5.2.tar.gz

vi config/elasticsearch.yml

修改如下內容

cluster.name: my-application

node.name: node-1

 bootstrap.system_call_filter: false(手動添加)

network.host: 192.168.19.95

http.port: 9200

保存退出

5.啓動elasticsearch

啓動Elasticsearch

./bin/elasticsearch

nohup ./elasticsearch &  ##後臺啓動

查看是否啓動:

netstat -an |grep 9200

6.啓動驗證

在瀏覽器中輸入http://192.168.19.95:9200/

{

  "name" : "node-1",

  "cluster_name" : "my-application",

  "cluster_uuid" : "O-cNGXEsScSns8Catgq4wg",

  "version" : {

    "number" : "6.5.2",

    "build_flavor" : "default",

    "build_type" : "tar",

    "build_hash" : "9434bed",

    "build_date" : "2018-11-29T23:58:20.891072Z",

    "build_snapshot" : false,

    "lucene_version" : "7.5.0",

    "minimum_wire_compatibility_version" : "5.6.0",

    "minimum_index_compatibility_version" : "5.0.0"

  },

  "tagline" : "You Know, for Search"

}

7.啓動報錯處理

◆max number of threads [1024] for user [lish] likely too low, increase to at least [2048]

解決:切換到root用戶,進入limits.d目錄下修改配置文件。

vi /etc/security/limits.d/90-nproc.conf

修改以下內容:

* soft nproc 1024

#修改成

* soft nproc 2048

 

◆max virtual memory areas vm.max_map_count [65530] likely too low, increase to at least [262144]

解決:切換到root用戶修改配置sysctl.conf

vi /etc/sysctl.conf

添加下面配置:

vm.max_map_count=655360

並執行命令:

sysctl -p

 

◆max file descriptors [4096] for elasticsearch process likely too low, increase to at least [65536]

解決:修改切換到root用戶修改配置limits.conf 添加下面兩行

命令:vi /etc/security/limits.conf

*        hard    nofile           65536

*        soft    nofile           65536

3、logstash搭建

一、解壓文件

tar -xvf logstash-6.5.2.tar.gz

 

二、新建索引配置文件

cd /elk/logstash-6.5.2/bin

mkdir conf

vi conf/logstash-indexer.conf

內容以下:

input {

 file {

   path=>["/elk/logstash-6.5.2/logs/a.log","/elk/logstash-6.5.2/logs/b.log"]

 }

}

 

output {

  elasticsearch { hosts => ["192.168.19.95:9200"] }

  stdout { codec => rubydebug }

}

◆◆◆◆◆

input{file{...}}部分指定的是日誌文件的位置(能夠多個文件)

output部分則是表示將日誌文件的內容保存到elasticsearch,這裏hosts對應的是一個數組,能夠設置多個elasticsearch主機,至關於一份日誌文件的內容,能夠保存到多個elasticsearch中

三、啓動

在logstash /bin 目錄下

./logstash -f conf/logstash-indexer.conf

等待片刻,打開另外一個窗口,向/elk/logstash-6.5.2/logs/a.log 中寫入  hello world 保存退出,而後觀察logstash的運行窗口,是否有東西輸出

{

       "message" => "hello world",

      "@version" => "1",

    "@timestamp" => "2016-01-08T14:35:16.834Z",

          "host" => "yangjunmingdeMacBook-Pro.local",

          "path" => "/var/opt/log/a.log"

}

 

此時瀏覽http://localhost:9200/_search?pretty 也應該能看到一堆輸出,代表elasticsearch接收到logstash的數據了

4、kibana的配置啓動

一、修改配置文件

vi /elk/kibana-6.5.2-linux-x86_64/config/kibana.yml

修改第12行:

elasticsearch.url: "http://192.168.19.95:9200"

##指定訪問位置

二、啓動服務

/elk/kibana-6.5.2-linux-x86_64/bin

./kibana

 

啓動完成後,在瀏覽器裏輸入http://localhost:5601/ 便可看到kibana界面,首次運行,會提示建立index,直接點擊Create按鈕便可。

相關文章
相關標籤/搜索