介绍

由于pk服务器使用arm架构,网上很难找到安装教程。并且官方也没有提供arm安装包,这点很坑!这里笔者整理了一下,供大家参考。
对比x86安装,相对麻烦一些。但能成功使用,大家有需要一定要耐心看完

安装使用
uname -a

pk:

x86安装方法这里就不阐述了,主要介绍pk版本的filebeat安装方法。

1. 安装golang

  1. 从golang官网下下载golang-1.14.3_arm64
    https://studygolang.com/dl
    go1.14.3.linux-arm64.tar.gz

  2. 解压到/usr/lib下

ln -s /usr/lib/go/bin/go  /usr/bin/go
ln -s /usr/lib/go/bin/gofmt  /usr/bin/gofmt
  1. 配置go环境变量
vim /etc/profile
export GOROOT=/usr/lib/go
export GOPATH=/root/go  # 这里请根据需要填入,用于存放之后go的各种依赖包,需先创建文件夹
export PATH=$GOPATH/bin:$GOROOT/bin:$PATH
source /etc/profile
go version

2. Filebeat安装

  1. Filebeat下载编译
cd /data/software
wget https://github.com/elastic/beats/archive/v7.4.1.tar.gz
  1. 创建目录并解压到指定目录
mkdir -p $GOPATH/src/github.com/elastic
tar -zxvf beats-7.4.1.tar.gz -C $GOPATH/src/github.com/elastic
cd  $GOPATH/src/github.com/elastic
mv beats-7.4.1 beats
  1. 修改配置文件stderr_other.go
cd /root/go/src/github.com/elastic/beats/libbeat/common/file/

拷贝该目录下的stderr_other.go到本地,用notepad++修改30行,return syscall.Dup2(int(toFile.Fd()),2)为return syscall.Dup3(int(toFile.Fd()),2,0)
放回linux原目录下

cd $GOPATH/src/github.com/elastic/beats/filebeat
go build

编译成功后生成可执行文件filebeat

修改filebeat.yml配置文件,先打印到控制台试下

filebeat.inputs: 
- type: stdin 
  enabled: true 
setup.template.settings: 
   index.number_of_shards: 3 
output.console: 
   pretty: true 
   enable: true
./filebeat -e -c filebeat.yml

filebeat多个应用目录采集配置方法:
修改filebeat.ymlll

filebeat.inputs:
- type: log
  enabled: true
  paths:
    - /opt/web/8091-cms-boot/logs/CMS_ROOT.log
  tags: ["cms"]
  fields:
    index: "cms"

- type: log
  enabled: true
  paths:
    - /opt/nodes/node-saber/boot/logs/SABER_ROOT.log
  tags: ["saber"]
  fields:
    index: "saber"
setup.template.settings:
  index.number_of_shards: 3
output.elasticsearch:
  hosts: ["192.168.1.137:9200"]
  indices:
    - index: "filebeat-cms"
      when.contains:
        fields:
          index: "cms"
    - index: "filebeat-saber"
      when.contains:
        fields:
          index: "saber"

把启动命令做成shell脚本

nohup /root/go/src/github.com/elastic/beats/filebeat/filebeat -e -c /root/go/src/github.com/elastic/beats/filebeat/filebeat.yml > filebeat.log &

启动成功后能看到日志