环境:centos7、docker
images下载:链接: https://pan.baidu.com/s/13wg-KSJAmb0V77zpin2vww 提取码: unkp
思路:docker容器模式的goaccess分析nginx日志——>配置crontab进行间隔分析——>配置nginx查看分析结果——>使用脚本分割nginx日志
1、goaccess 分析日志
[root@master242 kong-log]# cat /wj/rsgoaccess.sh
#!/bin/bash
cat /var/lib/docker/overlay/ba6f1d5344f354a5ac4262cfa64f8fa5ffa2a2f7dc677fb6e36780242b2478fc/upper/usr/local/kong/logs/access.log | docker run --rm -i -e LANG=zh_CN.UTF-8 allinurl/goaccess -a -o html --log-format COMBINED > /wj/goaccess/index.html
2、定时分析日志
1,30 8-18 * * * /wj/rsgoaccess.sh
3、配置nginx查看分析结果 http://ip:9999
docker run --name goaccess-nginx
-p 9999:80
-v /wj/goaccess:/usr/share/nginx/html
-itd nginx
4、日志分割
[root@master242 kong-log]# more update-rz.sh
#!/bin/bash
d=/wj/kong-log/$(date +"%Y-%m")
w=$d/$(date +"%Y-%m-%d").log
pdml(){
if [ -d "$d" ]
then
echo 'you'
else
echo 'meiyou'
mkdir $d
fi
}
pdml
cp /var/lib/docker/overlay/ba6f1d5344f354a5ac4262cfa64f8fa5ffa2a2f7dc677fb6e36780242b2478fc/upper/usr/local/kong/logs/access.log $w
echo a > /var/lib/docker/overlay/ba6f1d5344f354a5ac4262cfa64f8fa5ffa2a2f7dc677fb6e36780242b2478fc/upper/usr/local/kong/logs/access.log
crontab -l
59 23 * * * /wj/kong-log/update-rz.sh