ELK日志系統:Filebeat使用及Kibana如何設置登錄認證


根據elastic上的說法:

Filebeat is a lightweight, open source shipper for log file data. As the next-generation Logstash Forwarder, Filebeat tails logs and quickly sends this information to Logstash for further parsing and enrichment or to Elasticsearch for centralized storage and analysis.

Filebeat比Logstash貌似更好,是下一代的日志收集器,ELK(Elastic + Logstash + Kibana)以后估計要改名成EFK。

 

Filebeat使用方法:

1、下載最新的filebeat

地址:https://www.elastic.co/downloads/beats/filebeat 然后解壓到任意目錄

 

2、修改filebeat下的filebeat.yml文件,參考以下內容:

filebeat:
  prospectors:
    -
      paths:
        - "/var/log/nginx/*.log"
      input_type: log
      document_type: nginx-access

    -
     paths:
       - "/data/log/order/*.log"
     input_type: log
     document_type: order-service

    -
     paths:
       - "/opt/service/zhifu/logs/*.log"
     input_type: log
     document_type: zhifu-service

output:
  elasticsearch:
    hosts: ["localhost:9200"]

logging:
  files:
    rotateeverybytes: 10485760

里面hosts里的內容,改成實際elasticsearch的地址。

 

3、設置elasticsearch的filebeat模板

curl -XPUT 'http://localhost:9200/_template/filebeat?pretty' -d@/etc/filebeat/filebeat.template.json

注:上面localhost:9200改成實際的elasticsearch的地址,后面的一串為filebeat根目錄下的filebeat.template.json的完整路徑,順利的話,會返回:

{
  "acknowledged" : true
}

表示模板已被接收。

 

4、啟動

./filebeat -e -c filebeat.yml -d "Publish"

如果能看到一堆東西輸出,表示正在向elastic search發送日志。可以瀏覽:http://192.168.1.111:9200/_search?pretty 如果有新內容返回,表示ok

測試正常后,Ctrl+C結束,然后用

nohup ./filebeat -e -c filebeat.yml >/dev/null 2>&1 &

轉入后台運行,最后到kibana里,創建一個索引,注意pattern為:filebeat-*

  

 

二、kibana的登錄認證問題

kibana是nodejs開發的,本身並沒有任何安全限制,直接瀏覽url就能訪問,如果公網環境非常不安全,可以通過nginx請求轉發增加認證,方法如下:

tips:kibana沒有重啟命令,要重啟,只能ps -ef|grep node 查找nodejs進程,干掉重來。

1、參考以下內容,修改配置文件:

server {
  listen       80;
  server_name elk.yjmyzz.com;
  location / {
     auth_basic "secret";
     auth_basic_user_file /data/nginx/db/passwd.db;
     proxy_pass http://localhost:5601;
     proxy_set_header Host $host:5601;
     proxy_set_header X-Real-IP $remote_addr;
     proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
     proxy_set_header Via "nginx";
  }
  access_log off;
}

上面的配置表示將elk.yjmyzz.com的請求,轉發到服務器的5601端口,同時使用最基本的用戶名、密碼來認證。

 

2、配置登錄用戶名,密碼

htpasswd -c /data/nginx/db/passwd.db user1

注意passwd.db的路徑要跟nginx配置中的一致,最后的user1為用戶名,可以隨便改,輸入完該命令后,系統會提示輸入密碼,搞定后passwd.db中就有加密后的密碼了,有興趣的可以cat看下。

提示:htpasswd是apache自帶的小工具,如果找不到該命令,嘗試用yum install httpd安裝

 

3、關掉kibana端口的外網訪問

用nginx轉發后,一定要記得配置iptables之類的防火牆,禁止外部直接訪問5601端口,這樣就只能通過nginx來訪問了。

參考文章:

1、http://elk-docker.readthedocs.org/

2、https://www.elastic.co/guide/en/beats/filebeat/current/filebeat-getting-started.html 

3、http://geek.csdn.net/news/detail/54967


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM