filebeat部署

一.filebeat软件包

1.在线获取

curl -L -O https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-6.4.0-x86_64.rpm

如果官网下载速度慢:通过下面方式获取:
链接: https://pan.baidu.com/s/1BERX19xKY63WMpvaNSlsJw
提取码: e827

2.离线获取

到filebeat官网自行下载到本地,再上传到服务器。filebeat官网下载地址:https://www.elastic.co/guide/en/beats/filebeat/current/index.html

二.部署

1.安装filebeat

到filebeat软件包所在的目录执行以下命令

rpm -iv filebeat-6.4.0-x86_64.rpm

执行该命令后,filebeat安装成功了,相应的目录如下:

Home path: [/usr/share/filebeat]
Config path: [/etc/filebeat]
Data path: [/var/lib/filebeat]
Logs path: [/var/log/filebeat]

2.配置filebeat,收集日志

filebeat启动后读取配置文件:/etc/filebeat/filebeat.yml

而filebeat配置灵活:推荐以下配置方式

  • /etc/filebeat/filebeat.yml 配置公用配置,比如连接kafka的地址,cpu核数限制等公用参数。
  • /etc/filebeat/configs/ 目录下放具体的配置文件,可以是多个;该目录下的配置文件: 不同的采集项配置内容不一样; /etc/filebeat/filebeat.yml文件中引用了目录:/etc/filebeat/configs/ 。

3.配置示例

以收集demo1日志为例:

3.1 /etc/filebeat/filebeat.yml 内容

filebeat.config.prospectors:
  path: configs/*.yml
  reload.enabled: true
  reload.period: 30s

output.kafka:
  hosts: ["node1:9092","node2:9092","node3:9092"]
  topic: '%{[log_type]}'
  partition.round_robin:
    reachable_only: true

3.2 /etc/filebeat/configs/ 下的配置文件: basiclog-demo1.yml

- type: log
  paths:
    - /data/logs/demo1.log
  tail_files: true
  fields_under_root: true
  fields:
    log_topic: basiclog-demo1

3.3 配置参数说明

- type: log
  paths:
    - /data/logs/demo1.log  (变量,填写实际采集路径)
  tail_files: true
  fields_under_root: true
  fields:
    log_topic: basiclog-demo1  (变量,这里是kafka的topic,填写实际的topic)

注:

  • 上述中除了标明是变量的地方,其他地方都固定。
  • 上图中的fields是自定义字段: file_name就写日志名称,如果没有日志文件名就自定义一个业务标识即可。
  • 日志采集路径 和kafka的topic都是动态的。

4.filebeat启动/重启/停止
centos 6.x:

service filebeat start
service filebeat restart
service filebeat stop

centos 7.x:

systemctl start filebeat
systemctl restart filebeat
systemctl stop filebeat

5.filebeat开机自启动

chkconfig filebeat on
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值