ELK5.5+Filebeat分布式日誌系統

來源:互聯網
上載者:User
這是一個建立於 的文章,其中的資訊可能已經有所發展或是發生改變。

最近在用k8s管理項目, 每個容器都會列印自己的日誌, 目前的解決方案是用ntfs4線上檔案系統統一儲存, 考慮到效能問題, 還是將日誌列印到宿主機, 然後通過elk分布式日誌收集. 但如果在每台伺服器部署logstash是比較耗資源的, 畢竟是java項目. 好在作者重新用golang寫了一套新的採集工具filebeat, 效能更高, 暫用資源也更少, 所以這裡在每台伺服器部署filebeat採集日誌, 然後統一緩衝到redis, 而elk所在的伺服器通過logstashredis裡面取資料, 然後發送給elasticsearch分析, 通過kibana顯示


此圖是盜用別人的, 但能夠很好的展示流程, 所以自己就不畫了

一. Log Service器配置

下載二進位檔案到/mnt掛在目錄

# 進入掛載目錄  cd /mnt# 建立elk檔案夾mkdir elk# 下載elasticsearchwget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.5.1.tar.gz# 下載kibanawget https://artifacts.elastic.co/downloads/kibana/kibana-5.5.1-linux-x86_64.tar.gz# 下載logstashwget https://artifacts.elastic.co/downloads/logstash/logstash-5.5.1.tar.gz# 分別解壓tar -zxvf elasticsearch-5.5.1.tar.gztar -zxvf kibana-5.5.1.tar.gztar -zxvf logstash-5.5.1.tar.gz# 移動到elk目錄mv elasticsearch-5.5.1 elk/elasticsearchmv kibana-5.5.1 elk/kibanamv logstash-5.5.1 elk/logstash
1.配置Elasticsearch
# 進入目錄(`ES_HOME`所在的目錄)cd /mnt/elk/elasticsearch# 安裝X-Packbin/elasticsearch-plugin install x-pack# 編輯設定檔vi config/elasticsearch.yml# 頭部添加#################################################cluster.name: yinnote-elasticnetwork.host: 127.0.0.1#################################################

cluster.name 叢集的名稱
network.host 服務監聽地址, 最好設定成本機, 沒有必要對外開放
http.port 預設9200
path.logs 預設ES_HOME/logs
path.data 預設ES_HOME/data

# 啟動(daemon方式)bin/elasticsearch -d

配置登入認證, 從5.5版本開始, Shield已經整合到X-Pack, 不需要額外安裝

# 配置elastic帳號的密碼curl -XPUT -u elastic 'localhost:9200/_xpack/security/user/elastic/_password'-H "Content-Type: application/json" -d '{   "password" : "123456"}'# 配置kibana帳號的密碼curl -XPUT -u elastic 'localhost:9200/_xpack/security/user/kibana/_password'-H "Content-Type: application/json" -d '{   "password" : "123456"}'# 配置elastic帳號的密碼curl -XPUT -u elastic 'localhost:9200/_xpack/security/user/logstash_system/_password'-H "Content-Type: application/json" -d '{   "password" : "123456"}'# 產生密鑰bin/x-pack/syskeygen# 修改設定檔, 重啟vi config/elasticsearch.yml# 添加密鑰支援#################################################xpack.security.audit.enabled: true################################################## 重啟Elasticsearchkill -9 [pid]bin/elasticsearch -d
2.配置Kibana
# 進入目錄(KIBABA_HOME所在的目錄)cd /mnt/elk/kibana# 安裝X-Packbin/kibana-plugin install x-pack# 設定檔vi config# 頭部添加#################################################server.host: "0.0.0.0."elasticsearch.username: "elastic"elasticsearch.password: "123456"#################################################

server.port 對外連接埠, 預設5601
server.host 對外監聽ip, 如果有nginx代理, 可以設定成127.0.0.1
elasticsearch.url es地址, 預設http://127.0.0.1:9200
elasticsearch.username elastic帳號
elasticsearch.password elastic密碼

# 啟動(daemon方式)bin/kibana -d
3.配置Logstash

模式一: 從filebeat擷取採集資料

# 進入目錄(LOGSTASH_HOME所在的目錄)cd /mnt/elk/logstash# 建立設定檔vi client-http.conf# 添加#################################################input {    beats {        port => 5044        codec => "json"    }}output {    elasticsearch {        hosts => ["127.0.0.1:9200"]        index => "logstash-nginx-error-%{+YYYY.MM.dd}"        user => "elastic"        password => "123456"    }    stdout {codec => rubydebug}}################################################## 啟動服務(監聽模式, 便於查看資料)bin/logstash -e -f client-http.conf

模式二: 從redis擷取採集資料

# 建立設定檔vi client-redis.conf# 添加#################################################input {    redis {        host => "127.0.0.1"        port => "6379"        key => "filebeat"        data_type => "list"        password => "redis的密碼"        threads => 50    }}output {    elasticsearch {        hosts => ["127.0.0.1:9200"]        index => "logstash-nginx-error-%{+YYYY.MM.dd}"        user => "elastic"        password => "123456"    }    stdout {codec => rubydebug}}################################################## 啟動服務(監聽模式, 便於查看資料)bin/logstash -e -f client-http.conf

二. 用戶端資料擷取配置

# 下載安裝cd /mntwget https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-5.5.1-linux-x86_64.tar.gztar -zxvf filebeat-5.5.1-linux-x86_64.tar.gzmv filebeat-5.5.1-linux-x86_64 filebeat# 進入目錄cd filebeat

模式一: 通過RESTful介面發送資料 (同Logstash模式一對應)

# 建立設定檔vi client-http.yml# 添加#################################################filebeat.prospectors:- input_type: log  paths:    - /mnt/logs/nginx/error.log  fields:    feature: nginx-erroutput.logstash:  hosts: ["yinnote.com:5044"]################################################## 啟動服務(監聽模式, 便於查看資料)./filebeat -c client-http.yml

模式二: 通過Redis介面發送資料 (同Logstash模式二對應)

# 建立設定檔vi client-redis.yml# 添加#################################################filebeat.prospectors:- input_type: log  paths:    - /mnt/logs/nginx/error.log  fields:    feature: nginx-erroutput.redis:  hosts: ["yinnote.com"]  port: 6379  password: "redis的密碼"################################################## 啟動服務(監聽模式, 便於查看資料)./filebeat -c client-redis.yml

訪問後台

1. 瀏覽器訪問  http://yinnote.com:56012. 輸入elastic使用者和密碼即可登入3. 點擊左側的 discover 菜單, 即可查看日誌採集情況

時間比較匆忙, 寫得比較簡潔, 這裡主要是介紹最精簡的配置方式部署, 所以很多配置參數沒有介紹, 另外關於Elasticsearch叢集的部署沒有介紹, 後續會專門寫一篇.

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.