GrayLog 配置日志文件读取

位置:首页>文章>详情   分类: 教程分享 > Linux和Shell教程   阅读(2416)   2024-04-19 09:14:52

前置条件

安装部署好graylog server

创建graylog input

打开System/Inputs菜单input菜单


选择输入类型为filebeat进行创建input

创建input
创建input

 

input信息配置
input信息配置


input信息,这里简单就注意填写两个东西,一个是名称,输入一个比如Beats,然后另外一个就是端口,默认是5044,注意该端口未被占用哟。其他信息默认即可
 

创建graylog-sidecar的token

token
操作示例图-1644557548001.png

创建完毕后记得复制出来,后面看不见了

安装collector-sidecar 

wget https://github.com/Graylog2/collector-sidecar/releases/download/1.1.0/graylog-sidecar_1.1.0-1_amd64.deb
sudo dpkg -i graylog-sidecar_1.1.0-1_amd64.deb

其他系统:
https://github.com/Graylog2/collector-sidecar 


修改配置
sudo vi /etc/graylog/sidecar/sidecar.yml

server_url: "http://你的ip:你的端口/api"
server_api_token: "上面获取的token"
node_name: "自己取一个客户端节点名称,会在graylog中System/Sidecars页面显示"
update_interval: 10
send_status: true


注册为系统服务

sudo graylog-sidecar -service install
sudo systemctl start graylog-sidecar

 

filebeat安装

wget https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-6.3.0-amd64.deb
sudo dpkg -i filebeat-6.3.0-amd64.deb

 其他系统:
Download Filebeat • Lightweight Log Analysis | Elastic

配置采集规则

在Sidecar Overview界面点击Configuration配置

当上面的graylog-sidecar服务启动成功后,如果链接到graylog服务没问题,则在Overview 界面下面的列表中可以看到配置的节点名称,例如上面配置的节点名称为glyh-host,同时可以看到在运行的状态等信息

点击Create Configuration创建配置
创建


配置信息
配置信息
红色圈的都是需要根据实际情况修改的
参考:

# Needed for Graylog
fields_under_root: true
fields.collector_node_id: ${sidecar.nodeName}
fields.gl2_source_collector: ${sidecar.nodeId}

filebeat.inputs:
- input_type: log
  paths:
    - /opt/docker/data/log/info/*.log
  #处理多行
  multiline.pattern: '^[0-9]{4}-[0-9]{2}-[0-9]{2}'
  multiline.negate: true
  multiline.match: after

  type: log
output.logstash:
   hosts: ["192.168.0.22:5044"]
path:
  data: /var/lib/graylog-sidecar/collectors/filebeat/data
  logs: /var/lib/graylog-sidecar/collectors/filebeat/log
multiline.pattern: '^\[[0-9]{4}-[0-9]{2}-[0-9]{2}'
multiline.negate: true
multiline.match: after

上方代码处理多行日志到同一行输出,注意正则表达式,这里我的日志全部是日期格式yyyy-MM-dd开头的,所以这样配置,效果为:
此配置使用negate: truematch: after设置来指定任何不符合指定模式的行都属于上一行。

 

提示:
output.logstash
       hosts: ["192.168.0.22:5044"]
这里的ip+端口必须是客服端能访问通的网络
ip:是graylog server 访问ip
端口:5044是前面配置的input beats类型的端口

配置好以后点击create保存配置
 

配置文件下发

先回到Sidecar Overview界面, 点击Administration管理按钮, 进行配置下发

选择采集器,勾选filebeat
操作示例图-1644557162989.png
点击configure, 选择之前创建的配置文件, 进行配置应用下发确定下发

验证日志采集是否生效

在Sidecars Overview  点击show messages 查询对应日志 如果存在则证明成功

操作示例图-1644557331858.png


成功输出日志

 

地址:https://www.leftso.com/article/960.html

相关阅读

前置条件安装部署好graylog server创建graylog input 打开System/Inputs菜单选择输入类型为filebeat进行创建input创建inputinput信息配置i...
环境准备minikube 安装,参考minikube k8s 安装详细教程spring boot demo项目一个spring boot项目 maven 主要依赖 <depe...
简单介绍在graylog web界面如何查询想要的日志 查询单个字符串 "your-info" 查询包含A和B的记录
接上篇文章minikube(k8s)部署spring boot项目(一)上篇文章讲解了k8s部署spring boot demo项目的一部分,本文主要讲解如何将服务暴露指定的端口给外部调用
环境本次minikube安装环境为Ubuntu 18.04.6 LTS安装docker-ce参考:Ubuntu 在线安装 Docker-左搜 (leftso.com)注意配置docker镜像地址...
Havenotfoundanylogfileforsshdjail导致原因没有找到ssh的日志文件/var/log/auth.log导致因素:Ubuntu22.04LTS,使用了精简版本,缺少了...
GrayLog admin账号修改密码(docker版)由于graylog的admin账号不是配置到数据库中,而是配置到配置文件/etc/graylog/server/server.conf里面...
安装docker和docker-compose参考文章:CentOS 8.0-8.4 yum 安装docker-ce-左搜 (leftso.com)Ubuntu 在线安装 Docker-左搜 (...
 GrayLog 普通用户添加及配置角色Graylog添加用户首先登录管理员账号,打开System&gtl;Users and Teams 点击右边的"Create User"按钮,开始创建用户...
poxm.xml文件添加maven依赖 <dependency&gtl; <groupId&gtl;org.apache.skywalking&...