1、logstash 收集系统日志

1.1 logstash配置文件

root@logstash-node1:~# vim /etc/logstash/conf.d/syslog-to-es.conf input {file {path =>"/var/log/syslog"#第一次从头收集,之后从新添加的日志收集start_position => "beginning"#日志收集的间隔时间stat_interval =>"3"type=>"syslog"}
}
output {if [type] == "syslog" {elasticsearch {hosts => ["10.10.100.120:9200"]index => "syslog-100.105-%{+YYYY.MM.dd}"}}
}

1.2 启动logstash

#添加syslog文件读权限,或者直接使用root用户启动logstash
root@logstash-node1:~# chmod o+r /var/log/syslog#启动前可以通过命令测试配置文件
root@logstash-node1:~# /usr/share/logstash/bin/logstash -f /etc/logstash/conf.d/syslog-to-es.conf -t#测试正常后重启logstash
root@logstash-node1:~# systemctl restart logstash

1.3 查看es索引

root@es-node1:~# curl 'localhost:9200/_cat/indices?v'
health status index                          uuid                   pri rep docs.count docs.deleted store.size
green  open   syslog-100.105-2022.04.12      2sKdW70BSz2ob8Jfxb6jXw   1   1      13062            0      4.8mb          2.4mb

1.4 kibana 查看日志

1.4.1 创建索引模式

Stack Management >> 索引模式 >> 创建索引模式



1.4.2 查看日志

Discover

2、tomcat日志收集

2.1 tomcat 日志转 json

root@logstash-node1:/apps/tomcat# vim conf/server.xml
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"prefix="localhost_access_log" suffix=".log"pattern="{&quot;clientip&quot;:&quot;%h&quot;,&quot;ClientUser&quot;:&quot;%l&quot;,&quot;authenticated&quot;:&quot;%u&quot;,&quot;AccessTime&quot;:&quot;%t&quot;,&quot;method&quot;:&quot;%r&quot;,&quot;status&quot;:&quot;%s&quot;,&quot;SendBytes&quot;:&quot;%b&quot;,&quot;Query?string&quot;:&quot;%q&quot;,&quot;partner&quot;:&quot;%{Referer}i&quot;,&quot;AgentVersion&quot;:&quot;%{User-Agent}i&quot;}"/>#验证查看日志
root@logstash-node1:/apps/tomcat# tail -f logs/localhost_access_log.2022-04-13.log
{"clientip":"10.10.100.1","ClientUser":"-","authenticated":"-","AccessTime":"[13/Apr/2022:11:32:18 +0800]","method":"GET / HTTP/1.1","status":"200","SendBytes":"14","Query?string":"","partner":"-","AgentVersion":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.75 Safari/537.36"}
{"clientip":"10.10.100.1","ClientUser":"-","authenticated":"-","AccessTime":"[13/Apr/2022:11:32:18 +0800]","method":"GET /favicon.ico HTTP/1.1","status":"200","SendBytes":"21630","Query?string":"","partner":"http://10.10.100.115:8080/","AgentVersion":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.75 Safari/537.36"}

2.2 配置logstash

root@logstash-node1:~# vim /etc/logstash/conf.d/tomcat_access_log.confinput {file {path => "/apps/tomcat/logs/localhost_access_log.2022-04-13.log"start_position => "beginning"stat_interval =>"3"type=>"tomcat_access_log"codec => "json"}
}
output {if [type] == "tomcat_access_log" {elasticsearch {hosts => ["10.10.100.120:9200"]index => "tomcat-accesslog-100.105-%{+YYYY.MM.dd}"}}
}#添加日志文件权限
root@logstash-node1:~# chmod o+r /apps/tomcat/logs/localhost_access_log.2022-04-13.log#重启logstash
root@logstash-node1:~# systemctl restart logstash

2.3 验证查看

查看索引

root@es-node1:~# curl '10.10.100.120:9200/_cat/indices?v'
health status index                               uuid                   pri rep docs.count docs.deleted store.size pri.store.size
green  open   tomcat-accesslog-100.105-2022.04.13 nXmwge_JQo6oTDx5BZK_3g   1   1         23            0    124.9kb         73.3kb
green  open   syslog-100.105-2022.04.13           8sm8Asb1RSyZZQvVSvsjhw   1   1         42            0     90.8kb         57.9kb

kibana查看日志

3、nginx日志收集

3.1 配置nginx json格式日志

root@logstash-node1:/apps/nginx# vim conf/nginx.conflog_format access_json '{"@timestamp":"$time_iso8601",''"host":"$server_addr",''"clientip":"$remote_addr",''"size":$body_bytes_sent,''"responsetime":$request_time,''"upstreamtime":"$upstream_response_time",''"upstreamhost":"$upstream_addr",''"http_host":"$host",''"url":"$uri",''"domain":"$host",''"xff":"$http_x_forwarded_for",''"referer":"$http_referer",''"status":"$status"}';access_log /apps/nginx/logs/access.log access_json;
#添加权限
root@logstash-node1:/apps/nginx# chmod o+r /apps/nginx/logs/access.log

3.2 配置logstash

root@logstash-node1:~# vim /etc/logstash/conf.d/nginx-access.log input {file {path => "/apps/nginx/logs/access.log"start_position => "beginning"stat_interval => "3"type => "nginx-access-log"codec => json}
}
output {if [type] == "nginx-access-log" {elasticsearch {hosts => ["10.10.100.120:9200"]index => "nginx-accesslog-100.105-%{+YYYY.MM.dd}"}}
}#重启logstash
root@logstash-node1:~# systemctl restart logstash

3.3 验证查看

4、java 日志搜集

使用 codec 的 multiline 插件实现多行匹配,这是一个可以将多行进行合并的插件,而且可以使用 what 指定将匹配到的行与前面的行合并还是和后面的行合并,
https://www.elastic.co/guide/en/logstash/current/plugins-codecs-multiline.html

4.1 配置logstash

root@logstash-node1:~# vim /etc/logstash/conf.d/java_log.conf
input {file {path = "/tmp/java.log"type = "java-log"start_position => "beginning"stat_interval => "3"codec => multiline {#匹配年月日开头行时进行多行合并pattern => "^([0-9]{4}-[0-9]{2}-[0-9]{2}"#true 为匹配成功进行操作,false 为不成功进行操作negate => true#与之前的行合并,如果是下面的行合并就是 nextwhat =>"previous"}}
}
output {if [type] == "syslog" {elasticsearch {hosts => ["10.10.100.120:9200"]index => "javalog-100.105-%{+YYYY.MM.dd}"}}
}

4.2 kibana 查看日志

logstash 日志收集相关推荐

  1. logstash日志收集走过的坑

    问题1:OOM内存溢出 背景介绍,通常对logstash的应用,是logstash日志收集日志然后写入到kafka,因为logstash本身是插件化,所以就会应用到kafka-output-plugi ...

  2. Logstash日志收集实践

    一.安装logstach [root@linux-node2 ~]# tar xf /usr/local/src/logstash-5.2.2.tar.gz -C /usr/local/ [root@ ...

  3. SpringBoot继承LogStash实现日志收集

    一.环境准备 安装Elasticsearch.kibana.logstash,教程链接 安装教程 二.配置SpringBoot 依赖 在springBoot 项目下pom文件增加logStash 依赖 ...

  4. 性能优越的轻量级日志收集工具,微软、亚马逊都在用!

    ELK日志收集系统大家都知道,但是还有一种日志收集系统EFK,肯定有很多朋友不知道!这里的F指的是Fluentd,它具有Logstash类似的日志收集功能,但是内存占用连Logstash的十分之一都不 ...

  5. 项目实战|史上最简单的springboot 整合elk教程,实现日志收集(带视频哦)

    配套视频教程已经上传 整合ELK-实现日志收集(知乎) 整合ELK-实现日志收集(CSDN) 项目源码已上传至 https://gitee.com/yangleliu/learning.git,免费索 ...

  6. ELK 日志收集系统方案

    文章目录 背景 ELK使用组件简介 方案1 ELK 方案二 EFK 方案三: FELK 方案四:个性化框架 总结: 日志展示及查询 环境 背景 在项目初期的时候,大家都是赶着上线,一般来说对日志没有过 ...

  7. ELK分布式日志收集搭建和使用

    大型系统分布式日志采集系统ELK 全框架 SpringBootSecurity 1.传统系统日志收集的问题 2.Logstash操作工作原理 3.分布式日志收集ELK原理 4.Elasticsearc ...

  8. Logback+ELK+SpringBoot搭建日志收集服务器

    前言 本文重点介绍Logback和ELK和SpringBoot是怎么整合收集日志的 关于ELK的说明和安装可以点击查看ELK(Elasticsearch.Logstash.Kibana)安装, htt ...

  9. 微服务架构-链路追踪、日志收集篇

    一.链路追踪 1.涉及的插件elasticsearch7.0.0.skywalking-oap-server:8.9.1.skywalking-ui:8.9.1.skywalking-agent 8. ...

  10. ELKstack日志收集系统

    简介   ELKstack是由Elasticsearch.Logstash.Kibana三个开源软件组合而成的一款集分析.搜索.图形展示于一身的实施日志收集系统. 各个组件的功能如下: Elastic ...

最新文章

  1. Mat对象与它各种用法
  2. Linux系统vi操作指南
  3. spring boot 1.5.4 之监控Actuator(十四)
  4. 密码学研究-密钥长度限制
  5. 智源“高能对撞粒子分类挑战赛”开启,品鉴宇宙粒子的独特“味道”
  6. 胃部不适,原来好辛苦!
  7. 中国移动5G商用首批开放50城 明年扩展至全国地级以上城市
  8. python面向对象的特征_03 Python 关键点讲解:面向对象的机制
  9. 修改Typora的快捷键【markdown软件】
  10. 产品研发过程管理专题——编写软件测试计划需要考虑的几个问题
  11. 小米与泰尔实验室联合发布《多模态技术白皮书》
  12. 微信小程序长按识别二维码
  13. 【每日学习3.31】 筹备腾讯三面 - 阿V
  14. window10安装kubectl工具及配置config信息
  15. Windows/Linux混合刻录之后,光盘文件不见了?
  16. SPI总线通信——基于STM32MP157A
  17. 《匆匆那年》的你,还记得吗?数学中的那些有(hui)趣(se)的定理(5)——鸡爪定理
  18. App上架应用市场操作流程
  19. 1+1为什么等于2(哥德巴赫猜想)
  20. 看史上最牛的夫妻生活协议书

热门文章

  1. NTP时间服务器安装配置详解
  2. 徐耀赐教授系列讲座——车道宽度理论在城市道路路网中的应用(编译文本)...
  3. 吴恩达机器学习正则化线性回归和偏差算法的MATLAB实现(对应ex5练习)
  4. C语言--指针实现字符串逆序输出
  5. PSnbsp;08人物抠图
  6. matlab 求obb,obb包围盒代码
  7. 通过串口波特率计算数据传输速率(每秒字节数)
  8. snort 错误 (CentOS 8)
  9. 微弱光信号检测MATLAB,基于数字锁相放大器的微弱光电信号检测研究
  10. 基于单片机的红外检测及语音响应系统