docker修改配置日志驱动程序,设置日志的大小

老版本的docker所使用的日志驱动程序是:journald,使用docker info能进行查看。我们要对docker上的容器的日志进行收集,需要将日志驱动程序修改为:json-file驱动,重启docker报错。

1.查看下文件配置:

[root@i-m7uysopv redis_exporter]# grep -v "^#" /etc/sysconfig/docker

OPTIONS='--selinux-enabled --log-driver=journald --signature-verification=false'
if [ -z "${DOCKER_CERT_PATH}" ]; then
    DOCKER_CERT_PATH=/etc/docker
fi

2.修改配置文件/etc/docker/daemon.json

[root@i-m7uysopv redis_exporter]# cat /etc/docker/daemon.json 
{
    "insecure-registries":[
        "registry:5000"
    ],
  "log-opts": {"max-size":"10m", "max-file":"3"}
}

重启后出现docker异常。

[root@i-m7uysopv redis_exporter]# systemctl restart docker
Job for docker.service failed because the control process exited with error code. See "systemctl status docker.service" and "journalctl -xe" for details.
[root@i-m7uysopv redis_exporter]# systemctl status docker
● docker.service - Docker Application Container Engine
   Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since Thu 2020-08-20 15:04:20 CST; 3s ago
     Docs: http://docs.docker.com
  Process: 16312 ExecStart=/usr/bin/dockerd-current --add-runtime docker-runc=/usr/libexec/docker/docker-runc-current --default-runtime=docker-runc --exec-opt native.cgroupdriver=systemd --userland-proxy-path=/usr/libexec/docker/docker-proxy-current --init-path=/usr/libexec/docker/docker-init-current --seccomp-profile=/etc/docker/seccomp.json $OPTIONS $DOCKER_STORAGE_OPTIONS $DOCKER_NETWORK_OPTIONS $ADD_REGISTRY $BLOCK_REGISTRY $INSECURE_REGISTRY $REGISTRIES (code=exited, status=1/FAILURE)
 Main PID: 16312 (code=exited, status=1/FAILURE)

Aug 20 15:04:20 i-m7uysopv systemd[1]: Starting Docker Application Container Engine...
Aug 20 15:04:20 i-m7uysopv dockerd-current[16312]: Failed to set log opts: unknown log opt 'max-size' for journald log driver
Aug 20 15:04:20 i-m7uysopv systemd[1]: docker.service: main process exited, code=exited, status=1/FAILURE
Aug 20 15:04:20 i-m7uysopv systemd[1]: Failed to start Docker Application Container Engine.
Aug 20 15:04:20 i-m7uysopv systemd[1]: Unit docker.service entered failed state.
Aug 20 15:04:20 i-m7uysopv systemd[1]: docker.service failed.

3.修改Docker服务启动文件:

[root@i-m7uysopv redis_exporter]# grep -v "^#"  /etc/sysconfig/docker

OPTIONS='--selinux-enabled --log-driver=json-file --signature-verification=false'
if [ -z "${DOCKER_CERT_PATH}" ]; then
    DOCKER_CERT_PATH=/etc/docker
fi

4.在重启下docker

[root@i-m7uysopv redis_exporter]# systemctl status docker
● docker.service - Docker Application Container Engine
   Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled)
   Active: active (running) since Thu 2020-08-20 15:15:04 CST; 2s ago
     Docs: http://docs.docker.com
 Main PID: 19200 (dockerd-current)
   Memory: 15.2M
   CGroup: /system.slice/docker.service
           ├─19200 /usr/bin/dockerd-current --add-runtime docker-runc=/usr/libexec/docker/docker-runc-current --default-runtime=docker-runc --exec-opt native.cgroupdriver=systemd --userland-proxy-path=/usr/...
           └─19206 /usr/bin/docker-containerd-current -l unix:///var/run/docker/libcontainerd/docker-containerd.sock --metrics-interval=0 --start-timeout 2m --state-dir /var/run/docker/libcontainerd/contain...

Aug 20 15:15:04 i-m7uysopv dockerd-current[19200]: time="2020-08-20T15:15:04.305180741+08:00" level=warning msg="Docker could not enable SELinux on the host system"
Aug 20 15:15:04 i-m7uysopv dockerd-current[19200]: time="2020-08-20T15:15:04.310750545+08:00" level=info msg="Graph migration to content-addressability took 0.00 seconds"
Aug 20 15:15:04 i-m7uysopv dockerd-current[19200]: time="2020-08-20T15:15:04.312438045+08:00" level=info msg="Loading containers: start."
Aug 20 15:15:04 i-m7uysopv dockerd-current[19200]: time="2020-08-20T15:15:04.321522243+08:00" level=info msg="Firewalld running: false"
Aug 20 15:15:04 i-m7uysopv dockerd-current[19200]: time="2020-08-20T15:15:04.437320198+08:00" level=info msg="Default bridge (docker0) is assigned with an IP address 172.17.0.0/16. Daemon optio...d IP address"
Aug 20 15:15:04 i-m7uysopv dockerd-current[19200]: time="2020-08-20T15:15:04.474608708+08:00" level=info msg="Loading containers: done."
Aug 20 15:15:04 i-m7uysopv dockerd-current[19200]: time="2020-08-20T15:15:04.499092884+08:00" level=info msg="Daemon has completed initialization"
Aug 20 15:15:04 i-m7uysopv dockerd-current[19200]: time="2020-08-20T15:15:04.499127312+08:00" level=info msg="Docker daemon" commit="64e9980/1.13.1" graphdriver=overlay2 version=1.13.1
Aug 20 15:15:04 i-m7uysopv systemd[1]: Started Docker Application Container Engine.
Aug 20 15:15:04 i-m7uysopv dockerd-current[19200]: time="2020-08-20T15:15:04.516506905+08:00" level=info msg="API listen on /var/run/docker.sock"
Hint: Some lines were ellipsized, use -l to show in full.

  • 4
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值