Java-Apache connect Tomcat with Perl and Awstats

1,工具

apache_2.2.8-win32-x86-openssl-0.9.8g.msi

Apache是世界使用排名第一的Web服务器软件。集成Perl (“实用报表提取语言”)处理模块

apache-tomcat-6.0.18

TomcatApache 软件基金会(Apache SoftwareFoundation)的Jakarta 项目中的一个核心项目

ActivePerl-5.12.2.1203-MSWin32-x86-294165.zip

一款可以执行Perl程序的工具软件。

Awstats

AWStats是在Sourceforge上发展很快的一个基于PerlWEB日志分析工具

2,安装

APACHE服务器端:

apache_2.2.8-win32-x86-openssl-0.9.8g.msi安装于C:\Program Files路径下。如果使用的是本文提到的apache版本,安装成功后,可直接用文件包中所带的Apache SoftwareFoundation覆盖,以简化操作。

ActivePerl-5.12.2.1203-MSWin32-x86-294165.zip

解压后,运行文件,一直点下一步,会安装在C:\

Awstats直接复制在C:\ProgramFiles

 

WEB项目服务器端:

apache-tomcat-6.0.18直接复制在C:\

 

3,配置

服务器端:

Apache配置:

 

将文件包中的mod_jk-1.2.30-httpd-2.2.3.so复制到C:\Program Files\Apache SoftwareFoundation\Apache2.2\modules下。

mod_jk 也叫 JK,这是一款 Apache/IIS 用来连接后台Tomcat的模块,支持集群和负载均衡。

----------------------------------------------------------------

将文件包中的mod_jk.confworkers.properties复制到C:\Program Files\ApacheSoftware Foundation\Apache2.2\conf下。

mod_jk.conf

#setupthe workers.properties file path, default prefix path is httpd'shome (/usr/local/httpd)

JkWorkersFile conf/workers.properties

JkLogFile  logs/jk.log

JkShmFile  logs/jk-runtime-status

JkLogLevel error

JkLogStampFormat "[%a %b %d %H:%M:%S %Y]"

JkOptions +ForwardKeySize +ForwardURICompat-ForwardDirectories

JkRequestLogFormat "%w %V %T"

 

#SampleJkMounts.  Replacethese with the paths you would

# liketo mount from your JSP server.

#syntax: JkMount ${URL_DIR}/*.jspworker_name

#JkMount /project1/*.jsp jsp-ap207

#JkMount /project2/*.jsp jsp-ap207

JkMount /*loadbalancer

JKUnmount /*.plloadbalancer

JKUnmount /awstatsicons/*loadbalancer

JKUnmount /awstatsclasses/*loadbalancer

JKUnmount /awstatscss/*loadbalancer

workers.properties

#這裡是關鍵,名字要和httpd.conf的一致。如果這裡改了httpd.conf也要改。

ps=\

worker.list=tomcat1,loadbalancer

 

#工作端口,tomcatjk監聽端口,可以查看Tomcat Server.xml中有port="8009"protocolHandlerClassName="org.apache.jk.server.JkCoyoteHandler"這樣的Connector

worker.tomcat1.port=8080

 

#Tomcat所在機器,如果安裝在與apache不同的機器則需要設置IP

worker.tomcat1.host=10.57.145.9

 

#類型,ApacheTomcat之間傳遞使用的協議

worker.tomcat1.type=ajp13

 

#代理數

worker.tomcat1.lbfactor=1

 

worker.loadbalancer.type=lb

worker.loadbalancer.balanced_workers=tomcat1

worker.loadbalancer.sticky_session=1

 

红色部分:apache接收客户端请求,mod_jk.conf所指定的URL类型(JkMount /* loadbalancer),交由workers.properties所指定的负载平衡工作器(tomcat,指定IP地址和端口号)处理。多工作器配置方面可参考文件包other下的workers.properties

JKUnmount /*.plloadbalancer

JKUnmount /awstatsicons/*loadbalancer

JKUnmount /awstatsclasses/*loadbalancer

JKUnmount /awstatscss/*loadbalancer

则由apache本身自己处理。

----------------------------------------------------------------

 

接下来,进行apache服务的参数配置。

(这部分比较复杂,最好是直接用文件包中所带的Apache SoftwareFoundation覆盖apache安装目录,然后在httpd.conf里修改,以简化操作。这样,需要修改的其实就只是ServerNameListen,即apache机器名称和监听端口

 

打开C:\Program Files\Apache SoftwareFoundation\Apache2.2\conf下的httpd.conf

在这里,我们设apache监听的端口号为默认,即Listen 80

这样,客户端访问的URL应为:http://apache服务器IP/tomcat项目名

----------------------------------------------------------------

 

添加LoadModule jk_modulemodules/mod_jk-1.2.30-httpd-2.2.3.soctrl+f找到LoadModule群组位置,复制于LoadModule群组位置最末即可)。这样,就为apache启动了JK模块。

----------------------------------------------------------------

 

设置ServerName

ServerName apache服务器电脑名称:80

----------------------------------------------------------------

 

设置日志格式:

    #

    #The location and format of the access logfile (Common LogfileFormat).

    #If you do not define any access logfiles within a<VirtualHost>

    #container, they will be loggedhere.  Contrariwise,if you *do*

    #define per-<VirtualHost> accesslogfiles, transactions will be

    #logged therein and *not* in this file.

    #

    #CustomLog"logs/access.log" common

CustomLog "|bin/rotatelogs.exe -llogs/access%Y-%m-%d.log 86400" combined

    #

    #If you prefer a logfile with access, agent, and refererinformation

    #(Combined Logfile Format) you can use the followingdirective.

    #

    #CustomLog"logs/access.log" combined

</IfModule>

 

----------------------------------------------------------------

 

设置apache可解析perlAWStats網站的權限設定

<IfModulealias_module>

    #

    #Redirect: Allows you to tell clients about documents that usedto

    #exist in your server's namespace, but do not anymore. Theclient

    #will make a new request for the document at its newlocation.

    #Example:

    #Redirect permanent /foo http://dps.com/bar

 

    #

    #Alias: Maps web paths into filesystem paths and is usedto

    #access content that does not live under theDocumentRoot.

    #Example:

    #Alias /webpath /full/filesystem/path

    #

    #If you include a trailing / on /webpath then the serverwill

    #require it to be present in theURL.  Youwill also likely

    #need to provide a <Directory> sectionto allow access to

    #the filesystem path.

 

    #

    #ScriptAlias: This controls which directories contain serverscripts.

    #ScriptAliases are essentially the same as Aliases, exceptthat

    #documents in the target directory are treated as applicationsand

    #run by the server when requested rather than as documents sent tothe

    #client.  Thesame rules about trailing "/" apply toScriptAlias

    #directives as to Alias.

    #

    ScriptAlias/cgi-bin/ "C:/Program Files/Apache SoftwareFoundation/Apache2.2/cgi-bin/"

#以下四行是設定AWStats之資源

   Alias /awstatsclasses "C:/ProgramFiles/Awstats/wwwroot/classes"

    Alias/awstatscss "C:/ProgramFiles/Awstats/wwwroot/css

    Alias/awstatsicons "C:/ProgramFiles/Awstats/wwwroot/icon"

    ScriptAlias/awstats/ "C:/ProgramFiles/Awstats/wwwroot/cgi-bin/"

</IfModule>

 

<IfModulecgid_module>

    #

    #ScriptSock: On threaded servers, designate the path to theUNIX

    #socket used to communicate with the CGI daemon ofmod_cgid.

    #

    #Scriptsocklogs/cgisock

</IfModule>

#使apache可解析perl,需要先安裝ActivePerl

ScriptInterpreterSourceregistry

#

# "C:/Program Files/Apache SoftwareFoundation/Apache2.2/cgi-bin" should be changed to whatever yourScriptAliased

# CGI directory exists, if you havethat configured.

#

<Directory "C:/ProgramFiles/Apache SoftwareFoundation/Apache2.2/cgi-bin">

    AllowOverrideNone

    OptionsNone

    Orderallow,deny

    Allow from all

</Directory>

#對於AWStats網站的權限設定

<Directory "C:/ProgramFiles/Awstats/wwwroot">

    OptionsFollowSymLinks +ExecCGI

AddHandler cgi-script.pl

AllowOverrideNone

#XAMPP

Orderdeny,allow

Allow fromall

#Deny fromall

</Directory>

----------------------------------------------------------------

 

添加JK配置:

Includeconf/mod_jk.conf

----------------------------------------------------------------

 

Awstats配置:

C:\ProgramFiles\Awstats\wwwroot\cgi-bin目录下,

编辑awstats.10.57.145.9.confawstats. apache服务器IP或是域名.conf

指定加载的日志文件:

LogFile="C:/Program Files/Apache SoftwareFoundation/Apache2.2/logs/access%YYYY-%MM-�.log"

----------------------------------------------------------------

 

设置awstats访问地址(apache服务器IP或域名,当然,前提是awstatsapache安装在同一台机器上)

SiteDomain="10.57.145.9"

HostAliases="localhost 127.0.0.1 10.57.145.9dps"

----------------------------------------------------------------

 

编辑autoupdate_awstats.cmd(执行这个文件,将会产生新的类似于awstats032011.10.57.145.9.txttxt文件,数据来源于apache的日志文件。)
perl"C:\Program Files\Awstats\wwwroot\cgi-bin\awstats.pl"-config=10.57.145.9 –update

-config=apache服务器IP,或是域名(如果有的话)

----------------------------------------------------------------

 

WEB项目服务器端

Tomcat:设置AJP通信端口

C:\apache-tomcat-6.0.18\confserver.xml

<!-- Define an AJP 1.3 Connectoron port 8009 -->

     <Connectorport="8009" protocol="AJP/1.3" redirectPort="8443"URIEncoding="UTF-8"/>

 

4,排定工作:

前面说到,执行autoupdate_awstats.cmd文件,将会产生新的类似于awstats032011.10.57.145.9.txttxt文件(报表的数据来源)

当然,也可以在WINDOWS下,设定自动运行。

打开控制台-排定工作-新增排定的工作,选定autoupdate_awstats.cmd,设置执行时间即可。

 

5,访问

前提,执行完上述所有内容。重启apachetomcat(项目需已部署上去)。

访问报表:http:// apache服务器IP或域名/awstats/awstats.pl?config= apache服务器IP或域名

访问项目:http://apache服务器IP或域名/tomcat服务器下的项目名/


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值