日志可视化之ELKF--filebeat

filebeat、elasticsearch、logstash、kibana此为日志可视化的基础设施。不过根据业务系统的体量不同,这些组件不是全都必须的。这里介绍EKF的部署方式,即elasticksearch、kibana、filebeat。

安装filebeat(centos)

  1. 执行
    sudo rpm --import https://packages.elastic.co/GPG-KEY-elasticsearch
    
  2. /etc/yum.repos.d/目录下创建elastic.repo 文件,内容如下:
    [elastic-7.x]
    name=Elastic repository for 7.x packages
    baseurl=https://mirror.tuna.tsinghua.edu.cn/elasticstack/7.x/yum/
    gpgcheck=1
    gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
    enabled=1
    autorefresh=1
    type=rpm-md
    
  3. 执行如下命令:
    sudo yum install filebeat
    sudo systemctl enable filebeat
    

filebeat配置

这里不再具体介绍,filebeat可以把应用产生的日志文件发送到logstash或者elasticsearch中去。这里主要介绍一些关键配置。

  • 在filebeat.yml文件中,首先修改filebeat.inputs:
#=========================== Filebeat inputs =============================

filebeat.inputs:

# Each - is an input. Most options can be set at the input level, so
# you can use different inputs for various configurations.
# Below are the input specific configurations.

- type: log

  # Change to true to enable this input configuration.
  enabled: true

  # Paths that should be crawled and fetched. Glob based paths.
  paths:
    - /home/xxx/xx/logs/xxx1.log
  tags: ['xxx1']
  fields:
    filetype: xxx1
  fields_under_root: true  # 新增一个字段,方便对不同的服务的log区分
  multiline.pattern: '^[0-9]{4}-[0-9]{2}-[0-9]{2}' #将异常栈信息合并
  multiline.negate: true
  multiline.match: after

- type: log

  # Change to true to enable this input configuration.
  enabled: true

  # Paths that should be crawled and fetched. Glob based paths.
  paths:
    - /home/xxx/xx/logs/xxx2.log
  tags: ['xxx2']
  fields:
    filetype: xxx1
  fields_under_root: true
  multiline.pattern: '^[0-9]{4}-[0-9]{2}-[0-9]{2}' #将异常栈信息合并
  multiline.negate: true
  multiline.match: after

这样可以给不同的服务的log文件加上不同的tag。这个tag在后面建立索引的时候很有用。

  • 其次要修改output.elasticsearch:
#-------------------------- Elasticsearch output ------------------------------
setup.template.name: "fb-"
setup.template.pattern: "fb-"
output.elasticsearch:
  # Array of hosts to connect to.
  hosts: ["host:9200"]

  # Protocol - either `http` (default) or `https`.
  protocol: "http"

  indices:
    - index: "fb-xxx1-%{+yyyy.MM.dd}"
      when.contains:
        tags: "xxx1"
    - index: "fb-xxx2-%{+yyyy.MM.dd}"
      when.contains:
        tags: "xxx2"

  # Authentication credentials - either API key or username/password.
  #api_key: "id:api_key"
  username: "elastic"
  password: "xxxxx"
  #index: "filebeat-%{+yyyy.MM.dd}"

注意indices这里就是根据上面的tag对log进行归类,创建不同的ES索引。这里的%{+yyyy.MM.dd}是根据日期来创建索引,为之后按天来删除历史索引数据提供方便。

需要注意的是前两行setup.template的配置一定要跟你修改的index的前缀一致。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值