ChanCMS

ChanCMS系列视频六:PM2定时清理logs日志(视频)

2024-11-06 17:50:55 阅读(597)

「导读」日志可以方便我们查找问题,过多的日志会占用空间,降低服务器运行性能。定期清理日志是必不可少的一步。

日志可以方便我们查找问题,过多的日志会占用空间,降低服务器运行性能。定期清理日志是必不可少的一步。

安装pm2-logrotate

pm2 install pm2-logrotate

查看详细配置

pm2 conf pm2-logrotate

pm2-logrotate 配置

每个文件最大存储 注:10G 10M 10K

pm2 set pm2-logrotate:max_size 10M

retain:保留的日志文件个数,比如设置为30,那么在日志文件达到30个后就会将最早的日志文件删除

pm2 set pm2-logrotate:retain 30

* 是否通过gzip压缩日志

pm2 set pm2-logrotate:compress false

dateFormat 日志文件名的日期格式。如设置的日志名为out.log,就会生成out-YYYY-MM-DD_HH-mm-ss.log 的日志文件

pm2 set pm2-logrotate:dateFormat YYYY-MM-DD_HH-mm-ss

检查日志大小的时间间隔,最小为1

pm2 set pm2-logrotate:workerInterval 30

设置强制分割,默认值是0 0 ***,意思是每天晚上0点分割

pm2 set pm2-logrotate:rotateInterval 0 0***

rotateModule 是否把pm2本身的日志也进行分割

pm2 set pm2-logrotate:rotateModule true

使用pm2 list查看到pm2-logrotate 进程id为0 ,执行pm2 stop 0即可停止服务

接口页面--全局数据:

site-> {"id":1,"name":"ChanCMS","domain":"www.chancms.top","email":"867528315@qq.com","wx":null,"icp":"皖ICP备2024033678号-1","code":"","json":"","title":"禅cms内容管理系统","keywords":"chancms_ChanCms_禅cms_网站建设_网站制作_企业建站","description":"chancms是一款基于Express和MySQL研发的高质量实用型CMS管理系统。它具备多种类型网站开发,公司,企业,学校,政府,图片,下载,产品等各类型网站建设。易扩展、基于模块化和插件化开发模式,适用于商用企业级程序开发。","template":null,"appid":null,"secret":null,"createdAt":null,"updatedAt":"2024-02-04T03:17:22.000Z"}

111-->

nav-> [{"id":9,"pid":0,"name":"首页","pinyin":"home","path":"/home","sort":1,"target":"0","status":"0","list_view":"chanyue.html","article_view":"chanyue.html","seo_title":"","seo_keywords":"","seo_description":"","type":"1"},{"id":1,"pid":0,"name":"案例","pinyin":"case","path":"/case","sort":2,"target":"0","status":"0","list_view":"list.html","article_view":"article.html","seo_title":"禅cms案例","seo_keywords":"禅cms,ChanCMS","seo_description":"禅cms网站案例","type":"0"},{"id":2,"pid":0,"name":"文档","pinyin":"docs","path":"/docs","sort":3,"target":"0","status":"0","list_view":"list.html","article_view":"article.html","seo_title":"ChanCMS文档","seo_keywords":"ChanCMS,禅cms,cms,express,nodejs","seo_description":"ChanCMS使用文档","type":"0"},{"id":3,"pid":0,"name":"模板","pinyin":"muban","path":"/muban","sort":4,"target":"0","status":"0","list_view":"list.html","article_view":"article.html","seo_title":"ChanCMS模板","seo_keywords":"禅cms,ChanCMS","seo_description":"ChanCMS模板市场","type":"0"},{"id":5,"pid":0,"name":"定制","pinyin":"custom","path":"/custom","sort":5,"target":"0","status":"0","list_view":"list.html","article_view":"article.html","seo_title":"ChanCMS定制","seo_keywords":"ChanCMS,禅cms,cms,nodecms,express","seo_description":"ChanCMS基于express进行可定制开发需求","type":"0"},{"id":8,"pid":0,"name":"关于","pinyin":"about","path":"/about","sort":6,"target":"0","status":"0","list_view":"list.html","article_view":"page.html","seo_title":"ChanCMS","seo_keywords":"ChanCMS","seo_description":"ChanCMS","type":"1"}]

category-> [{"id":9,"pid":0,"name":"首页","pinyin":"home","path":"/home","sort":1,"target":"0","status":"0","list_view":"chanyue.html","article_view":"chanyue.html","seo_title":"","seo_keywords":"","seo_description":"","type":"1"},{"id":1,"pid":0,"name":"案例","pinyin":"case","path":"/case","sort":2,"target":"0","status":"0","list_view":"list.html","article_view":"article.html","seo_title":"禅cms案例","seo_keywords":"禅cms,ChanCMS","seo_description":"禅cms网站案例","type":"0"},{"id":2,"pid":0,"name":"文档","pinyin":"docs","path":"/docs","sort":3,"target":"0","status":"0","list_view":"list.html","article_view":"article.html","seo_title":"ChanCMS文档","seo_keywords":"ChanCMS,禅cms,cms,express,nodejs","seo_description":"ChanCMS使用文档","type":"0"},{"id":3,"pid":0,"name":"模板","pinyin":"muban","path":"/muban","sort":4,"target":"0","status":"0","list_view":"list.html","article_view":"article.html","seo_title":"ChanCMS模板","seo_keywords":"禅cms,ChanCMS","seo_description":"ChanCMS模板市场","type":"0"},{"id":5,"pid":0,"name":"定制","pinyin":"custom","path":"/custom","sort":5,"target":"0","status":"0","list_view":"list.html","article_view":"article.html","seo_title":"ChanCMS定制","seo_keywords":"ChanCMS,禅cms,cms,nodecms,express","seo_description":"ChanCMS基于express进行可定制开发需求","type":"0"},{"id":8,"pid":0,"name":"关于","pinyin":"about","path":"/about","sort":6,"target":"0","status":"0","list_view":"list.html","article_view":"page.html","seo_title":"ChanCMS","seo_keywords":"ChanCMS","seo_description":"ChanCMS","type":"1"}]

friendlink-> [{"id":1,"title":"香港日报","link":"http://www.hongkongdaily.net","sort":0,"createdAt":"2023-07-22T14:59:55.000Z","updatedAt":"2023-11-25T04:44:34.000Z"}]

base_url-> /public/template/chancms

frag--->{"copyright":"<p class=\"f-13 text-c c-bfbfbf\">自豪的采用 chancms</p>"}

tag--->[{"id":5,"name":"模板","path":"muban"},{"id":4,"name":"文档","path":"docs"},{"id":3,"name":"案例","path":"case"},{"id":1,"name":"cms","path":"cms"}]

-----------

position------>[{"id":2,"pid":0,"name":"文档","pinyin":"docs","path":"/docs","sort":3,"target":"0","status":"0","list_view":"list.html","article_view":"article.html","seo_title":"ChanCMS文档","seo_keywords":"ChanCMS,禅cms,cms,express,nodejs","seo_description":"ChanCMS使用文档","type":"0"}]

navSub------>{"cate":{"id":2,"pid":0,"name":"文档","pinyin":"docs","path":"/docs","sort":3,"target":"0","status":"0","list_view":"list.html","article_view":"article.html","seo_title":"ChanCMS文档","seo_keywords":"ChanCMS,禅cms,cms,express,nodejs","seo_description":"ChanCMS使用文档","type":"0"},"id":2}

article------>{"id":86,"cid":2,"sub_cid":"","title":"ChanCMS系列视频六:PM2定时清理logs日志(视频)","short_title":"","tag_id":"","attr":"","seo_title":"","seo_keywords":"","seo_description":"","source":"","author":"","description":"日志可以方便我们查找问题,过多的日志会占用空间,降低服务器运行性能。定期清理日志是必不可少的一步。","img":"","content":"<p>日志可以方便我们查找问题,过多的日志会占用空间,降低服务器运行性能。定期清理日志是必不可少的一步。</p>\n<p><iframe src=\"//player.bilibili.com/player.html?aid=664239988&bvid=BV1Qa4y1o7XD&cid=1353263929&p=1\" width=\"100%\" height=\"520\" frameborder=\"no\" scrolling=\"no\" allowfullscreen=\"allowfullscreen\"> </iframe></p>\n<h2>安装pm2-logrotate</h2>\n<pre class=\"language-markup\"><code>pm2 install pm2-logrotate</code></pre>\n<h3>查看详细配置</h3>\n<pre class=\"language-markup\"><code>pm2 conf pm2-logrotate</code></pre>\n<h3>pm2-logrotate 配置</h3>\n<p>每个文件最大存储 注:10G 10M 10K</p>\n<pre class=\"language-markup\"><code>pm2 set pm2-logrotate:max_size 10M</code></pre>\n<p>retain:保留的日志文件个数,比如设置为30,那么在日志文件达到30个后就会将最早的日志文件删除</p>\n<pre class=\"language-markup\"><code>pm2 set pm2-logrotate:retain 30</code></pre>\n<p>* 是否通过gzip压缩日志</p>\n<pre class=\"language-markup\"><code>pm2 set pm2-logrotate:compress false</code></pre>\n<p>dateFormat 日志文件名的日期格式。如设置的日志名为out.log,就会生成out-YYYY-MM-DD_HH-mm-ss.log 的日志文件</p>\n<pre class=\"language-markup\"><code>pm2 set pm2-logrotate:dateFormat YYYY-MM-DD_HH-mm-ss</code></pre>\n<p>检查日志大小的时间间隔,最小为1</p>\n<pre class=\"language-markup\"><code>pm2 set pm2-logrotate:workerInterval 30</code></pre>\n<p>设置强制分割,默认值是0 0 ***,意思是每天晚上0点分割</p>\n<pre class=\"language-markup\"><code>pm2 set pm2-logrotate:rotateInterval 0 0***</code></pre>\n<p>rotateModule 是否把pm2本身的日志也进行分割</p>\n<pre class=\"language-markup\"><code>pm2 set pm2-logrotate:rotateModule true</code></pre>\n<p>使用pm2 list查看到pm2-logrotate 进程id为0 ,执行pm2 stop 0即可停止服务</p>","status":0,"pv":597,"link":"","createdAt":"2024-05-30 16:27:10","updatedAt":"2024-11-06 17:50:55","field":{},"tags":[]}

article.tags------>[]

news------>[{"id":86,"title":"ChanCMS系列视频六:PM2定时清理logs日志(视频)","short_title":"","img":"","createdAt":"2024-05-30T08:27:10.000Z","description":"日志可以方便我们查找问题,过多的日志会占用空间,降低服务器运行性能。定期清理日志是必不可少的一步。","pinyin":"docs","name":"文档","path":"/docs"},{"id":85,"title":"ChanCMS系列教程五:Linux服务器部署教程(视频)","short_title":"","img":"","createdAt":"2024-05-30T08:18:02.000Z","description":"ChanCMS系列教程五:Linux服务器部署教程(视频操作),讲解nodejs环境部署,mysql安装,pm2运行,域名绑定,反向代理等操作。","pinyin":"docs","name":"文档","path":"/docs"},{"id":84,"title":"ChanCMS系列教程四:后台基本操作(视频)","short_title":"","img":"","createdAt":"2024-05-30T08:13:11.000Z","description":"ChanCMS后台基本操作视频,主要讲解一下功能点,通过此视频可以大概了解ChanCMS基本功能。","pinyin":"docs","name":"文档","path":"/docs"},{"id":83,"title":"ChanCMS系列教程三:常用模板标签","short_title":"","img":"","createdAt":"2024-05-30T08:06:25.000Z","description":"ChanCMS系列教程三:常用模板标签","pinyin":"docs","name":"文档","path":"/docs"},{"id":82,"title":"ChanCMS系列教程二:模板开发","short_title":"","img":"","createdAt":"2024-05-30T07:30:39.000Z","description":"ChanCMS教程之模板开发,模板目录介绍、模板文件介绍、模板开发核心流程、自定义模板数据。","pinyin":"docs","name":"文档","path":"/docs"},{"id":81,"title":"ChanCMS系列教程一:安装运行快速入门","short_title":"","img":"","createdAt":"2024-02-03T14:21:08.000Z","description":"环境配置​前置条件:安装node.js mysql 和 mysql可视化工具。本地开发推荐用phpStudy。","pinyin":"docs","name":"文档","path":"/docs"}]

hot------>[{"id":81,"title":"ChanCMS系列教程一:安装运行快速入门","path":"/docs"},{"id":82,"title":"ChanCMS系列教程二:模板开发","path":"/docs"},{"id":84,"title":"ChanCMS系列教程四:后台基本操作(视频)","path":"/docs"},{"id":83,"title":"ChanCMS系列教程三:常用模板标签","path":"/docs"},{"id":85,"title":"ChanCMS系列教程五:Linux服务器部署教程(视频)","path":"/docs"},{"id":86,"title":"ChanCMS系列视频六:PM2定时清理logs日志(视频)","path":"/docs"}]

imgs------>[]

pre------>{"id":85,"title":"ChanCMS系列教程五:Linux服务器部署教程(视频)","name":"文档","path":"/docs"}

next------>