1. 程式人生 > 實用技巧 >ELK7.8.0版本整合記錄

ELK7.8.0版本整合記錄

1.搭建elasticsearch 版本:7.8.0

1.前期準備:

1.jdk1.8及以上環境安裝

2. elasticsearch,logstash,kibana的7.8.0下載

2.配置修改

在config下的elasticsearch.yml

#配置節點名稱,為下面的cluster.initial_master_nodes鋪墊

node.name: node-1

#配置日誌路徑

path.logs: /usr/local/app/elasticsearch-7.8.0/logs

#配置外網訪問(需關閉防火牆)

network.host: 0.0.0.0

#配置埠號

http.port: 9200

3. 啟動elasticsearch

在bin目錄下,切換到非root使用者,啟動命令: ./elasticsearch

後臺啟動elasticsearch,需要使用: ./elasticsearch -d

這時執行的時候會出現沒有許可權./elasticsearch: Permission denied
需要授權執行命令:chmod +x bin/elasticsearch
再次執行./elasticsearch -d即可啟動
使用ps aux|grep elasticsearch可以檢視是否啟動

4.可能出現的bug以及解決方案

報錯:max file descriptors [4096] for elasticsearch process is too low, increase to at least [65535]

解決方案: 編輯 /etc/security/limits.conf,追加以下內容;
* soft nofile 65536
* hard nofile 65536
此檔案修改後需要重新重新啟動或者登入使用者,才會生效

報錯:max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]

解決方案:

切換到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

即可永久修改

5.瀏覽器頁面瀏覽

比如我自己的虛擬機器器ip是192.168.1.10 ,那麼瀏覽器訪問http://192.168.1.10:9200/

2.搭建logstash 版本:7.8.0

  1.新增配置

初始化配置檔案為config目錄下的logstash-sample.conf,為了啟動方便,在bin目錄下新增logstash.conf檔案

1.讀取檔案直接傳送到es


         input {
                #beats {
                # port => 5044
                #}
                file {
                    path => "/var/log/httpd/access_log"
                    start_position => beginning
                     }
                }

         output {
                elasticsearch {
                    hosts => ["http://localhost:9200"]
                    index => "%{[@metadata][logstash]}-%{[@metadata][version]}-%{+YYYY.MM.dd}"
                    #user => "elastic"
                    #password => "changeme"
                              }
                 }    

2.tcp方式

         input {
                tcp {  
                    ##host:port就是上面appender中的 destination,這裡其實把logstash作為服務,開啟8080埠接收logback發出的訊息  
                    host => "localhost"  
                    port => 8080  
                    #模式選擇為server  
                    mode => "server"  
                    tags => ["tags"]  

                    ##格式json  
                    codec => json_lines         
                    }  

               } 

         output {
                elasticsearch {
                    #ES地址
                    hosts => "127.0.0.1:9200"
                    #指定索引名字
                    index => "applog"
                    }
                stdout { codec => rubydebug}
                }

2.啟動

定位到config目錄下,啟動命令: ../logstash -f logstash.conf

後臺啟動命令: ../logstash -f logstash.conf &

3.搭建kibana 版本:7.8.0

1.配置

1. 將kibana/config/kibana.yml中的預設配置#i18n.locale: "en"改為i18n.locale: "zh-CN"

2.在kibana/config/kibana.yml中修改配置

            server.port: 5601       ##服務埠
            server.host: "0.0.0.0"  ##伺服器ip  本機
            elasticsearch.url: "http://localhost:9200" ##elasticsearch服務地址 與elasticsearch對應

2.啟動

定位到bin目錄下,啟動命令: ./kibana &