定時清理服務器上log文件,清理docker日誌文件

/var/spool/cron/root
#00 18 * * * /usr/bin/curl https://www.xxxx.com/app/index.php?i=5\&c=entry\&do=printpreorder\&m=canteen
#*/10 * * * * /usr/bin/curl https://www.xxxx.com/app/index.php?i=5\&c=entry\&do=orderstatus\&m=canteen
#00 18 * * * /usr/bin/curl https://www.xxxx.com/app/index.php?i=2\&c=entry\&do=printpreorder\&m=canteen
#*/10 * * * * /usr/bin/curl https://www.xxxx.com/app/index.php?i=2\&c=entry\&do=orderstatus\&m=canteen
#00 18 * * * /usr/bin/curl https://www.xxxx.com/app/index.php?i=7\&c=entry\&do=printpreorder\&m=canteen
#*/10 * * * * /usr/bin/curl https://www.xxxx.com/app/index.php?i=7\&c=entry\&do=orderstatus\&m=canteen
*/5 * * * * flock -xn /tmp/stargate.lock -c '/usr/local/qcloud/stargate/admin/start.sh > /dev/null 2>&1 &'
0 5 * * * /usr/bin/find /tmp -name "*.jpg" |xargs rm -rf
0 5 * * * /usr/bin/find /docker/weight/assets/uploads -name "*.jpg" | xargs rm -rf "/docker/weight/assets/uploads/*.jpg"
0 5 * * * /usr/bin/find /var/lib/docker/overlay2/83fb17a6c17d7375ab745d694b465aa68233164a55bfaca2028dd8ba55985f9d/merged/tmp -name "*.jpg" |xargs rm -rf


truncate -s 0 /docker/nginx/log/access.log
truncate -s 0 /docker/nginx/log/error.log

truncate -s 0 /docker/weight/logs/out-0.log
truncate -s 0 /docker/weight/logs/out-1.log


truncate -s 0 /var/lib/docker/containers/bf12c61101fb7570ef8e082bff1e3bdfae04d8507ef4cf9e6186890c66421499/bf12c61101fb7570ef8e082bff1e3bdfae04d8507ef4cf9e6186890c66421499-json.log
truncate -s 0 /var/lib/docker/containers/c2d58d297166ecc7b2aaf39932b5c8af1c0278dffa36840124af0c3badba3028/c2d58d297166ecc7b2aaf39932b5c8af1c0278dffa36840124af0c3badba3028-json.log
truncate -s 0 /var/lib/docker/containers/dc34fa7a2446f41a4d1db33bd896e3ec1ca5887b6c14784db8711ef77e853a3f/dc34fa7a2446f41a4d1db33bd896e3ec1ca5887b6c14784db8711ef77e853a3f-json.log


2、查詢日誌大小
ls -lh $(find /var/lib/docker/containers/ -name *-json.log)

3、清理日誌
truncate -s 0 /var/lib/docker/containers/xxx-json.log


4、維護
日誌清理腳本,可以添加到crontab中
#!/bin/sh

logs=$(find /var/lib/docker/containers/ -name *-json.log)
for log in $logs
do
truncate -s 0 $log
done

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章