发布网友 发布时间:2022-04-19 18:33
共1个回答
热心网友 时间:2023-06-26 18:57
yum install -y epel-release && yum clean all &&yum makecache
yum install -y perl-DBD-SQLite perl-Term-ReadLine-Gnu -y
#下载asql包。汉字换成字符。或者安装到系统中
wget https冒号//steve点fi/Software/asql/asql-1点7点tar点gz
tar xvfvz asql-1.7.tar.gz
cd asql-1.7/bin/
#在终端直接敲./asql 进入程序
./asql
#安装方法为
cd asql-1.7 && make install
#################
#source 为客户端IP
#date 为日期
#status 为 HTTP状态代码,200 正常,403禁止访问,404未找到 等等
#request 为访问的具体文件
#size 为客户端请求的数据量(或者是数据传输量)。
#####################
#载入日志文件,路径为log文件所在路径。
#debian like
asql> load /var/log/apache2/access.*
#centos/rhel like
sql> load /var/log/httpd/access_log*
# root @ konvicts in ~/asql-1.7/bin [12:38:04]
$ ./asql
Name "Regexp::IPv6::IPv6_re" used only once: possible typo at ./asql line 1534.
asql v1.7 - type 'help' for help.
asql> load /home/wwwlogs/access.log
Loading: /home/wwwlogs/access.log
asql>
#查询制定时间段的客户端IP (今年6月25号凌晨0点以后的客户端IP)
SELECT source, date, status FROM logs WHERE date >= '2017-06-25T00:00:00' ORDER BY source;
asql> SELECT source, date, status FROM logs WHERE date >= '2017-06-27T00:00:00' ORDER BY source
107.150.7.240 2017-06-27T00:13:32 200
107.150.7.240 2017-06-27T00:13:33 499
107.150.7.240 2017-06-27T04:08:23 499
111.162.144.4 2017-06-27T00:13:34 200
123.125.71.105 2017-06-27T04:08:23 200
#以降序显示每个客户端提供的请求的总大小(以字节为单位)
select source,SUM(size) AS Number FROM logs GROUP BY source ORDER BY Number DESC;
asql> select source,SUM(size) AS Number FROM logs GROUP BY source ORDER BY Number DESC;
123.117.42.214 6323311
123.117.46.50 5242111
111.200.229.2 5160965
107.150.7.240 1116391
111.162.144.4 21683
111.162.147.249 21683
111.162.156.21 3433
111.162.145.213 1668
111.162.158.255 1668
178.173.156.79 398
123.125.71.105 67
#保存数据到一个文件
save test.2017-06-28
#载入已存数据到一个新的asql会话
restore test.2017-06-28
#筛选 404错误,并用日期排序
SELECT source,date,status,request FROM logs WHERE status='404' ORDER BY date
asql> select source,date,status,request FROM logs WHERE status='404' ORDER BY date
123.28.54.69 2017-06-23T16:21:06 404 /favicon.ico