根据elastic上的说法:javascript
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.html
Filebeat比Logstash貌似更好,是下一代的日志收集器,ELK(Elastic + Logstash + Kibana)之后估计要更名成EFK。java
Filebeat使用方法:node
一、下载最新的filebeatnginx
地址:https://www.elastic.co/downloads/beats/filebeat 而后解压到任意目录docker
二、修改filebeat下的filebeat.yml文件,参考如下内容:apache
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的地址。json
三、设置elasticsearch的filebeat模板安全
curl -XPUT 'http://localhost:9200/_template/filebeat?pretty' -d@/etc/filebeat/filebeat.template.json
注:上面localhost:9200改为实际的elasticsearch的地址,后面的一串为filebeat根目录下的filebeat.template.json的完整路径,顺利的话,会返回:bash
{ "acknowledged" : true }
表示模板已被接收。
四、启动
./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-*
2、kibana的登陆认证问题
kibana是nodejs开发的,自己并无任何安全限制,直接浏览url就能访问,若是公网环境很是不安全,能够经过nginx请求转发增长认证,方法以下:
tips:kibana没有重启命令,要重启,只能ps -ef|grep node 查找nodejs进程,干掉重来。
一、参考如下内容,修改配置文件:
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端口,同时使用最基本的用户名、密码来认证。
二、配置登陆用户名,密码
htpasswd -c /data/nginx/db/passwd.db user1
注意passwd.db的路径要跟nginx配置中的一致,最后的user1为用户名,能够随便改,输入完该命令后,系统会提示输入密码,搞定后passwd.db中就有加密后的密码了,有兴趣的能够cat看下。
提示:htpasswd是apache自带的小工具,若是找不到该命令,尝试用yum install httpd安装
三、关掉kibana端口的外网访问
用nginx转发后,必定要记得配置iptables之类的防火墙,禁止外部直接访问5601端口,这样就只能经过nginx来访问了。
参考文章:
一、http://elk-docker.readthedocs.org/
二、https://www.elastic.co/guide/en/beats/filebeat/current/filebeat-getting-started.html