几个常用的自动处理日志脚本
nacos日志
#!/bin/sh #description:clean nacos logs time1=$(date -d '20 day ago' +%Y-%m-%d) #echo $time1 time2=$(date -d '1 day ago' +%Y-%m-%d) #echo $time2 file1=/usr/local/nacos/bin/logs/ cd $file1 gzip access_log.$time2.log rm -f access_log.$time1.log.gz
nohup日志
#!/bin/sh #description: clean hmm3 nohup.out log time1=$(date -d 'yesterday' +%Y%m%d) time2=$(date -d '15 day ago' +%Y%m%d) #echo $time1 #echo $time2 cd /opt/hmm3/hmm-appserver-provider/ cp nohup.out nohup.out-$time1 gzip nohup.out-$time1 cat /dev/null > nohup.out rm -f nohup.out-$time2 cd /opt/hmm3/hmm-system/ cp nohup.out nohup.out-$time1 gzip nohup.out-$time1 cat /dev/null > nohup.out rm -f nohup.out-$time2 cd /opt/hmm3/hmm-appserver-consumer/ cp nohup.out nohup.out-$time1 gzip nohup.out-$time1 cat /dev/null > nohup.out rm -f nohup.out-$time2 cd /opt/hmm3/hmm-file/ cp nohup.out nohup.out-$time1 gzip nohup.out-$time1 cat /dev/null > nohup.out rm -f nohup.out-$time2
启动微服务
#!/bin/sh #chkconfig: 2345 80 90 #description: start nacos and spring cloud jar cd /usr/local/nacos/bin/ nohup ./startup.sh -m standalone sleep 90 cd /opt/hmm3/hmm-appserver-provider/ nohup ./startup.sh sleep 90 cd /opt/hmm3/hmm-appserver-consumer/ nohup ./startup.sh cd /opt/hmm3/hmm-auth/ nohup ./startup.sh cd /opt/hmm3/hmm-file/ nohup ./startup.sh cd /opt/hmm3/hmm-gateway/ nohup ./startup.sh cd /opt/hmm3/hmm-system/ nohup ./startup.sh cd /opt/hmm3/hmm-job/ nohup ./startup.sh
nginx的日志
/etc/logrotate.d/nginx
/var/log/nginx/*log { create 0664 nginx root daily rotate 200 missingok #notifempty compress sharedscripts postrotate /bin/kill -USR1 `cat /run/nginx.pid 2>/dev/null` 2>/dev/null || true endscript }
/usr/nginx/logs/*log { create 0664 nginx root daily compress rotate 200 missingok #notifempty dateext sharedscripts postrotate if [ -f /usr/nginx/logs/nginx.pid ]; then kill -USR1 `cat /usr/nginx/logs/nginx.pid` fi endscript }
若不起作用,可在crontab中创建
10 3 * * * /usr/sbin/logrotate -f /etc/logrotate.d/nginx
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 【杭电多校比赛记录】2025“钉耙编程”中国大学生算法设计春季联赛(1)
2021-02-09 springboot 支持 jsp
2021-02-09 redis 储存session