然后设置tomcat
修改tomcat的conf中的
server.xml
这里面主要是配置你项目和日志分析系统的发布目录和日志生成的格式,
<ValveclassName="org.apache.catalina.valves.FastCommonAccessLogValve"directory="logs" prefix="access_test_log." suffix=".log"pattern="combined" resolveHosts="false"fileDateFormat="yyyy-MM-dd" />(每天生成前一天的日志用)
可以根据你自己的需要配置,不多说了。在附件里面有这个配置文件。
context.xml
<Context privileged="true"> <!-- Default set of monitored resources --> <WatchedResource>WEB-INF/web.xml</WatchedResource> <!-- Uncomment this to disable session persistence across Tomcat restarts --> <!-- <Manager pathname="" /> --> <!-- Uncomment this to enable Comet connection tacking (provides events on session expiration as well as webapp lifecycle) --> <!-- <Valve className="org.apache.catalina.valves.CometConnectionManagerValve" /> --> </Context>
web.xml
主要为了支持cgi
<servlet><servlet-name>cgi</servlet-name><servlet-class>org.apache.catalina.servlets.CGIServlet</servlet-class><init-param><param-name>debug</param-name><param-value>0</param-value></init-param><init-param><param-name>cgiPathPrefix</param-name><param-value>WEB-INF/cgi</param-value></init-param><load-on-startup>5</load-on-startup></servlet><servlet-mapping><servlet-name>cgi</servlet-name><url-pattern>/cgi-bin/*</url-pattern></servlet-mapping>
如果你的这个日志分析系统需要用户权限控制,可以在web.xml中添加
<!-- Define reference to the user database for looking up roles --><resource-env-ref><description>Awstats status</description><resource-env-ref-name>users</resource-env-ref-name><resource-env-ref-type>org.apache.catalina.UserDatabase</resource-env-ref-type></resource-env-ref><!-- Define a Security Constraint on this Application --><security-constraint><web-resource-collection><web-resource-name>awstats statics</web-resource-name><url-pattern>/cgi-bin/*</url-pattern></web-resource-collection><auth-constraint><!-- NOTE: This role is not present in the default users file --><role-name>AwstatsAdmin</role-name></auth-constraint></security-constraint><!-- Define the Login Configuration for this Application --><login-config><auth-method>BASIC</auth-method><realm-name>Awstats status</realm-name></login-config><!-- Security roles referenced by this web application --><security-role><description>leon</description><role-name>AwstatsAdmin</role-name></security-role>
然后再tomcat-users.xml中加,
<tomcat-users><role rolename="AwstatsAdmin" /><user username="admintest" password="testtest" roles="AwstatsAdmin" /></tomcat-users>
重启服务,可以直接通过http://localhost:8080/awstats/cgi-bin/awstats.pl?config=www.test.com访问
tomcat 的日志配置成按照每24小时生成一个日志文件的原则,但是有个问题是每个日志文件记录的时间是从每天的早晨八点钟到第二天的八点钟。这样的话我的awstats自动统计程序最好在每天早晨七点59分开始运行,crontab配置如下:
58 7 * * * root /home/webapps/awstats/awstats/WEB-INF/cgi/awstats.pl -update -config=test
我的linxu不知道为什么,不自动执行,所以直接将命令写成脚本,并且定时运行这个脚本才可以
新建一个.sh的文件,然后添加/home/webapps/awstats/awstats/WEB-INF/cgi/awstats.pl -update -config=test
在crontab -e中添加任务,每天凌晨一点十分执行
10 1 * * * /bin/sh /home/crontab1/awstats.sh