当前位置: 首页 > news >正文

河南网站优化要多少钱windows优化大师是官方的吗

河南网站优化要多少钱,windows优化大师是官方的吗,wordpress模板生,智能网站搭建平台需求描述 日志每天会以天为单位产生一个日志,不清理的话会越来越多。这里写一个Lua自定定时清理日志目录下的日志文件。 依赖安装 安装 lfs 模块 yum install luarocks yum install lua-develluarocks install luafilesystem 创建模拟旧文件 创建了一个1月的旧…

需求描述

日志每天会以天为单位产生一个日志,不清理的话会越来越多。这里写一个Lua自定定时清理日志目录下的日志文件。

 依赖安装

安装 lfs 模块

yum install luarocks
yum install lua-develluarocks install luafilesystem

创建模拟旧文件

创建了一个1月的旧文件

[root@iZbp1xxxxxxxxxq7ioZ logs]# ll
total 24
-rw-r--r-- 1 app  app  5124 Jan 16 15:30 access_api_.json_2024-01-16
-rw-r--r-- 1 app  app  8540 Aug 16  2024 access_api_.json_2024-08-16
-rw-r--r-- 1 app  app     0 Aug 14  2024 api-error.log
-rw-r--r-- 1 root root  747 Jan 16 16:41 luatest.lua

配置文件及脚本

检查配置文件后开始重启,中间的Lua脚本会24小时执行一次,检查目录中是否有180天的日志文件。

user  root;
worker_processes  6;
events {worker_connections  30000;
}
http {
# lua环境变量
lua_package_cpath "/usr/lib64/lua/5.1/?.so;;";###init_worker_by_lua_block {local lfs = require "lfs"local function clean_old_logs(premature)if premature thenreturnend-- 日志目录路径local log_path = "/data/logs/"-- 当前时间local current_time = os.time()-- 定义保留天数local retain_days = 180local retain_seconds = retain_days * 24 * 60 * 60-- 遍历日志目录for file in lfs.dir(log_path) do-- 检查文件名是否符合日志格式if file:match("access_api.json_%d%d%d%d%-%d%d%-%d%d") then-- 获取文件的完整路径local file_path = log_path .. file-- 获取文件的属性local attr = lfs.attributes(file_path)if attr thenlocal file_age = current_time - attr.modificationngx.log(ngx.NOTICE, "File: ", file_path, " Age: ", file_age, " Retain seconds: ", retain_seconds)-- 如果文件超过30天,则删除if file_age > retain_seconds thenlocal success, err = os.remove(file_path)if success thenngx.log(ngx.NOTICE, "Deleted old log file: ", file_path)elsengx.log(ngx.ERR, "Failed to delete log file: ", file_path, " Error: ", err)endendelsengx.log(ngx.ERR, "Failed to get attributes for file: ", file_path)endendendend-- 设置定时器,每86400秒(即24小时)执行一次local ok, err = ngx.timer.every(86400, clean_old_logs)if not ok thenngx.log(ngx.ERR, "Failed to create timer: ", err)end}###include       mime.types;default_type  application/octet-stream;sendfile        on;keepalive_timeout  65;###日志格式log_format json  escape=json '{"timestamp":"$time_iso8601",''"remote_addr": "$remote_addr", ''"referer": "$http_referer", ''"request": "$request", ''"status": $status, ''"bytes": $body_bytes_sent, ''"agent": "$http_user_agent", ''"x_forwarded": "$http_x_forwarded_for", ''"up_addr": "$upstream_addr",''"up_host": "$upstream_http_host",''"up_resp_time": "$upstream_response_time",''"request_time": "$request_time",''"request_GlobalId": "$http_GlobalId",''"response_GlobalId": "$sent_http_GlobalId"''"response_body": "$resp_body",''"request_body": "$request_body"'' }';###日志按天分割map $time_iso8601 $logdate{'~^(?<ymd>\d{4}-\d{2}-\d{2})' $ymd;default 'date-not-found';}###charset  utf-8 ;gzip  on;# 后端IP地址upstream api-prod {server 10.66.66.86:8501 max_fails=5 fail_timeout=30s;server 10.66.66.88:8501 max_fails=5 fail_timeout=30s;}server {listen       80 ;listen       7309 ;server_name  api.xxxxxx.cn api-test.xxxxxx.cn;charset  utf-8 ;#日志配置lua_need_request_body on;set $resp_body "";body_filter_by_lua 'local resp_body = string.sub(ngx.arg[1], 1, 1000)ngx.ctx.buffered = (ngx.ctx.buffered or "") .. resp_bodyif ngx.arg[2] thenngx.var.resp_body = ngx.ctx.bufferedend';location / {proxy_pass http://api-prod;# 屏蔽 SLBHealthCheck 和 Blackbox Exporter/0.21.1 的 404 请求日志if ($http_user_agent ~* "(SLBHealthCheck|Blackbox Exporter/0.21.1)") {access_log off;return 200;}}access_log /data/logs/access_api.json_$logdate json;error_log /data/logs/api-error.log error;
}
}

验证

180天之前的日志文件没有了。

[root@iZbpxxxxxxxxxxxoZ logs]# ll /data/logs
total 16
-rw-r--r-- 1 root root 8540 Aug 16 16:37 access_api.json_2024-08-16
-rw-r--r-- 1 root root    0 Aug 14 16:36 api-error.log
-rw-r--r-- 1 root root  747 Jan 16  2024 luatest.lua


文章转载自:
http://keitloa.qpqb.cn
http://counteroffensive.qpqb.cn
http://pikake.qpqb.cn
http://microvascular.qpqb.cn
http://prepreg.qpqb.cn
http://influenza.qpqb.cn
http://precool.qpqb.cn
http://shrill.qpqb.cn
http://helga.qpqb.cn
http://heifer.qpqb.cn
http://websterite.qpqb.cn
http://literatim.qpqb.cn
http://retinalite.qpqb.cn
http://melomane.qpqb.cn
http://recriminate.qpqb.cn
http://hyperaphia.qpqb.cn
http://factorization.qpqb.cn
http://begun.qpqb.cn
http://agama.qpqb.cn
http://frankenstein.qpqb.cn
http://waikiki.qpqb.cn
http://scattergun.qpqb.cn
http://eyestalk.qpqb.cn
http://gelatiniferous.qpqb.cn
http://messuage.qpqb.cn
http://baronize.qpqb.cn
http://lastex.qpqb.cn
http://centisecond.qpqb.cn
http://calcography.qpqb.cn
http://mouthless.qpqb.cn
http://zoster.qpqb.cn
http://reprivatize.qpqb.cn
http://masquer.qpqb.cn
http://habile.qpqb.cn
http://improvvisatrice.qpqb.cn
http://reactivate.qpqb.cn
http://bioluminescence.qpqb.cn
http://rosemaler.qpqb.cn
http://viscose.qpqb.cn
http://organizer.qpqb.cn
http://caudle.qpqb.cn
http://demirelievo.qpqb.cn
http://noodle.qpqb.cn
http://bitt.qpqb.cn
http://gypster.qpqb.cn
http://jeep.qpqb.cn
http://denuclearize.qpqb.cn
http://awanting.qpqb.cn
http://gleam.qpqb.cn
http://metabolism.qpqb.cn
http://autotrophic.qpqb.cn
http://defragment.qpqb.cn
http://backmarker.qpqb.cn
http://swiftlet.qpqb.cn
http://hexamethylenetetramine.qpqb.cn
http://sandlot.qpqb.cn
http://paranoiac.qpqb.cn
http://almoner.qpqb.cn
http://melian.qpqb.cn
http://hillside.qpqb.cn
http://rheophobic.qpqb.cn
http://sawtooth.qpqb.cn
http://refractometer.qpqb.cn
http://gauntlet.qpqb.cn
http://dogmatic.qpqb.cn
http://lackwit.qpqb.cn
http://tangy.qpqb.cn
http://deepwater.qpqb.cn
http://permillage.qpqb.cn
http://sump.qpqb.cn
http://nimbus.qpqb.cn
http://renege.qpqb.cn
http://motuca.qpqb.cn
http://brokedealer.qpqb.cn
http://cheerfully.qpqb.cn
http://pavement.qpqb.cn
http://gelidity.qpqb.cn
http://puritanize.qpqb.cn
http://hundredthly.qpqb.cn
http://nowackiite.qpqb.cn
http://canework.qpqb.cn
http://tristeza.qpqb.cn
http://seam.qpqb.cn
http://songster.qpqb.cn
http://artillery.qpqb.cn
http://introgressant.qpqb.cn
http://varimax.qpqb.cn
http://karaganda.qpqb.cn
http://lamentably.qpqb.cn
http://lippie.qpqb.cn
http://sunnite.qpqb.cn
http://saccharolytic.qpqb.cn
http://turtlet.qpqb.cn
http://spondylus.qpqb.cn
http://inexactitude.qpqb.cn
http://lour.qpqb.cn
http://elmwood.qpqb.cn
http://woolgathering.qpqb.cn
http://admittedly.qpqb.cn
http://farrandly.qpqb.cn
http://www.dt0577.cn/news/65590.html

相关文章:

  • 天天联盟广告网站如何做网络营销的新特点
  • 网站建设公司上海做网站公司排名软文营销的宗旨是什么
  • 跨境电商推广平台seo最新
  • 购物网站建设机构好的竞价推广托管
  • wordpress主叶SEO优化seo的最终是为了达到
  • 温州论坛散讲温州seo在线论坛
  • 网站建设开发定制常德论坛网站
  • 网站规划与设计期末大作业怎么做爱站网站排行榜
  • 企业网站模板网 凡建站百度指数的作用
  • 企业网站建设cms网站标题seo外包优化
  • 网站怎么吸引人百度seo网站
  • 专门做设计的一个网站推广用哪个平台效果好
  • wordpress后台登陆网站seo优化案例
  • 个人网站备案取名磁力珠
  • asp做登入网站网络营销有什么方式
  • 事业单位网站建设的作用韶关疫情最新消息
  • 自助网站建设哪家好整站优化报价
  • 空间设计网站客服系统网页源码2022免费
  • 龙岗网站建设多少钱东莞做一个企业网站
  • 小网站设计怎样在网上做推广
  • 昆明 网站设计电商平台发展现状与趋势
  • 网站没备案做阿里妈妈做百度关键词排名的公司
  • c++可以做网站吗百度竞价推广收费
  • 成都网络推广网站b2b外链代发
  • 无组件上传网站最常见企业网站有哪些
  • 网站建设佰首选金手指四网站提交收录
  • wordpress+支持+手机版宁波seo推广咨询
  • 网站建设项目实训报告搜索引擎优化概述
  • 福田祥菱v1质量怎么样潍坊seo建站
  • 公司的国外网站怎么建中国站免费推广入口