如何快速定位到报错日志中的关键信息,一招学会,赶快GET吧

news2024/11/27 0:15:14

一般的服务器日志一个可能大的有几十上百m,小的也得几百k,里面内容是比较多的,如拿到日志没思路去看的话,下面一些办法可以让你快速定位到日志中的异常错误信息

文章目录

    • 步骤1:定位到错误信息再那个日志中(grep)
    • 步骤2:查看日志上下文信息
      • 查看上下多少x行信息(cat指令)
      • 查看关键字下多少x行信息(cat指令)
      • 直接进入日志用关键字定位(less指令)
      • 直接进入日志用关键字定位(vim指令-但是不太推荐)
    • 特殊情况(日志被打成tar包了。。。)

下面的这块日志可以作为练习参考

g_2.11-3.9.0.jar:/export/server/kafka/bin/../libs/scala-reflect-2.11.12.jar:/export/server/kafka/bin/../libs/slf4j-api-1.7.25.jar:/export/server/kafka/bin/../libs/slf4j-log4j12-1.7.25.jar:/export/server/kafka/bin/../libs/snappy-java-1.1.7.2.jar:/export/server/kafka/bin/../libs/validation-api-1.1.0.Final.jar:/export/server/kafka/bin/../libs/zkclient-0.10.jar:/export/server/kafka/bin/../libs/zookeeper-3.4.13.jar:/export/server/kafka/bin/../libs/zstd-jni-1.3.5-4.jar (org.apache.zookeeper.ZooKeeper)
[2022-11-15 20:46:32,836] INFO Client environment:java.library.path=/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib (org.apache.zookeeper.ZooKeeper)
[2022-11-15 20:46:32,836] INFO Client environment:java.io.tmpdir=/tmp (org.apache.zookeeper.ZooKeeper)
[2022-11-15 20:46:32,836] INFO Client environment:java.compiler=<NA> (org.apache.zookeeper.ZooKeeper)
[2022-11-15 20:46:32,836] INFO Client environment:os.name=Linux (org.apache.zookeeper.ZooKeeper)
[2022-11-15 20:46:32,836] INFO Client environment:os.arch=amd64 (org.apache.zookeeper.ZooKeeper)
[2022-11-15 20:46:32,836] INFO Client environment:os.version=3.10.0-1160.76.1.el7.x86_64 (org.apache.zookeeper.ZooKeeper)
[2022-11-15 20:46:32,837] INFO Client environment:user.name=root (org.apache.zookeeper.ZooKeeper)
[2022-11-15 20:46:32,837] INFO Client environment:user.home=/root (org.apache.zookeeper.ZooKeeper)
[2022-11-15 20:46:32,837] INFO Client environment:user.dir=/root (org.apache.zookeeper.ZooKeeper)
[2022-11-15 20:46:32,839] INFO Initiating client connection, connectString=master:2181,slave1:2181,slave2:2181 sessionTimeout=6000 watcher=kafka.zookeeper.ZooKeeperClient$ZooKeeperClientWatcher$@77fbd92c (org.apache.zookeeper.ZooKeeper)
[2022-11-15 20:46:32,946] INFO Opening socket connection to server slave2/192.168.241.23:2181. Will not attempt to authenticate using SASL (unknown error) (org.apache.zookeeper.ClientCnxn)
[2022-11-15 20:46:32,949] INFO [ZooKeeperClient] Waiting until connected. (kafka.zookeeper.ZooKeeperClient)
[2022-11-15 20:46:32,970] INFO Socket error occurred: slave2/192.168.241.23:2181: 拒绝连接 (org.apache.zookeeper.ClientCnxn)
[2022-11-15 20:46:33,073] INFO Opening socket connection to server slave1/192.168.241.22:2181. Will not attempt to authenticate using SASL (unknown error) (org.apache.zookeeper.ClientCnxn)
[2022-11-15 20:46:33,074] INFO Socket error occurred: slave1/192.168.241.22:2181: 拒绝连接 (org.apache.zookeeper.ClientCnxn)
[2022-11-15 20:46:33,174] INFO Opening socket connection to server master/192.168.241.21:2181. Will not attempt to authenticate using SASL (unknown error) (org.apache.zookeeper.ClientCnxn)
[2022-11-15 20:46:33,175] INFO Socket connection established to master/192.168.241.21:2181, initiating session (org.apache.zookeeper.ClientCnxn)
[2022-11-15 20:46:33,182] INFO Unable to read additional data from server sessionid 0x0, likely server has closed socket, closing socket connection and attempting reconnect (org.apache.zookeeper.ClientCnxn)
[2022-11-15 20:46:34,747] INFO Opening socket connection to server slave2/192.168.241.23:2181. Will not attempt to authenticate using SASL (unknown error) (org.apache.zookeeper.ClientCnxn)
[2022-11-15 20:46:34,748] INFO Socket error occurred: slave2/192.168.241.23:2181: 拒绝连接 (org.apache.zookeeper.ClientCnxn)
[2022-11-15 20:46:35,820] INFO Opening socket connection to server slave1/192.168.241.22:2181. Will not attempt to authenticate using SASL (unknown error) (org.apache.zookeeper.ClientCnxn)
[2022-11-15 20:46:35,821] INFO Socket error occurred: slave1/192.168.241.22:2181: 拒绝连接 (org.apache.zookeeper.ClientCnxn)
[2022-11-15 20:46:36,209] INFO Opening socket connection to server master/192.168.241.21:2181. Will not attempt to authenticate using SASL (unknown error) (org.apache.zookeeper.ClientCnxn)
[2022-11-15 20:46:36,209] INFO Socket connection established to master/192.168.241.21:2181, initiating session (org.apache.zookeeper.ClientCnxn)
[2022-11-15 20:46:36,210] INFO Unable to read additional data from server sessionid 0x0, likely server has closed socket, closing socket connection and attempting reconnect (org.apache.zookeeper.ClientCnxn)
[2022-11-15 20:46:37,505] INFO Opening socket connection to server slave2/192.168.241.23:2181. Will not attempt to authenticate using SASL (unknown error) (org.apache.zookeeper.ClientCnxn)
[2022-11-15 20:46:37,510] INFO Socket error occurred: slave2/192.168.241.23:2181: 拒绝连接 (org.apache.zookeeper.ClientCnxn)
[2022-11-15 20:46:38,515] INFO Opening socket connection to server slave1/192.168.241.22:2181. Will not attempt to authenticate using SASL (unknown error) (org.apache.zookeeper.ClientCnxn)
[2022-11-15 20:46:38,515] INFO Socket error occurred: slave1/192.168.241.22:2181: 拒绝连接 (org.apache.zookeeper.ClientCnxn)
[2022-11-15 20:46:38,951] INFO [ZooKeeperClient] Closing. (kafka.zookeeper.ZooKeeperClient)
[2022-11-15 20:46:39,623] INFO Session: 0x0 closed (org.apache.zookeeper.ZooKeeper)
[2022-11-15 20:46:39,624] INFO EventThread shut down for session: 0x0 (org.apache.zookeeper.ClientCnxn)
[2022-11-15 20:46:39,627] INFO [ZooKeeperClient] Closed. (kafka.zookeeper.ZooKeeperClient)
[2022-11-15 20:46:39,629] ERROR Fatal error during KafkaServer startup. Prepare to shutdown (kafka.server.KafkaServer)
kafka.zookeeper.ZooKeeperClientTimeoutException: Timed out waiting for connection while in state: CONNECTING
        at kafka.zookeeper.ZooKeeperClient$$anonfun$kafka$zookeeper$ZooKeeperClient$$waitUntilConnected$1.apply$mcV$sp(ZooKeeperClient.scala:268)
        at kafka.zookeeper.ZooKeeperClient$$anonfun$kafka$zookeeper$ZooKeeperClient$$waitUntilConnected$1.apply(ZooKeeperClient.scala:264)
        at kafka.zookeeper.ZooKeeperClient$$anonfun$kafka$zookeeper$ZooKeeperClient$$waitUntilConnected$1.apply(ZooKeeperClient.scala:264)
        at kafka.utils.CoreUtils$.inLock(CoreUtils.scala:251)
        at kafka.zookeeper.ZooKeeperClient.kafka$zookeeper$ZooKeeperClient$$waitUntilConnected(ZooKeeperClient.scala:264)
        at kafka.zookeeper.ZooKeeperClient.<init>(ZooKeeperClient.scala:97)
        at kafka.zk.KafkaZkClient$.apply(KafkaZkClient.scala:1693)
        at kafka.server.KafkaServer.kafka$server$KafkaServer$$createZkClient$1(KafkaServer.scala:348)
        at kafka.server.KafkaServer.initZkClient(KafkaServer.scala:372)
        at kafka.server.KafkaServer.startup(KafkaServer.scala:202)
        at kafka.server.KafkaServerStartable.startup(KafkaServerStartable.scala:38)
        at kafka.Kafka$.main(Kafka.scala:75)
        at kafka.Kafka.main(Kafka.scala)
[2022-11-15 20:46:39,633] INFO shutting down (kafka.server.KafkaServer)
[2022-11-15 20:46:39,636] INFO shut down completed (kafka.server.KafkaServer)
[2022-11-15 20:46:39,638] ERROR Exiting Kafka. (kafka.server.KafkaServerStartable)
[2022-11-15 20:46:39,647] INFO shutting down (kafka.server.KafkaServer)
(END)

步骤1:定位到错误信息再那个日志中(grep)

当天日志可能比较多,被切分成很多个小日志
如下图
在这里插入图片描述
如果出现这种情况,我们可以使用这种办法来定位错误信息再那个日志中
比如我们有相关的关键字可以直接用,用关键字匹配日志
grep -ri "关键字" 所以查询的日志(可以使用*进行匹配)

[root@master logs]# grep -ri "ERROR Fatal" server.log.2022-11-14-21*
server.log.2022-11-14-21:[2022-11-15 20:46:39,629] ERROR Fatal error during KafkaServer startup. Prepare to shutdown (kafka.server.KafkaServer)
server.log.2022-11-14-21-1:[2022-11-15 20:46:39,629] ERROR Fatal error during KafkaServer startup. Prepare to shutdown (kafka.server.KafkaServer)

从上面我们可以直接定位到错误信息在server.log.2022-11-14-21和server.log.2022-11-14-21-1都有

步骤2:查看日志上下文信息

查看上下多少x行信息(cat指令)

查看指定文件中关键词上下5行的信息cat xxx |grep -C 5 "关键信息"

[root@master logs]# cat server.log.2022-11-14-21 |grep -C 5 "ERROR Fatal"
[2022-11-15 20:46:38,515] INFO Socket error occurred: slave1/192.168.241.22:2181: 拒绝连接 (org.apache.zookeeper.ClientCnxn)
[2022-11-15 20:46:38,951] INFO [ZooKeeperClient] Closing. (kafka.zookeeper.ZooKeeperClient)
[2022-11-15 20:46:39,623] INFO Session: 0x0 closed (org.apache.zookeeper.ZooKeeper)
[2022-11-15 20:46:39,624] INFO EventThread shut down for session: 0x0 (org.apache.zookeeper.ClientCnxn)
[2022-11-15 20:46:39,627] INFO [ZooKeeperClient] Closed. (kafka.zookeeper.ZooKeeperClient)
[2022-11-15 20:46:39,629] ERROR Fatal error during KafkaServer startup. Prepare to shutdown (kafka.server.KafkaServer)
kafka.zookeeper.ZooKeeperClientTimeoutException: Timed out waiting for connection while in state: CONNECTING
        at kafka.zookeeper.ZooKeeperClient$$anonfun$kafka$zookeeper$ZooKeeperClient$$waitUntilConnected$1.apply$mcV$sp(ZooKeeperClient.scala:268)
        at kafka.zookeeper.ZooKeeperClient$$anonfun$kafka$zookeeper$ZooKeeperClient$$waitUntilConnected$1.apply(ZooKeeperClient.scala:264)
        at kafka.zookeeper.ZooKeeperClient$$anonfun$kafka$zookeeper$ZooKeeperClient$$waitUntilConnected$1.apply(ZooKeeperClient.scala:264)
        at kafka.utils.CoreUtils$.inLock(CoreUtils.scala:251)
[root@master logs]#


如图示效果
在这里插入图片描述

查看关键字下多少x行信息(cat指令)

查看指定文件中关键词往下10行的信息cat xxx |grep -A 10 "关键信息"

[root@master logs]# cat server.log.2022-11-14-21 |grep -A 10  "ERROR Fatal"
[2022-11-15 20:46:39,629] ERROR Fatal error during KafkaServer startup. Prepare to shutdown (kafka.server.KafkaServer)
kafka.zookeeper.ZooKeeperClientTimeoutException: Timed out waiting for connection while in state: CONNECTING
        at kafka.zookeeper.ZooKeeperClient$$anonfun$kafka$zookeeper$ZooKeeperClient$$waitUntilConnected$1.apply$mcV$sp(ZooKeeperClient.scala:268)
        at kafka.zookeeper.ZooKeeperClient$$anonfun$kafka$zookeeper$ZooKeeperClient$$waitUntilConnected$1.apply(ZooKeeperClient.scala:264)
        at kafka.zookeeper.ZooKeeperClient$$anonfun$kafka$zookeeper$ZooKeeperClient$$waitUntilConnected$1.apply(ZooKeeperClient.scala:264)
        at kafka.utils.CoreUtils$.inLock(CoreUtils.scala:251)
        at kafka.zookeeper.ZooKeeperClient.kafka$zookeeper$ZooKeeperClient$$waitUntilConnected(ZooKeeperClient.scala:264)
        at kafka.zookeeper.ZooKeeperClient.<init>(ZooKeeperClient.scala:97)
        at kafka.zk.KafkaZkClient$.apply(KafkaZkClient.scala:1693)
        at kafka.server.KafkaServer.kafka$server$KafkaServer$$createZkClient$1(KafkaServer.scala:348)
        at kafka.server.KafkaServer.initZkClient(KafkaServer.scala:372)
[root@master logs]#

效果如图所示
在这里插入图片描述

直接进入日志用关键字定位(less指令)

less xxx.log

[root@master logs]# less server.log.2022-11-14-21

进入日志后敲一下/ + 关键字,之后按一下回车
具体看图操作
在这里插入图片描述
回车之后就定位到关键词的地方了,如果还有其他相同的关键字日志继续/ + 方向键↑就能快速把刚才的关键字打出来了,完了在敲回车
在这里插入图片描述

直接进入日志用关键字定位(vim指令-但是不太推荐)

同less指令的后续操作
直接vim进去或者vi进去,不太建议使用是有时候shell连接在你正在vi或者vim的时候断掉之后会产生一部分快照文件,如果下一次连到服务器的时候需要把快照文件删除掉才能继续编辑

特殊情况(日志被打成tar包了。。。)

如果日志比较大了,而且是前n天的,比如说是10天前,有可能会被压缩tar包(具体看你们公司相关配置),这个时候使用可以解压文件之后再查看,但是如果权限不够,不允许解压,就需要另求他法了
查看tar包中的日志内容:zcat xxx.tar.gz | egrep -a "关键字"


[root@master logs]# zcat test.tar.gz |egrep -a "ERROR Fatal"
[2022-11-15 20:46:39,629] ERROR Fatal error during KafkaServer startup. Prepare to shutdown (kafka.server.KafkaServer)

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/48062.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

[附源码]计算机毕业设计springboot教育企业网站

项目运行 环境配置&#xff1a; Jdk1.8 Tomcat7.0 Mysql HBuilderX&#xff08;Webstorm也行&#xff09; Eclispe&#xff08;IntelliJ IDEA,Eclispe,MyEclispe,Sts都支持&#xff09;。 项目技术&#xff1a; SSM mybatis Maven Vue 等等组成&#xff0c;B/S模式 M…

鲲鹏devkit性能分析工具介绍(三)

鲲鹏devkit性能分析工具介绍&#xff08;三&#xff09; 本篇主要讲解鲲鹏devkit性能分析工具的访存分析功能 访存分析 访存统计分析基于CPU访问缓存和内存的PMU事件&#xff0c;分析存储的访问次数、命中率、带宽等情况。 Miss事件分析基于ARM SPE&#xff08;Statistical…

固话号码认证有什么好处?固话号码认证有什么作用?

固话号码认证为企业提供号码认证服务&#xff0c;在来电时显示企业信息&#xff0c;可提高电话号码辨识度&#xff0c;防止错误标记&#xff0c;确保展现的企业信息与企业的手机终端、APP等多平台展示信息一致&#xff0c;保证品牌企业的身份及商业价值。 那如何上线号码认证服…

图的初识·基本概念

文章目录基本概念图有两种基本形式无向图的表示有向图的表示基本概念 图结构也是数据结构的一部分。而且还有一点小难。图是由多个结点链接而成的&#xff0c;但是一个结点可以同时连接多个其他结点&#xff0c;多个节点也可以同时指向一个节点。【多对多的关系】 图结构是任意…

iPhone升级iOS 16后出现提示“面容ID不可用”怎么办?

最近&#xff0c;很多用户在苹果社区反馈&#xff0c;iPhone升级iOS 16后Face ID不能用了&#xff0c;尝试重置Face ID时&#xff0c;系统会弹窗提示“面容ID不可用&#xff0c;稍后尝试设置面容ID。” 如果你的iPhone在没有摔落手机或是手机进水的情况下出现这个弹窗&#xff…

电脑游戏录屏哪个好用免费?这2款录屏软件,用过都说好!

​相信很多小伙伴都有过在游戏中的精彩操作吧。有些小伙伴想要把自己在游戏中的精彩操作分享给朋友&#xff0c;可是却不知道有什么好用免费的游戏录屏软件&#xff0c;能够将自己游戏里的亮眼表现录制下来。那么电脑游戏录屏哪个好用免费&#xff1f;接下来小编分享2款永久免费…

PyQt5 窗口数据传递

PyQt5 窗口数据传递单一窗口数据传递多窗口数据传递&#xff1a;调用属性多窗口数据传递&#xff1a;信号与槽开发应用程序时&#xff0c;若只有一个窗口则只需关心这个窗口里面的各控件之间如何传递数据。如果程序有多个窗口&#xff0c;就要关心不同的窗口之间是如何传递数据…

History、Location

History、Location 学习路线&#xff1a;JavaScript_BOM->Window对象->confirm()、setInterval()、setTimeout()->History、Location->闪烁的灯泡 History History 对象是 JavaScript 对历史记录进行封装的对象。 History 对象的获取 使用 window.history获取&a…

云小课|云小课教您如何选择Redis实例类型

阅识风云是华为云信息大咖&#xff0c;擅长将复杂信息多元化呈现&#xff0c;其出品的一张图(云图说)、深入浅出的博文(云小课)或短视频(云视厅)总有一款能让您快速上手华为云。更多精彩内容请单击此处。 摘要&#xff1a;购买Redis实例时&#xff0c;实例类型有单机、主备、Pr…

vmware安装openEuler20.03

一&#xff0c;直接看图。 点击创建虚拟机。 这里如果是21.03版本的话&#xff0c;版本需要选择Linux5.x内核64位。 20.03选择Linux4.x的内核。 2个或者4个都行。 内存不要小于4G。 官方推荐不要小于32G。 直接下一步即可。 然后等待&#xff0c;进入配置。 安…

数据结构学习:Trie树

Trie一、概念二、代码实现三、Tire树的时间复杂度和空间复杂度四、Tire树的优势一、概念 Trie树,也叫"字典树",顾名思义,是一种专门处理字符串匹配的树形结构,用来解决在一组字符串集合中快速找到某个字符串类似于这种字符串匹配问题,可以使用RF暴力匹配、RK哈希匹配…

RabbitMQ 快速入门七种简单模式

RabbitMQ 快速入门七种简单模式起步七种模式项目依赖1、"Hello World!"(1) Connection 方式(2) RabbitTemplate 方式2、Work Queues生产者消费者3、Publish/Subscribe关系绑定生产者消费者4、Routing消费者生产者5. Topics消费者生产者6、RPC7、Publisher Confirms起…

面试又卡在多线程?那就来分享几道 Java 多线程高频面试题,面试不用愁

多线程中的忙循环是什么?忙循环就是程序员用循环让一个线程等待&#xff0c;不像传统方法 wait()、 sleep() 或 yield()&#xff0c;它们都放弃了 CPU 控制&#xff0c;而忙循环不会放弃 CPU&#xff0c;它就是在运行一个空循环。 这么做的目的是为了保留 CPU 缓存&#xff0c…

用于大规模 MIMO 检测的近似消息传递 (AMP)(Matlab代码实现)

&#x1f468;‍&#x1f393;个人主页&#xff1a;研学社的博客 &#x1f4a5;&#x1f4a5;&#x1f49e;&#x1f49e;欢迎来到本博客❤️❤️&#x1f4a5;&#x1f4a5; &#x1f3c6;博主优势&#xff1a;&#x1f31e;&#x1f31e;&#x1f31e;博客内容尽量做到思维缜…

【二开】mattermos扩展第三方登录

目录 前景提要明确目标开始动手部署开发环境找到项目入口梳理登录流程修改请求地址前景提要 公司准备使用mattermost,项目进行任务管理,我们需要让已有系统能够对接该系统的登录。 明确目标 前端webApp项目独立部署使用第三方Token可以通过使用第三方Token登录mattermost平…

因子模型:套利定价理论APT

本文是Quantitative Methods and Analysis: Pairs Trading此书的读书笔记。 因子模型(factor models)用来解释资产的风险或者回报的特点。在CAPM模型中&#xff0c;资产的回报几乎就是由市场决定的&#xff0c;每个资产对市场的敏感程度可以用beta来描述。因而&#xff0c;在C…

RabbitMQ系列【18】对象序列化机制

有道无术&#xff0c;术尚可求&#xff0c;有术无道&#xff0c;止于术。 文章目录前言发送对象接收对象使用Jackson 序列化前言 使用RabbitMQ原生API&#xff0c;发送消息时&#xff0c;发送的是二进制byte[]数据。 void basicPublish(String var1, String var2, byte[] var4…

1.2 监督学习

1.2 监督学习监督学习的定义监督学习的相关概念监督学习流程图监督学习的定义 监督学习(Supervised Learning&#xff09;是指从标注数据中学习预测模型的机器学习问题&#xff0c;其本质是学习输入到输出的映射的统计规律。 输入空间 (Input Space&#xff09;&#xff1a;输…

11.29总结

目录 一.连续子数组最大和 方法2动态规划 二.查找最小的k对数字 一.从先序遍历还原二叉树 二.完全二叉树 三.判断对称二叉树 四 回文 五.连续子数组最大和 六.TopK问题 思路一如果数据特别大.排序的时间复杂度会很大 思路二:用大根堆或者小根堆然后分别弹出. 思路三…

CANoe-vTESTstudio之State Diagram编辑器(功能介绍)

1. 阶段 State Diagram从测试设计到测试执行,分为4个阶段: Test Design 在测试设计期间,测试设计人员使用图形元素和分配的测试代码来对要测试的SUT的状态和转换进行建模。这个阶段的结果是生成状态图 Evaluation 在评估期间,将验证各个元素及其关系并创建路径。评估产…