溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

docker日志出現(xiàn)無法檢索問題如何解決

發(fā)布時(shí)間:2022-05-31 14:21:27 來源:億速云 閱讀:341 作者:iii 欄目:大數(shù)據(jù)

這篇“docker日志出現(xiàn)無法檢索問題如何解決”文章的知識(shí)點(diǎn)大部分人都不太理解,所以小編給大家總結(jié)了以下內(nèi)容,內(nèi)容詳細(xì),步驟清晰,具有一定的借鑒價(jià)值,希望大家閱讀完這篇文章能有所收獲,下面我們一起來看看這篇“docker日志出現(xiàn)無法檢索問題如何解決”文章吧。

日常檢查服務(wù)的時(shí)候,從portainer那里進(jìn)去看容器日志的時(shí)候,發(fā)現(xiàn)右上角出現(xiàn)紅色的感嘆號(hào):unable to retrieve container logs。

因?yàn)橹皼]出現(xiàn)過這樣的問題,所以就先上服務(wù)器上用命令docker logs -f containerid看日志,發(fā)現(xiàn)日志也是動(dòng)不了,還是停留在某個(gè)時(shí)間的日志記錄上。

想了一下不應(yīng)該是服務(wù)的日志打印出問題,先照著google搜索了一遍,發(fā)現(xiàn)都沒有跟我的問題相匹配的。因?yàn)槿罩居袝r(shí)能收集顯示,有些日志不可以,應(yīng)該是跟docker設(shè)置的日志引擎有問題。

本來是想整一套efk的,但是感覺現(xiàn)在日志量還不夠大,所以并沒有修改docker的日志引擎,還是默認(rèn)的journald

[root@ad-official xiaoxiao]# docker info|grep logging
 warning: you're not using the default seccomp profile
logging driver: journald

journald的官方文檔上有這么一個(gè)說明:

man journald.conf ... ratelimitinterval=, ratelimitburst= configures the rate limiting that is applied to all messages generated on the system. if, in the time interval defined by ratelimitinterval=, more messages than specified in ratelimitburst= are logged by a service, all further messages within the interval are dropped until the interval is over. a message about the number of dropped messages is generated. this rate limiting is applied per-service, so that two services which log do not interfere with each other's limits. defaults to 1000 messages in 30s. the time specification for ratelimitinterval= may be specified in the following units: "s", "min", "h", "ms", "us". to turn off any kind of rate limiting, set either value to 0. ...

這里寫了默認(rèn)30秒內(nèi)只能接收1000條日志,看到這里就能明白了,因?yàn)榍瓣囎觿傇赿ocker發(fā)布了一個(gè)單日日志文件大小差不多達(dá)到3g的服務(wù),導(dǎo)致到了其他服務(wù)的日志也受到了影響,大量的日志被journald丟棄,所以我們修改一下配置就沒有問題了。

打開/etc/systemd/journald.conf文件,將ratelimitburst從默認(rèn)的1000修改成5000,根據(jù)自己目前的日志輸出量進(jìn)行調(diào)整:

[root@ad-official log]# cat /etc/systemd/journald.conf
# this file is part of systemd.
#
# systemd is free software; you can redistribute it and/or modify it
# under the terms of the gnu lesser general public license as published by
# the free software foundation; either version 2.1 of the license, or
# (at your option) any later version.
#
# entries in this file show the compile time defaults.
# you can change settings by editing this file.
# defaults can be restored by simply deleting this file.
#
# see journald.conf(5) for details.

[journal]
#storage=auto
#compress=yes
#seal=yes
#splitmode=uid
#syncintervalsec=5m
#ratelimitinterval=30s
ratelimitburst=5000
#systemmaxuse=
#systemkeepfree=
#systemmaxfilesize=
#runtimemaxuse=
#runtimekeepfree=
#runtimemaxfilesize=
#maxretentionsec=
#maxfilesec=1month
forwardtosyslog=no
#forwardtokmsg=no
#forwardtoconsole=no
forwardtowall=no
#ttypath=/dev/console
#maxlevelstore=debug
#maxlevelsyslog=debug
#maxlevelkmsg=notice
#maxlevelconsole=info
#maxlevelwall=emerg
#linemax=48k

順便將forwardtosyslog和forwardtowall設(shè)置成no,因?yàn)槟J(rèn)是yes,會(huì)導(dǎo)致我們清理了journal的日志文件,而syslog中的沒有清除掉,慢慢的就會(huì)將磁盤占滿。

然后重啟一下journald就可以恢復(fù)正常使用啦:systemctl restart systemd-journald.service

以上就是關(guān)于“docker日志出現(xiàn)無法檢索問題如何解決”這篇文章的內(nèi)容,相信大家都有了一定的了解,希望小編分享的內(nèi)容對(duì)大家有幫助,若想了解更多相關(guān)的知識(shí)內(nèi)容,請(qǐng)關(guān)注億速云行業(yè)資訊頻道。

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI