对于k8s中的服务器,由于k8s的日志量太多,容易引发服务器硬盘空间不足造成服务不能使用,从而配置定时清理日志尤为重要:

  1. 优化journal日志
    vim /etc/systemd/journald.conf
    [Journal]
    #Storage=auto
    #Compress=yes
    #Seal=yes
    #SplitMode=uid
    SyncIntervalSec=7day
    #RateLimitIntervalSec=30s
    #RateLimitBurst=10000
    SystemMaxUse=1G
    #SystemKeepFree=
    #SystemMaxFileSize=
    #SystemMaxFiles=100
    #RuntimeMaxUse=
    #RuntimeKeepFree=
    #RuntimeMaxFileSize=
    #RuntimeMaxFiles=100
    #MaxRetentionSec=
    #MaxFileSec=1month
    #ForwardToSyslog=yes
    #ForwardToKMsg=no
    #ForwardToConsole=no
    #ForwardToWall=yes
    #TTYPath=/dev/console
    #MaxLevelStore=debug
    #MaxLevelSyslog=debug
    #MaxLevelKMsg=notice
    #MaxLevelConsole=info
    #MaxLevelWall=emerg
    #LineMax=48K
    #ReadKMsg=yes
    systemctl restart systemd-journald
  2. 优化docker日志配置,限制日志文件大小
    vim /etc/docker/daemon.json
    {
    “registry-mirrors”: [“https://b9pmyelo.mirror.aliyuncs.com”],
    “exec-opts”: [“native.cgroupdriver=systemd”],
    “log-driver”:“json-file”,
    “log-opts”: {“max-size”:“500m”, “max-file”:“3”}
    }
    如果有人说生产环境日志怎么能随便清除,你可以用elk来存储和查询日志;
    3.用以下命令,定时清理exit的docker容器和挂载的文件夹。可以直接写成脚本,或者直接定时任务执行。
    docker image prune -a -f
    docker system prune -f
Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐