ELK日志系统:Filebeat使用及Kibana如何设置登录认证

来源:互联网 发布:nginx 市场占有量 编辑:程序博客网 时间:2024/05/17 02:01

根据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文件,参考以下内容:

里面hosts里的内容,改成实际elasticsearch的地址。

 

3、设置elasticsearch的filebeat模板

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

注:上面localhost:9200改成实际的elasticsearch的地址,后面的一串为filebeat根目录下的filebeat.template.json的完整路径,顺利的话,会返回:

1
2
3      
{
  "acknowledged":true
}

表示模板已被接收。

 

4、启动

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

如果能看到一堆东西输出,表示正在向elastic search发送日志。可以浏览:http://192.168.1.111:9200/_search?pretty 如果有新内容返回,表示ok

测试正常后,Ctrl+C结束,然后用

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

转入后台运行,最后到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 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、配置登录用户名,密码

1
    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

作者:菩提树下的杨过
出处:http://yjmyzz.cnblogs.com
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。

阅读全文
0 0