Fork me on GitHub

ELK日志收集系统—ELK

参考文档:
https://blog.csdn.net/u014773389/article/details/81207017
https://www.cnblogs.com/aubin/p/8026184.html
https://blog.csdn.net/qq_22211217/article/details/80764568

一、ELK应用场景

在复杂的企业应用服务群中,记录日志方式多种多样,并且不易归档以及提供日志监控的机制。无论是开发人员还是运维人员都无法准确的定位服务、服务器上面出现的种种问题,也没有高效搜索日志内容从而快速定位问题的方式。因此需要一个集中式、独立的、搜集管理各个服务和服务器上的日志信息,集中管理,并提供良好的UI界面进行数据展示,处理分析。

得此:ELK提供一套开源的解决方案,能高效、简便的满足以上场景。

二、ELK日志系统介绍

1、ELK分别是Elasticsearch、Logstash、Kibana三个开源框架缩写。

框架 简介 作用
Elasticsearch 开源分布式搜索引擎,提供存储、分析、搜索功能。特点:分布式、基于reasful风格、支持海量高并发的准实时搜索场景、稳定、可靠、快速、使用方便等。 接收搜集的海量结构化日志数据,并提供给kibana查询分析
Logstash 开源日志搜集、分析、过滤框架,支持多种数据输入输出方式。 用于收集日志,对日志进行过滤形成结构化数据,并转发到elasticsearch中
Kibana 开源日志报表系统,对elasticsearch以及logstash有良好的web页面支持。 对elasticsearch提供的数据进行分析展示

2、ELK经典应用如下

Logstash部署至服务主机,对各个服务的日志进行采集、过滤、推送。
Elasticsearch存储Logstash传送的结构化数据,提供给Kibana。
Kibana提供用户UIweb页面进行,数据展示和分析形成图表等。

备注:logs 泛指,各种日志文件以及日志信息:windows,negix,tomcat,webserver等等。

工作中每天需要做的报表

1.找出访问排名前10的IP
2.找出访问排名前10的URL
3.找出10点到14点之间访问频次最高的IP和URL
4.找出10点到14点之间bbs网站访问最高的IP和URL
5.找出攻击者的IP,他都访问了什么页面?从什么时候来的,什么时候走的,一共访问多少次
6.找出昨天和今天同时间段访问有什么变化
7.查看各大搜索引擎今天访问了多少次,都访问了哪些页面
8.找出哪些是伪造的爬虫IP,并查封
9.5分钟内告诉我结果

资料链接

ELK日志收集

Elasticsearch java 存储,提供数据
Logstash java 收集日志,转发到ES,过滤转换字段
Kibana java 过滤,分析,搜索,展示
Filebeat GO 收集日志,转发给ES


1.kibana安装

[root@elk01 /server/tools/EFLK软件包v6.6.0]# ls
ansible_elk.tar.gz
elasticsearch-6.6.0.rpm
filebeat-6.6.0-x86_64.rpm
kibana-6.6.0-x86_64.rpm
logstash-6.6.0.rpm
rpm -ivh kibana-6.6.0-x86_64.rpm

2.kibana配置

[root@lb01 /data/soft]# grep "^[a-z]" /etc/kibana/kibana.yml
server.port: 5601
server.host: "10.0.0.5"
elasticsearch.hosts: ["http://10.0.0.5:9200"]
kibana.index: ".kibana"

重启kibana
systemctl restart kibana.service





删除例子

3.filebeat

安装filebeat
rpm -ivh filebeat-6.6.0-x86_64.rpm 

查看配置文件路径
[root@elk01 ~]# rpm -qc filebeat 
/etc/filebeat/filebeat.yml

修改配置文件
[root@elk01 ~]# vim  /etc/filebeat/filebeat.yml
filebeat.inputs:
- type: log
  enabled: true
  paths:
    - /var/log/nginx/access.log
output.elasticsearch:
  hosts: ["10.0.0.5:9200"]

启动filebeat
[root@elk01 ~]# systemctl restart filebeat.service

查看日志
[root@elk01 ~]# tail -f /var/log/filebeat/filebeat 

安装nginx
[root@elk01 ~]# yum install -y nginx

启动nginx
[root@elk01 ~]# systemctl restart nginx.service 

在浏览器上刷一些访问日志
http://10.0.0.5/YouArePig

查看nginx的日志
[root@elk01 ~]# tail -f /var/log/nginx/access.log

filebeat工作原理
100条
停止filebeat
110条
启动filebeat

刷新elasticsearch-head插件

操作kibana







收集Nginx的json日志

1.第一步:修改nginx日志为json格式,重启nginx

> /var/log/nginx/access.log

log_format json '{ "time_local": "$time_local", '
                     '"remote_addr": "$remote_addr", '
                     '"referer": "$http_referer", '
                     '"request": "$request", '
                     '"status": $status, '
                     '"bytes": $body_bytes_sent, '
                     '"agent": "$http_user_agent", '
                     '"x_forwarded": "$http_x_forwarded_for", '
                     '"up_addr": "$upstream_addr",'
                     '"up_host": "$upstream_http_host",'
                     '"upstream_time": "$upstream_response_time",'
                     '"request_time": "$request_time"'
 ' }';


systemctl restart nginx
 
access_log  /var/log/nginx/access.log  json; 

第二步:修改filebeat配置文件

[root@lb01 ~]# cat /etc/filebeat/filebeat.yml 
filebeat.inputs:
- type: log
  enabled: true
  paths:
    - /var/log/nginx/access.log
  json.keys_under_root: true
  json.overwrite_keys: true
  tags: ["access"] 

- type: log
  enabled: true
  paths:
    - /var/log/nginx/error.log
  tags: ["error"] 

output.elasticsearch:
  hosts: ["10.0.0.5:9200"]
  indices:
  - index: "nginx-access-%{[beat.version]}-%{+yyyy.MM}"
    when.contains:
      tags: "access"
  - index: "nginx-error-%{[beat.version]}-%{+yyyy.MM}"
    when.contains:
      tags: "error"

setup.template.name: "nginx"
setup.template.pattern: "nginx-*"
setup.template.enabled: false
setup.template.overwrite: true

=================================

重启filebeat

systemctl restart filebeat

第三步: 访问nginx

ab -c 10 -n 100 http://10.0.0.5/oldzhang.html

第四步: kibana添加索引








posted @ 2019-09-02 09:55  lcx1997  阅读(388)  评论(0)    收藏  举报