根據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使用方法:
http://www.dahouduan.com/2016/10/17/bigdata-filebeat-elasticsearch-kibana-elk/
在日誌所在服務器上安裝Filebeat 收集日誌
rpm --import https://packages.elastic.co/GPG-KEY-elasticsearch
創建 vi /etc/yum.repos.d/beat.repo 文件
保存以下內容
[beats]
name=Elastic Beats Repository
baseurl=https://packages.elastic.co/beats/yum/el/$basearch
enabled=1
gpgkey=https://packages.elastic.co/GPG-KEY-elasticsearch
gpgcheck=1
開始安裝 yum -y install filebeat
開機自啓動 chkconfig --add filebeat
啓動命令 service filebeat start
修改filebeat.yml 配置文件
vi /etc/filebeat/filebeat.yml
重啓服務
service filebeat restart
轉入後臺運行,最後到kibana裏,創建一個索引,注意pattern爲:filebeat-*
二、kibana的登錄認證問題
kibana是nodejs開發的,本身並沒有任何安全限制,直接瀏覽url就能訪問,如果公網環境非常不安全,可以通過nginx請求轉發增加認證,方法如下:
tips:kibana沒有重啓命令,要重啓,只能ps -ef|grep node 查找nodejs進程,幹掉重來。
1、參考以下內容,修改配置文件:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | server { listen 80; server_name kibana.xxx.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; } |
上面的配置表示將kibana.xxx.com的請求,轉發到服務器的5601端口,同時使用最基本的用戶名、密碼來認證。
2、配置登錄用戶名,密碼
1 | htpasswd -c /data/nginx/db/passwd .db kibana |
注意passwd.db的路徑要跟nginx配置中的一致,最後的kibana爲用戶名,可以隨便改,
輸入完該命令後,系統會提示輸入密碼,搞定後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