查看文件大小
df -Th
find . -type f -size +100M
服务器日志清理
脚本处理
设置一个查看的脚本docker_log_size.sh:
echo "======== docker containers logs file size ========"
logs=$(find /var/lib/docker/containers/ -name *-json.log)
for log in $logs
do
ls -lh $log
done
同时,也可以通过脚本来清理:clean_docker_log.sh
echo "======== start clean docker containers logs ========"
logs=$(find /var/lib/docker/containers/ -name *-json.log)
for log in $logs
do
echo "clean logs : $log"
cat /dev/null > $log
done
echo "======== end clean docker containers logs ========"
docker 日志设置
全局配置
在/etc/docker/daemon.json文件中的以下内容自动轮换日志:
{
"log-driver": "json-file",
"log-opts": {"max-size": "100m", "max-file": "3"}
}
配置完后重启docker
systemctl daemon-reload && systemctl restart docker
docker-compose 容器限制
nginx:
image: nginx:1.12.1
restart: always
logging:
driver: "json-file"
options:
max-size: "512M"