我们先来看mysql备份脚本
代码如下 | 复制代码 |
mysql_back.sh #!/bin/sh backupdir=/opt/cpfxs/mysqlbak time=` date +%Y%m%d ` $mysqlpath/mysqldump -h127.0.0.1 -uroot -pluobo mydb | gzip > $backupdir/mydb$time.sql.gz #删除超过7天的备份 |
上面步骤与方法超很简单的,下面日志分割
代码如下 | 复制代码 |
cut_nginx_log_.sh #!/bin/bash logs_path="/var/www/log" date=$(date -d "yesterday" +"%Y-%m-%d") #重命名日志文件 #通知nginx 重新写日志文件 |
上面只是简单的日志操作,下面我们来看一段更详细的nginx日志分割功能
一,日志的切割
shell脚本如下:
代码如下 | 复制代码 |
#!/bin/bash logs_path="/nginx/logs/" |
其中 "/nginx/logs" 指的是nginx的log日志文件所在目录,生成的日志文件是以昨天日期命名的。
为了达到每天自动分割的目的,在crontab中加入以下部分:
1 0 * * * sh /home/zyf/sh/cut_nginx_log.sh
这样就每天的0点1分把nginx日志重命名为日期格式,并重新生成今天的新日志文件。
二,Awstats的配置
日志文件分割好了,接下来就是分析了,也就是工具软件Awstats的使用了。
Awstats的配置文件默认会存储在/etc/awstats/目录下,包括你安装时设置的域名如:awstats.www.xxxxke.com.conf。
在这个配置文件中修改这个地方:
代码如下 | 复制代码 |
LogFile="/nginx/logs/access_%YYYY-24%MM-24%DD-24.log" |
这个意思是要去读取nginx昨天的日志文件,关于后边%YYYY-24%MM-24%DD-24的设置,规则如下:
# You can also use tags in this filename if you need a dynamic file name
# depending on date or time (Replacement is made by AWStats at the beginning
# of its execution). This is available tags :
# %YYYY-n is replaced with 4 digits year we were n hours ago
# %YY-n is replaced with 2 digits year we were n hours ago
# %MM-n is replaced with 2 digits month we were n hours ago
# %MO-n is replaced with 3 letters month we were n hours ago
# %DD-n is replaced with day we were n hours ago
# %HH-n is replaced with hour we were n hours ago
# %NS-n is replaced with number of seconds at 00:00 since 1970
# %WM-n is replaced with the week number in month (1-5)
# %Wm-n is replaced with the week number in month (0-4)
# %WY-n is replaced with the week number in year (01-52)
# %Wy-n is replaced with the week number in year (00-51)
# %DW-n is replaced with the day number in week (1-7, 1=sunday)
# use n=24 if you need (1-7, 1=monday)
# %Dw-n is replaced with the day number in week (0-6, 0=sunday)
# use n=24 if you need (0-6, 0=monday)
# Use 0 for n if you need current year, month, day, hour
三,开始分析、生成结果
最后,可以执行分析了。
使用这个命令:
代码如下 | 复制代码 |
/usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=www.111com.net |
这个命令会把结果生成到/var/lib/awstats 目录下 awstatsXXXX.www.XXXX.com.txt文件。
当然这样看起来不太方便,可以再用下面的命令来生成html页面,更加直观。
代码如下 | 复制代码 |
perl /usr/local/awstats/tools/awstats_buildstaticpages.pl -update |
这样就会在/html/awstats目录下生成很直观的分析结果页。
四,自动化
要是每天都去服务器上运行几条命令肯定是件令人烦燥的事情,幸亏Linux的世界里有crontab,
下面是从网友那找的 crontab
代码如下 | 复制代码 |
1 0 * * * sh /home/zyf/sh/cut_nginx_log.sh 0 1 * * * /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=www.xxxxke.com 0 2 * * * perl /usr/local/awstats/tools/awstats_buildstaticpages.pl -update -config=www.xxxxke.com -lang=cn -dir=/html/awstats -awstatsprog=/usr/local/awstats/wwwroot/cgi-bin/awstats.pl
LogFile="/usr/local/nginx/logs/%YYYY-24/%MM-24/expotia2.access_%YYYY-24%MM-24%DD-24.log" log_format main '$remote_addr - $remote_user [$time_local] "$request" ' |
荒野乱斗国际版 (BrawlStars)最新版本v56.274
下载一波超人内置修改器菜单版 安卓版v1.0.2
下载敢达决战官方正版 安卓版v6.7.9
下载敢达决战 安卓版v6.7.9
下载继承了一座戏园子无限声望铜钱版 内置菜单最新版v1.7
继承了一座戏园子折相思版是游戏的破解版本,在该版本中为玩家提
山河半世橙光清软金手指版 无限鲜花v3.24
山河半世是一款超级好玩的橙光恋爱游戏,在游戏中玩家们需要扮演
蓬莱手游折相思版 安卓版v1.0.0
蓬莱免广告版是游戏的修改版本,在该版本中为玩家去除了广告,玩
当红影后橙光游戏破解版2025 最新版v1.0
当红影后橙光破解版是一款超级好玩的娱乐圈题材的橙光游戏,在这
忽然成了万人迷清软完结版 无限鲜花版v12.15
忽然成了万人迷破解版是一款非常好玩的男性向橙光游戏,在有一天