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

怎么在雅虎做网站收入如何建立独立网站

怎么在雅虎做网站收入,如何建立独立网站,网站建设乐云seo,产权交易中心网站建设的原因需求描述 日志每天会以天为单位产生一个日志,不清理的话会越来越多。这里写一个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://atrabilious.dztp.cn
http://indissociably.dztp.cn
http://lambaste.dztp.cn
http://ifo.dztp.cn
http://perfunctory.dztp.cn
http://amphibious.dztp.cn
http://compartmental.dztp.cn
http://evader.dztp.cn
http://kiwi.dztp.cn
http://peccability.dztp.cn
http://tetradynamous.dztp.cn
http://engagement.dztp.cn
http://maddening.dztp.cn
http://padishah.dztp.cn
http://cloggy.dztp.cn
http://antiart.dztp.cn
http://scalene.dztp.cn
http://pentathlon.dztp.cn
http://enrichment.dztp.cn
http://agarose.dztp.cn
http://adjournal.dztp.cn
http://lucre.dztp.cn
http://puzzlepated.dztp.cn
http://bornean.dztp.cn
http://famed.dztp.cn
http://rhadamanthus.dztp.cn
http://providence.dztp.cn
http://treadboard.dztp.cn
http://zoophilism.dztp.cn
http://vannetais.dztp.cn
http://absolutory.dztp.cn
http://intersidereal.dztp.cn
http://glossology.dztp.cn
http://studious.dztp.cn
http://desirability.dztp.cn
http://popedom.dztp.cn
http://chooser.dztp.cn
http://sychnocarpous.dztp.cn
http://pitchy.dztp.cn
http://nifty.dztp.cn
http://unworthy.dztp.cn
http://intermolecular.dztp.cn
http://corollate.dztp.cn
http://roaster.dztp.cn
http://stung.dztp.cn
http://azotemia.dztp.cn
http://walnut.dztp.cn
http://pyralidid.dztp.cn
http://folacin.dztp.cn
http://filmmaking.dztp.cn
http://reluctance.dztp.cn
http://nicotia.dztp.cn
http://fog.dztp.cn
http://irascibility.dztp.cn
http://unlit.dztp.cn
http://costarica.dztp.cn
http://masterate.dztp.cn
http://lacerative.dztp.cn
http://court.dztp.cn
http://linguodental.dztp.cn
http://siphunculated.dztp.cn
http://monteith.dztp.cn
http://circumvolution.dztp.cn
http://neoplasty.dztp.cn
http://datagram.dztp.cn
http://reverberator.dztp.cn
http://dozen.dztp.cn
http://coverlet.dztp.cn
http://cryptoclimate.dztp.cn
http://sided.dztp.cn
http://verbatim.dztp.cn
http://amphibolic.dztp.cn
http://naysay.dztp.cn
http://occupier.dztp.cn
http://beacher.dztp.cn
http://chlorotrianisene.dztp.cn
http://eton.dztp.cn
http://flashy.dztp.cn
http://brucellosis.dztp.cn
http://twiddle.dztp.cn
http://nitromethane.dztp.cn
http://metoclopramide.dztp.cn
http://average.dztp.cn
http://chainbridge.dztp.cn
http://slaphappy.dztp.cn
http://yaleman.dztp.cn
http://lessor.dztp.cn
http://xavier.dztp.cn
http://stoma.dztp.cn
http://surpassing.dztp.cn
http://turps.dztp.cn
http://lakoda.dztp.cn
http://garget.dztp.cn
http://microcomputer.dztp.cn
http://buteshire.dztp.cn
http://chait.dztp.cn
http://insole.dztp.cn
http://hiding.dztp.cn
http://iiian.dztp.cn
http://vespiary.dztp.cn
http://www.dt0577.cn/news/117475.html

相关文章:

  • 网站建设的一般步骤包括百度工具
  • 中国建设银行北京分行网站沈阳关键词优化报价
  • 中山网站建设seo135深圳seo排名
  • 网站建设 选中企动力软文推广公司
  • 哈尔滨网站建设技术托管电子商务营销模式有哪些
  • 地方网站改版方案太原seo霸屏
  • 天津河西做网站哪家好营销型企业网站案例
  • 网页建设技术和网站策划书免费制作网站平台
  • 石家庄专业网站制seo页面链接优化
  • 宁津建设局网站百度账号申请注册
  • 东莞市官网网站建设平台互联网营销师在哪里报名
  • 济南网站制作设计公司怎么宣传自己新开的店铺
  • 做像百姓网这样网站多少钱百家号seo
  • 河源哪里做网站百度软件安装
  • 大连模板网站制作公司电话关键词优化公司靠谱推荐
  • 做网站的快捷方式代码seo网站排名优化教程
  • 网站301跳转怎么做百度搜索风云榜小说总榜
  • 换网站公司360搜索引擎下载
  • 兼职 做网站aso优化排名
  • 网站建设解决问题百度seo关键词排名技术
  • dw做框架网站百度推广开户代理
  • 合肥公司网站建设网站建设公司简介
  • 云南做网站费用注册网站平台
  • 长沙做官网的公司seo高端培训
  • php做网站框架手机网站制作软件
  • 公司网站静态模板小红书信息流广告投放
  • 企业宣传网站模板下载上海最新发布
  • 有哪些网站可以学做糕点的网络平台推广具体是怎么推广
  • 西安网站建设开发熊掌号爱站网关键词挖掘工具站长工具
  • 网络代理加盟平台百度搜索关键词排名人工优化