首页
Search
1
安装docker时报错container-selinux >= 2:2.74
124 阅读
2
rsync命令(可替代rm删除巨量文件)
101 阅读
3
docker 镜像加速器配置,daemon.json文件详解
90 阅读
4
使用国内镜像地址拉取k8s安装需要的images
79 阅读
5
Redhat 8版本安装ansible步骤
75 阅读
运维
自动化运维
数据库
容器与k8s
环境
云计算
脚本
登录
Search
标签搜索
命令
nginx
Mingrui
累计撰写
64
篇文章
累计收到
0
条评论
首页
栏目
运维
自动化运维
数据库
容器与k8s
环境
云计算
脚本
页面
搜索到
7
篇与
的结果
2024-01-29
nginx日志文件按日期分割脚本
{card-describe title="写在开头"}工作环境下,更建议直接使用系统自带的日志切割工具lograte来进行日志分割。此脚本只为练习用。{/card-describe}{dotted startColor="#ff6c6c" endColor="#1989fa"/}1.若日志文件可能存在往日的访问信息,可以运行下面的脚本.该脚本先判断日志文件中是否存在过往的访问信息,如果存在,先处理这些过往信息。处理方式是按照日期生成文本文档,并写入对应的访问信息。然后清空日志文件,等待新的记录写入。如果不存在过往访问记录,则直接将该文件按日期重命名,然后通知nginx重新打开日志文件。说明:如果原始的日志文件非常大,可以先用split命令对文件进行切割,然后再逐个处理切割出来的小文件,以减轻服务器的压力。#!/bin/bash #将日志文件中未按日期分割的历史记录进行分割。 #获取日志文件中的日期信息,并将其写入临时文件 log_dir=/opt/access.log awk '{print $4}' $log_dir | awk -F: '{print $1}' | sed 's/\[//' | sort -u -t/ -k3 -k1 > /opt/log_date.txt #先判断日志文件中是否存在往期的日志信息,如果存在,先处理历史日志信息。 sum=`wc -l < /opt/log_date.txt` if [ $sum -gt 1 ];then #通过for循环,将历史日志记录按日期分别记录到指定的文件内。 for i in `cat /opt/log_date.txt` do dir=`echo $i| sed 's#/#-#g' ` grep $i $log_dir >> /opt/a/$dir-access.log done > $log_dir else dir=`cat /opt/log_date.txt| sed 's#/#-#g' ` mv $log_dir /opt/a/$dir-access.log kill -USR1 $(cat /var/run/nginx.pid) #通过USER1信号通知nginx重新打开日志文件 $nginx_sbin force-reload fi {lamp/}一个简单的分割脚本#!/bin/bash Dateformat=`date +%Y%m%d` Basedir="/usr/local/nginx" Nginxlogdir="$Basedir/logs" Logname="access_www" [ -d $Nginxlogdir ] && cd $Nginxlogdir || exit 1 [ -f ${Logname}.log ] || exit 1 mv ${Logname}.log ${Dateformat}_${Logname}.log $Basedir/sbin/nginx -s reload {lamp/}一个非常耗时的日志分割脚本cat access.log | while read i a b t c do date_dir=`echo $t|sed 's#\[##'|sed 's#\/#-#g'|cut -d: -f1` echo $i $a $b $t $c >> /tmp/log/$date_dir-log.txt date=`echo $date_dir| sed 's#-#\.#g'` sed -i "/$i.*$date/d" access.log done
2024年01月29日
56 阅读
0 评论
0 点赞
2024-01-01
nginx配置文件详解
#user nobody; worker_processes 1; #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; #pid logs/nginx.pid; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; #log_format main '$remote_addr - $remote_user [$time_local] "$request" ' # '$status $body_bytes_sent "$http_referer" ' # '"$http_user_agent" "$http_x_forwarded_for"'; #access_log logs/access.log main; sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; #gzip on; server { listen 80; server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; location / { root html; index index.html index.htm; } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } # proxy the PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ \.php$ { # proxy_pass http://127.0.0.1; #} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # #location ~ \.php$ { # root html; # fastcgi_pass 127.0.0.1:9000; # fastcgi_index index.php; # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; # include fastcgi_params; #} # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # #location ~ /\.ht { # deny all; #} } # another virtual host using mix of IP-, name-, and port-based configuration # #server { # listen 8000; # listen somename:8080; # server_name somename alias another.alias; # location / { # root html; # index index.html index.htm; # } #} # HTTPS server # #server { # listen 443 ssl; # server_name localhost; # ssl_certificate cert.pem; # ssl_certificate_key cert.key; # ssl_session_cache shared:SSL:1m; # ssl_session_timeout 5m; # ssl_ciphers HIGH:!aNULL:!MD5; # ssl_prefer_server_ciphers on; # location / { # root html; # index index.html index.htm; # } #} }
2024年01月01日
62 阅读
0 评论
0 点赞
1
2