当前位置: 首页 > news >正文

ELK 通过 logstash 收集单个/多个日志文件

一、收集单个日志文件

注意事项:

  1. logstah 服务默认启动用户和组是 logstash
  2. 被收集的日志文件有读的权限并对写入的文件有写权限
  3. 而 logstash 是普通用户

1.1 编辑 logstash 配置文件

1.2 检测配置文件语法是否正确和启动

#检测配置文件语法是否正确
root@ubuntu1804:~# /usr/share/logstash/bin/logstash -f /etc/logstash/conf.d/test.conf -t
#启动
root@ubuntu1804:~# /usr/share/logstash/bin/logstash -f /etc/logstash/conf.d/test.conf

1.3 生成数据并验证

root@logstash1:~# echo "test" >> /var/log/syslog

二、收集多个日志文件

2.1 编辑 logstash 配置文件

vim /etc/logstash/conf.d/test.conf
input {
  file {
    path => "/var/log/syslog"
    type => "systemlog"
    start_position => "beginning"
    stat_interval => "3 second"
  } 
  file {
    path => "/var/log/vmware*.log"
    type => "vmwarelog"
    start_position => "beginning"
    stat_interval => "3 second"
  }
}

output {
  if [type] == "systemlog" {
    elasticsearch {
      hosts => ["10.0.0.31:9200"] 
      index => "logstash-lck-testindex"
    }
  }
  if [type] == "vmwarelog" {
    elasticsearch {
      hosts => ["10.0.0.31:9200"] 
      index => "logstash-lck-vmwarelog-%{+YYYY.MM.dd}"
    }
  }
}

2.2 检测配置文件语法是否正确和启动

#检测配置文件语法是否正确
root@ubuntu1804:~# /usr/share/logstash/bin/logstash -f /etc/logstash/conf.d/test.conf -t
#启动
root@ubuntu1804:~# /usr/share/logstash/bin/logstash -f /etc/logstash/conf.d/test.conf

2.3 启动服务,并验证

#注册成系统服务的启动
systemctl restart logstash.service
#压缩包方式的启动
root@ubuntu1804:~# /usr/share/logstash/bin/logstash -f /etc/logstash/conf.d/test.conf

2.4 创建索引方便查询日志


 


 

相关文章:

  • GaussDB(for PostgreSQL) 存储引擎:ASTORE 与 USTORE 详细对比
  • KTransformer:国产高性能大模型加载工具使用指南
  • WindowsPE文件格式入门04.导入表
  • Spring基础一(IoC、Spring配置)
  • Oracle数据库数据编程SQL<3.7 PL/SQL 触发器(Trigger)>
  • Modbus TCP转profibusDP网关接防撞雷达快速配置
  • 【TVM教程】使用 TVMC Micro 执行微模型
  • [C++]C++11(上)
  • 基于 SpringBoot 的旧物置换网站
  • 域渗透-域环境操作与组策略
  • 飞桨深度学习平台:技术架构、产业实践与生态全景解析
  • 【软件】在Windows和Ubuntu上使用TFTP和NFS
  • 视频设备轨迹回放平台EasyCVR渡口码头智能监控系统方案,确保港口安全稳定运行
  • 23种设计模式-结构型模式-外观
  • 《深度剖析SQL游标:复杂数据处理场景下的智慧抉择》
  • 如何选择飞速(FS)1G POE交换机?
  • 【JavaWeb】前端基础
  • Node 22.11使用ts-node报错
  • 快速部署:AI创作系统通用部署流程,上手简单高效部署
  • 变更日志0..1.0
  • 上海:到2027年,实现近海航线及重点海域5G网络高质量覆盖
  • 霍步刚任辽宁沈阳市委书记
  • 中央提级巡视后,昆明厅官郭子贞接受审查调查
  • 农行再回应客户办理业务期间离世:亲属连续三次输错密码,理解亲属悲痛,将协助做好善后
  • 经常口干口渴的人,要当心这些病
  • 从能源装备向应急装备蓝海拓展,川润股份发布智能综合防灾应急仓