一、测试环境
server.tomcat.accesslog.enabled=false
1
二、正式环境
1、编写脚本文件
logFile:日志删除记录文件(需要手动在指定文件下创建记录日志文件)
delFilePath:nacos日志文件(access.log)路径
#!/bin/bash
logFile="/usr/local/nacos/bin/logs/nacos_del_access.log"
# 保留7天日志
dateLog=`date -d "-7 day" +%Y-%m-%d`
# 具体位置可调整
delFilePath="/usr/local/nacos/bin/logs/access_log.${dateLog}.log"
# 日志文件存在,则删除
if [ -f "${delFilePath}" ];then
rm -rf ${delFilePath}
curDate=`date --date='0 days ago' "+%Y-%m-%d %H:%M:%S"`
echo '['${curDate}'] 删除文件'${delFilePath} >>${logFile}
fi
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
2、赋权限
chmod 755 nacosDelAccessLogs.sh
1
3、添加或更新linux系统中crontab指令
添加 crontab -e
查看 crontab -l
删除 crontab -r
1
2
3
4、添加定时执行指令
0 23 * * * /usr/local nacosDelAccessLogs.sh (23点执行脚本)
crontab表达式
5、启动服务
①第一种
service crond start //启动服务
service crond stop //关闭服务
service crond restart //重启服务
service crond reload //重新载入配置
service crond status //查看状态
②第二种
systemctl start crond.service //启动服务
systemctl stop crond.service //关闭服务
systemctl restart crond.service //重启服务
systemctl reload crond.service //重新载入配置
systemctl status crond.service //查看状态