- 生产环境
- 编写脚本文件
#!/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
- 赋权限
chmod 755 nacosDelAccessLogs.sh
- 添加或更新linux系统中crontab指令
添加 crontab -e
查看 crontab -l
删除 crontab -r
- 添加定时执行指令
0 23 * * * /usr/local nacosDelAccessLogs.sh (23点执行脚本)
- 启动服务
①第一种
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 //查看状态
- 测试环境
server.tomcat.accesslog.enabled=false
生产环境 编写脚本文件 #!/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 赋权限 chmod 755 nacosDelAccessLogs.sh 添加或更新linux系统中crontab指令 添加 crontab -e 查看 crontab -l 删除 crontab -r 添加定时执行指令 0 23 * * * /usr/local nacosDelAccessLogs.sh (23点执行脚本) 启动服务 ①第一种 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 //查看状态 测试环境 server.tomcat.accesslog.enabled=false