您现在的位置是:首页 > 正文

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

2024-02-01 04:24:36阅读 1

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

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

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)

网站文章

  • 母函数及其应用

    母函数,又称生成函数,是ACM竞赛中经常使用的一种解题算法,常用来解决组合方面的题目。 使用母函数解决问题的方法称为母函数方法。 1.母函数的原理 对于序列C0、C1、C2、…、Cn,构造函数G(x)...

    2024-02-01 04:24:01
  • c语言中int的取值范围是怎么算出来的,int的取值范围怎么算

    大家好,我是时间财富网智能客服时间君,上述问题将由我为大家进行解答。int的意思是基本整型,计算取值范围:1、当字节数为2时,取值范围为-32768到32767。2、当字节数为4时,取值范围为负的2的...

    2024-02-01 04:23:54
  • 计算机共享访问权限 xp,上面就是xp访问win7共享要密码的解决方法

    计算机共享访问权限 xp,上面就是xp访问win7共享要密码的解决方法

    系统之家WinXP系统访问win7共享要密码的解决方法。不知道大家有没有发现,有时候我们用xp访问win7共享要密码!这个问题有点大啊,有些朋友为了保险起见,特地将密码设置得很复杂,每次访问都要输入的...

    2024-02-01 04:23:25
  • MYSQL json数组创建多值索引

    MYSQL json数组创建多值索引

    MYSQL json数组创建多值索引有感 ##函数索引 ##多值索引

    2024-02-01 04:23:18
  • VMware日志收集方法总结

    VMware日志收集方法总结

    https://www.kclouder.cn/vmware-log-collection/ VM VMware的产品线很多,非常庞大,每种产品都有Diagnostic Information的收集方...

    2024-02-01 04:23:10
  • 安兔兔上html5是什么意思,除了安兔兔跑分,还有这6种办法能证明手机强弱

    安兔兔上html5是什么意思,除了安兔兔跑分,还有这6种办法能证明手机强弱

    现在说起手机跑分,已经稀松平常,但早在五年前,很多手机用户根本不知道如何测试手机性能。“跑分”这个词汇只会出现在媒体的评测文章里。后来,雷布斯捧着小米1代杀到了手机行业,第一句话就是“跑个分呗”,于是...

    2024-02-01 04:22:40
  • 实验15:20211127 Java大数据1+X 中级实操考试(id:2660)

    实验15:20211127 Java大数据1+X 中级实操考试(id:2660)

    【5 分】步骤 1:项目准备【5 分】步骤 2:完成实体类 Student【10 分】步骤 3:完成实体类 Course【10 分】步骤 4:完成实体类 Score【10 分】步骤 5:完成 Stud...

    2024-02-01 04:22:34
  • pytorch里的nn.Embedding是什么东西?

    pytorch里的nn.Embedding是什么东西?

    2024-02-01 04:22:18
  • [NepCTF2022] 复现

    [NepCTF2022] 复现

    www.zip源码泄露,啥也不懂没注意正确的入口在哪里,一直把注意力放在web.php上面。附件下载后是个osz后缀,当时用010看是压缩包文件头,就改后缀了。当时写的过程,确实9.12.2的版本也是...

    2024-02-01 04:22:11
  • aes key长度_AES 自动打分 Automated Essay Scoring

    aes key长度_AES 自动打分 Automated Essay Scoring

    文章自动打分简称 AES (Automated Essay Scoring),AES 系统利用 NLP 技术自动对文章进行打分,可以减轻阅卷人员的负担。目前有不少大型的考试都采用了 AES 算法进行作...

    2024-02-01 04:21:42