文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>squid的mysar实现

squid的mysar实现

时间:2010-05-23  来源:lwtcn

一、下载程序

http://giannis.stoilis.gr/software/mysar

 

http://downloads.sourceforge.net/project/mysar/mysar/2.1.4/mysar-2.1.4.tar.gz

tar zxvf mysar-2.1.1.tar.gz -C /usr/local

 

二、修改apache的配置

#vi /usr/local/apache2/conf/httpd.conf

Alias /mysar /usr/local/apache2/htdocs/mysar
<Directory "/usr/local/apache2/htdocs/mysar ">
Options Indexes FollowSymLinks
AllowOverride authconfig
Order allow,deny
Allow from all
</Directory>

 

#ln -s /usr/local/mysar/www /usr/local/apache2/htdocs/mysar

#/usr/local/apache2/bin/apachectl restart

 

由于网页里面有administrator的权限,可以修改日志保存的数量,还有其他的一些参数设置。所以这里网页的访问,最好加个密码认证。

 

#cd /usr/local/apache2/htdocs/mysar

# vi /usr/local/apache2/htdocs/mysar/.htaccess

AuthType Basic

AuthName "请输入用户名和密码"

AuthUserFile /usr/local/apache2/htdocs/mysar/passwords
Require valid-user

 

#htpasswd -c /usr/local/apache2/htdocs/mysar/passwords adminmysar

重复输入2次密码:2010mysar

#/usr/local/apache2/bin/apachectl restart

 

三、从网站安装mysar

http://it.webwiner.cn/mysar/

访问网站,安装!

 

#vi /usr/local/mysar/etc/config.ini

dbUser = mysar
dbPass = mysarjf
dbHost = localhost
dbName = mysar

如果,因为apache的用户权限问题,不能写进文件,可以按照上述格式,直接写文件。

这个安装的程序做的比较人性化,提示跟退回都做的不错。应该不难安装。

安装成功后,将install目录删除或者mv另一个文件目录名字

#mv /usr/local/apache2/htdocs/mysar/install  /usr/local/apache2/htdocs/mysar/installover

 

这个时候可以访问网站:

http://it.webwiner.cn/mysar/

进入:administration的栏目,去修改:

Cient DNS resolving is的选项,disabled

 

四、添加squid的access记录到数据库

把squid的access.log的记录加入数据库的2种办法:

(一)、php的办法

#cat /usr/local/mysar/etc/mysar.cron

这个mysar.cron里面提到的3个文件,好像就一个重要点。

 

首先修改每个文件的开始部分:

修改成:

#!/usr/local/php/bin/php

 

 

三个程序,目前我的认识如下:

1、mysar-resolver.php

#/usr/local/mysar/bin/mysar-resolver.php

这个一般用不到,除非你的客户端的用户,每个都有dns名字对应的。

所以这个不要执行。

如果执行了也是提醒你:

esolving is NOT enabled. Exiting...

 

#/usr/local/mysar/bin/mysar-maintenance.php

这个不是很清楚,是做什么的。

Optimizing config...

Optimization finished.

Optimizing hostnames...

Optimization finished.

Optimizing sites...

Optimization finished.

Optimizing traffic...

Optimization finished.

Optimizing trafficSummaries...

Optimization finished.

Optimizing users...

Optimization finished.

 

感觉是定义一些,usrs什么的,平时不要运行!

 

 

#/usr/local/mysar/bin/mysar-importer.php

这个是把access.log记录写进数据库的,可能是使用php的方式,所以执行时间比较长,要留一点时间的,不然这个程序还没结束就运行,/usr/local/squid/sbin/squid -k rotate的话会有问题的。

 

#crontab –e

30 23 * * * /usr/local/mysar/bin/mysar-importer.php

0  0 * * * /usr/local/squid/sbin/squid -k rotate

 

ln -s /usr/local/mysar/etc/mysar.cron /etc/cron.d/mysar

这个就不加了!

 

 

(2)、c语言的办法

#cd /home/soft/squid/mysar/bin/mysar-binary-importer/

#./configure --prefix=/usr --sysconfdir=/etc

#make

#make install

vi /etc/mysar.conf

username=mysar

password=mysarjf

database=mysar

server=localhost

pidfile=/tmp/mysar.pid

logfile=/var/log/squid/access.log

 

#/usr/bin/mysar

MySAR 2.1.4 Log importer, 32 bit Version

Copyright 2007 Cassiano Martin

 

 

DNS name resolver is disabled. hosts will show up only IP addresses on report.

 

Last Database cleanup performed on 2010-05-19

History keep days: 60

Current Date 2010-05-19

Loading plain text log file...

 

Freeing statements....

Total runtime: 316 seconds. Processed: 730837 Imported: 724594 Read errors: 0

一共执行了6分钟的时间,建议采用c语言编译的方式,去更新数据库。

后来我又运行了2次:

#/usr/bin/mysar

Total runtime: 0 seconds. Processed: 137 Imported: 137 Read errors: 0

#/usr/bin/mysar

Total runtime: 0 seconds. Processed: 16 Imported: 16 Read errors: 0

发现他有更新的功能,非常好前面处理过的记录,是不要处理的。

所以,在crontab中建议,每一个小时运行一次。

 

#crontab –e

40 * * * * /usr/bin/mysar

0  0 * * * /usr/local/squid/sbin/squid -k rotate

 

秀一下我的mysar网页:

上面的图根据用户的下载大小排序。

上面的图根据用户访问的网站数量排序。

可以根据用户访问的网站人数进行排序。

上面这个图是列出了公司访问http://tipsimage2.qq.com的用户ip的排序,同时还能看到他们访问这个网站的流量

上述图就是根据内网当天访问流量多少的网站的排序!

 

 

 

最后附加/usr/bin/mysar的参数:

 

--resolver                      this enables the DNS resolver

--noresolver                    this disables the DNS resolver

--traffic                       enable full traffic import from logfile

--notraffic                     disable full traffic import. navigation details wont be imported.

--zip           <file>          load a gzipped logfile for importing.

--logfile       <file>          load a different plain text logfile.

--debug                         enable some debug functionality. useful to find obscure problems.

--config        <file>          load an alternative configuration file, instead of /etc/mysar.conf

--help                          show the help, with command line options.

--generatedb                    shows the database creator. create or replace MySAR databases.

--stats                         show records status when importing.

--optimizedb                    force database optimize. the importer quits afer finish.

--quiet                         does not show any message. all error messages are logged within syslog.

--kill                          send a kill signal to a running importer. the running importer will shutdown

                                and save its runtime states. the new launched importer will continue the job.

 

--groupdomains                  group domains on the site viewer. instead of showing each URL for the domain,

                                it will sum all traffic size, and display the main domain on site viewer.

                                details will show its sub-domains, and so on.

 

--offline                       this will make the importer read the log file, and do not check for timestamps.

                                useful when importing old logfiles. It will not update any timestamps from the

                                last import. It will only insert data on the database and quit. be careful

                                to not import twice the same file, or all traffic and summaries will be duplicated!

 

                                For offline mode work, you should specify a logfile. can be either plain text, or

                                gzipped. If you dont specify --zip or --logfile it will not run, and show an error.

 

相关阅读 更多 +
排行榜 更多 +
单挑幸存者安卓版

单挑幸存者安卓版

飞行射击 下载
决战战地指挥官

决战战地指挥官

飞行射击 下载
鸡仔幸存者最新版

鸡仔幸存者最新版

飞行射击 下载