lizongbo at 618119.com 工作,生活,Android,前端,Linode,Ubuntu,nginx,java,apache,tomcat,Resin,mina,Hessian,XMPP,RPC

2008年01月5日

geoserver与OpenLayers配置入门

Filed under: Java — 标签:, , , — lizongbo @ 13:10

geoserver与OpenLayers配置入门

Word文档在: http://618119.com/docs/gis/geoserver_OpenLayers_Config.doc

因工作需要,这几天早对webgis进行摸索,总结如下:

2008年1月

目录

1    准备工作    4
1.1    需要用到的程序和资料    4
2    地图格式转换方式(一)    5
3    地图格式转换方式(二)    5
3.1    解压地图    5
3.2    打开地图    5
3.3    导出图层    6
3.4    转换MIF格式为SHP格式    6
4    GEOSERVER安装配置    6
4.1    GEOSERVER安装    6
4.2    配置地图    6
4.2.1    登录geoserver    7
4.2.2    配置数据    7
4.2.3    新建数据集    8
4.2.4    新建Feature Type    10
4.2.5    应用保存配置    12
4.2.6    访问地图    15
5    OPENLAYERS配置    16
5.1    测试页面    16
5.2    部署示例    21
5.3    查看效果    21
5.4    加上GOOGLEMAP图层    21
5.4.1    申请Google 地图 API 的key    21
5.4.1.1    将域名映射到本地    21
5.4.2    编辑html    22
5.4.3    查看效果    22
6    GEOSERVER高级设置    23
6.1    自定义图层的STYLE    23
6.2    查看图层的字段信息    26
6.3    在TOMCAT上部署GEOSERVER    27
6.4    自定义名称空间    28
7    参考资料    31

1 准备工作
相关资料文件下载
1.1 需要用到的程序和资料

1. JDK 1.6 :
http://www.mnidc.net/software/java_se/jdk-6u3-windows-i586-p.exe
安装好JDK1.6
2. MapInfo Professional 6.4 SCP中文版或者8.5 SCP英文版
安装好Mapinfo
3. geoserver 1.5.4 或者 1.6.0 Rc2
http://superb-east.dl.sourceforge.net/sourceforge/geoserver/geoserver-1.5.4a.bin.zip
http://jaist.dl.sourceforge.net/sourceforge/geoserver/geoserver-1.5.4a.src.zip
http://jaist.dl.sourceforge.net/sourceforge/geoserver/geoserver-1.5.4a.war.zip
http://jaist.dl.sourceforge.net/sourceforge/geoserver/geoserver-1.6.0-RC2-war.zip
http://nchc.dl.sourceforge.net/sourceforge/geoserver/geoserver-1.6.0-RC2-pyramid-plugin.zip
http://nchc.dl.sourceforge.net/sourceforge/geoserver/geoserver-1.6.0-RC2-mysql-plugin.zip
来源: http://docs.codehaus.org/display/GEOS/Download

4. Openalyers 2.5
http://www.openlayers.org/download/OpenLayers-2.5.zip
来源: http://www.openlayers.org/

5. 深圳地图一份
来源: http://www.iseaman.com/down/18/2006/20061106129.html
(这个地图只是局部信息,而且信息两很小,我重新找了份效果还不错的深圳局部地图)

6. 地图格式转换工具
http://www.gissky.com/Download/download/2006/datatransfer.rar
来源:http://www.gissky.com/Download/Showsoft.asp?Type=1&ID=216

7. Apache Tomcat 6.0.14
http://apache.mirror.phpchina.com/tomcat/tomcat-6/v6.0.14/bin/apache-tomcat-6.0.14.zip
http://apache.mirror.phpchina.com/tomcat/tomcat-6/v6.0.14/src/apache-tomcat-6.0.14-src.zip
来源:?http://tomcat.apache.org/

2 地图格式转换方式(一)
Mapinfo 8.5中,主菜单 –> Tools –>Universal Translator–> Universal Translator
MapInfo6.5中,主菜单–> Tools –>工具–>通用转换器–>通用转换器。
(或者进入 D:\Program Files\MapInfo\Professional\UT,运行IMUTGUI.EXE)
选择源文件格式,选择多个源文件,再选择输出文件夹,点 ok开始进行转换,
IMUTGUI.exe实际是调用 IMUT.exe来进行文件转换的。

对于字段名为中文的,需要先将字段名修改掉,否则编写Style的时候用中文字段可能无法正确读取
修改方法如下:
先打开地图,然后:
主菜单—>Window –> New browser Window(快捷键为F2),打开指定的表,
主菜单选择Browse (浏览) >Pick Fields (选取字段), Pick Fields对话框显示出来。
(我照上面没改出来,我是用转换方式二,先导出成mif文件,然后再用文本编辑器打开mif文件。直接改的字段名)
Update:最后知道了正确的改字段名的方法:
主菜单–>表–> 维护–>表结构–>选择需要修改的表–>选中字段,在字段名输入新的字段名即可.
实际对应的MapBasic为: Alter Table “Bguangdong” ( rename Kind Kindaaa ) Interactive

3 地图格式转换方式(二)
(该步操作是我走的弯路,仅做记录以备忘)
3.1 解压地图
解压深圳地图到 E:\gis\深圳
3.2 打开地图
启动Mapinfo,打开E:\gis\深圳下面所有图层

3.3 导出图层
主菜单–>Table–>Export–>选择要导出的图层,点Export.将图层导出为mif格式的文件。
3.4 转换mif格式为shp格式
运行datatransfer.exe,选择格式和文件,进行转换。
4 GeoServer安装配置
4.1 GeoServer安装
解压geoserver-1.5.4a.bin.zip到 E:\gis\geoserver,
运行E:\gis\geoserver\bin\startup.bat
4.2 配置地图
打开浏览器,访问:http://localhost:8080/geoserver/

4.2.1 登录geoserver
点“配置”,在登录界面输入用户名 ‘admin’,密码’geoserver’

4.2.2 配置数据
登录成功之后,再点“配置”。在配置界面,点“数据”。

在数据配置界面,点“数据库”。

4.2.3 新建数据集
在Feature数据集配置界面,点“新建”

在新建界面,Feature 数据描述类型,选择Shaperfile,Feature数据集ID,输入“szmap_bingguanjiudian”,点“新建”

(此时,由于地图信息还没部署,因此,先将shape格式的数据文件复制到E:\gis\geoserver\data_dir\data\szmapnew。)

在数据文件配置界面中,url填写为:file:data/szmapnew/bingguanjiudian_custom_point.shp
(表示对应E:\gis\geoserver\data_dir\data\szmapnew\bingguanjiudian_custom_point.shp)
Charset填写为:GBK,点“提交”。

4.2.4 新建Feature Type
文件加载成功,进入Feature Type编辑界面,样式选择 point,SRS填写为4326,点生成.

再点“提交”。(千万不要勾上启用缓存,我就是勾上它,结果导致创建的FeaTure Type无法保存,走了弯路)

4.2.5 应用保存配置
然后先点左上角的“应用”,

再点“保存”。

重复上述步骤可配置多个图层。

数据集的信息保存在

E:\gis\geoserver\data_dir\ catalog.xml
featureTypes信息保存在 E:\gis\geoserver\data_dir\featureTypes

catalog.xml内容节选为:

<datastore id = “szmap_jumindi” enabled = “true” namespace = “topp” >
<connectionParams >
<parameter name = “charset” value = “GBK” />
<parameter name = “url” value = “file:data/szmapnew/jumindi_region.shp” />
<parameter name = “namespace” value = “topp” />
</connectionParams>
</datastore>
<datastore id = “szmap_lvdi” enabled = “true” namespace = “topp” >
<connectionParams >
<parameter name = “charset” value = “GBK” />
<parameter name = “url” value = “file:data/szmapnew/lvdi_region.shp” />
<parameter name = “namespace” value = “topp” />
</connectionParams>
</datastore>
<datastore id = “szmap_shangsha” enabled = “true” namespace = “topp” >
<connectionParams >
<parameter name = “charset” value = “GBK” />
<parameter name = “url” value = “file:data/szmapnew/shangsha_font_point.shp” />
<parameter name = “namespace” value = “topp” />
</connectionParams>
</datastore>
<datastore id = “szmap_danwei” enabled = “true” namespace = “topp” >
<connectionParams >
<parameter name = “charset” value = “GBK” />
<parameter name = “url” value = “file:data/szmapnew/danwei_font_point.shp” />
<parameter name = “namespace” value = “topp” />
</connectionParams>
</datastore>
<datastore id = “szmap_bingguanjiudian” enabled = “true” namespace = “topp” >
<connectionParams >
<parameter name = “charset” value = “GBK” />
<parameter name = “url” value = “file:data/szmapnew/bingguanjiudian_custom_point.shp” />
<parameter name = “namespace” value = “topp” />
</connectionParams>
</datastore>
<datastore id = “szmap_jiaotonggandao” enabled = “true” namespace = “topp” >
<connectionParams >
<parameter name = “charset” value = “GBK” />
<parameter name = “url” value = “file:data/szmapnew/jiaotonggandao_region.shp” />
<parameter name = “namespace” value = “topp” />
</connectionParams>
</datastore>
<datastore id = “szmap_daoluzhongxinxian” enabled = “true” namespace = “topp” >
<connectionParams >
<parameter name = “charset” value = “GBK” />
<parameter name = “url” value = “file:data/szmapnew/daoluzhongxinxian_polyline.shp” />
<parameter name = “namespace” value = “topp” />
</connectionParams>
</datastore>
<datastore id = “szmap_dise” enabled = “true” namespace = “topp” >
<connectionParams >
<parameter name = “charset” value = “GBK” />
<parameter name = “url” value = “file:data/szmapnew/dise_region.shp” />
<parameter name = “namespace” value = “topp” />
</connectionParams>
</datastore>
(文件重新加载保存之后,原有的注释说明不见了。)
4.2.6 访问地图
回到首页欢迎界面,点“Mapbuilder 客户端”

找到 topp:bingguanjiudian_custom_point,点 Openlayers。

把地图缩放比例拉到最小,然后点其中一个标注点,网页下面会显示出查询到的信息。

5 Openlayers配置
5.1 测试页面
编写测试页面,内容如下:

<?xml version=”1.0″ encoding=”UTF-8″?>
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Strict//EN” “DTD/xhtml1-strict.dtd”>

<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<title>OpenLayers map preview</title>
<style type=”text/css”>
#map {
width: 800px;
height: 380px;
border: 1px solid black;
}
</style>

<script src=”http://localhost:8080/geoserver/openlayers/OpenLayers.js” type=”text/javascript”>
</script>
<script defer=”defer” type=”text/javascript”>
var map;
var untiled;
var tiled;
function setHTML(response) {
OpenLayers.Util.getElement(‘nodelist’).innerHTML = response.responseText;
};

function init(){
map = new OpenLayers.Map(‘map’, {controls:[], ‘projection’: ‘EPSG:4326’, ‘units’:’degrees’});

OpenLayers.IMAGE_RELOAD_ATTEMPTS = 5;

// setup tiled layer
var bounds = new OpenLayers.Bounds(114.08473735,22.5444392,114.09911765000001,22.5517168)
tiled = new OpenLayers.Layer.WMS(
“topp:danwei_font_point”, “http://localhost:8080/geoserver/wms”,
{
height: ‘380’,
width: ‘800’,
layers: ‘topp:danwei_font_point’,
styles: ”,
srs: ‘EPSG:4326’,
format: ‘image/png’, tiled: ‘true’, tilesOrigin : “114.08473735,22.5444392”
},
{maxExtent: bounds, maxResolution: 5.617304687505209E-5, projection: “EPSG:4326”, buffer: 0}
);
map.addLayer(tiled);
jiaotonggandao_region = new OpenLayers.Layer.WMS(
“topp:jiaotonggandao_region”, “http://localhost:8080/geoserver/wms”,
{
height: ‘392’,
width: ‘800’,
layers: ‘topp:jiaotonggandao_region’,
styles: ”,
srs: ‘EPSG:4326’, transparent: “true”,
format: ‘image/png’, tiled: ‘true’, tilesOrigin : “114.0836293,22.543578500000002”
},
{maxExtent: bounds, maxResolution: 6.49429687499814E-5, projection: “EPSG:4326”, buffer: 0}
);
map.addLayer(jiaotonggandao_region);
daoluzhongxinxian_polyline = new OpenLayers.Layer.WMS(
“topp:daoluzhongxinxian_polyline”, “http://localhost:8080/geoserver/wms”,
{
height: ‘392’,
width: ‘800’,
layers: ‘topp:daoluzhongxinxian_polyline’,
styles: ”,
srs: ‘EPSG:4326’, transparent: “true”,
format: ‘image/png’, tiled: ‘true’, tilesOrigin : “114.0836293,22.543578500000002”
},
{maxExtent: bounds, maxResolution: 6.49429687499814E-5, projection: “EPSG:4326”, buffer: 0,isBaseLayer:false}
);
map.addLayer(daoluzhongxinxian_polyline);

shangsha_font_point = new OpenLayers.Layer.WMS(
“topp:shangsha_font_point”, “http://localhost:8080/geoserver/wms”,
{
width: ‘800’,
layers: ‘topp:shangsha_font_point’,
styles: ”,
srs: ‘EPSG:4326’,
height: ‘381’,
format: ‘image/png’, transparent: “true”,tiled: ‘true’, tilesOrigin : “114.0838415,22.543650900000003”
},
{maxExtent: bounds, maxResolution: 6.20898437499462E-5, projection: “EPSG:4326”, buffer: 0,isBaseLayer:false}
);
map.addLayer(shangsha_font_point);

//map.addLayer(tiled);
// setup untiled layer

untiled = new OpenLayers.Layer.WMS.Untiled(
“topp:danwei_font_point”, “http://localhost:8080/geoserver/wms”,
{
height: ‘380’,
width: ‘800’,
layers: ‘topp:danwei_font_point’,
styles: ”,
srs: ‘EPSG:4326’,
format: ‘image/png’
},
{maxExtent: bounds, maxResolution: 5.617304687505209E-5, projection: “EPSG:4326”}
);
untiled.ratio=1;
untiled.setVisibility(false, false);
//map.addLayer(untiled);

// setup controls and initial zooms
map.addControl(new OpenLayers.Control.PanZoomBar({div:$(‘nav’)}));
map.addControl(new OpenLayers.Control.MouseDefaults());
map.addControl(new OpenLayers.Control.Scale($(‘scale’)));
map.addControl(new OpenLayers.Control.MousePosition({element: $(‘position’)}));
map.addControl(new OpenLayers.Control.LayerSwitcher());
map.addControl(new OpenLayers.Control.OverviewMap());
map.zoomToExtent(bounds);

// support GetFeatureInfo
map.events.register(‘click’, map, function (e) {
OpenLayers.Util.getElement(‘nodelist’).innerHTML = “Loading… please wait…” + map.layers[0].name;
var url =  map.layers[0].getFullRequestString({
REQUEST: “GetFeatureInfo”,
EXCEPTIONS: “application/vnd.ogc.se_xml”,
BBOX: map.getExtent().toBBOX(),
X: e.xy.x,
Y: e.xy.y,
INFO_FORMAT: ‘text/html’,
QUERY_LAYERS: map.layers[0].params.LAYERS,
FEATURE_COUNT: 50,
layers: ‘topp:danwei_font_point’,
styles: ”,
srs: ‘EPSG:4326’,
WIDTH: map.size.w,
HEIGHT: map.size.h},
http://localhost:8080/geoserver/wms”
);
OpenLayers.loadURL(url, ”, this, setHTML, setHTML);
Event.stop(e);
});
}
</script>
</head>

<body onload=”init()”>
<table>
<tr>
<td style=”width:40px” valign=”middle” rowspan=”3″><div id=”nav”></div></td>
<td colspan=”3″ align=”right”>
<!– Switch layers when links are pressed –>
<a id=”untiledLink” href=”#” onclick=”map.removeLayer(tiled);map.addLayer(untiled)”>Untiled</a>
<a id=”tiledLink” href=”#” onclick=”map.removeLayer(untiled);map.addLayer(tiled);”>Tiled</a>
</td>
</tr>
<tr>
<td colspan=”3″><div id=”map”></div></td>
</tr>
<tr>
<td><div id=”scale”></div></td>
<td/>
<td align=”right”><div id=”position”></div></td>
</tr>
</table>
<div id=”nodelist”>Click on the map to get feature infos</div>
</body>
</html>
5.2 部署示例
将该页面保存到E:\gis\geoserver\webapps\geoserver\5.htm
5.3 查看效果
访问 http://localhost:8080/geoserver/5.htm 拖动图层,并可点击数据

5.4 加上googlemap图层
5.4.1 申请Google 地图 API 的key
http://www.google.com/intl/zh-CN/apis/maps/signup.html
申请的url填写为: http://www.618119.com:8080/

5.4.1.1 将域名映射到本地
编辑hosts文件,将www.618119.com映射为127.0.0.1.否则在本地加载不了google map.

5.4.2 编辑html
参考 E:\gis\tools\OpenLayers\examples\google.html
增加 google map的js引用
<script src=”http://maps.google.com/maps?file=api&amp;v=2&amp;key=yourkey”
type=”text/javascript”></script>

增加图层
var googlesatellite = new OpenLayers.Layer.Google( “Google Satellite” , {type: G_SATELLITE_MAP, ‘maxZoomLevel’:18} );
map.addLayers([googlesatellite]);

var googlebybrid = new OpenLayers.Layer.Google( “Google Hybrid” , {type: G_HYBRID_MAP });

map.addLayers([googlebybrid]);
var GMapsStreets = new OpenLayers.Layer.Google( “Google Steets” , {type: G_NORMAL_MAP, ‘maxZoomLevel’:18} );

map.addLayers([GMapsStreets]);

5.4.3 查看效果
从图上可以看出mapinfo地图数据和google的卫星照片没有对齐。

6 GeoServer高级设置
6.1 自定义图层的Style
参考E:\gis\geoserver\data_dir\styles\ poi.sld,我自己定义了一个mypoi的样式,但是由于geoserver直接显示中文存在问题,于是先将显示的名称定义成了拼音。

Mypoi.sld的内容如下:
<?xml version=”1.0″ encoding=”UTF-8″?>
<StyledLayerDescriptor version=”1.0.0″
xsi:schemaLocation=”http://www.opengis.net/sld StyledLayerDescriptor.xsd”
xmlns=”http://www.opengis.net/sld” xmlns:ogc=”http://www.opengis.net/ogc”
xmlns:xlink=”http://www.w3.org/1999/xlink”
xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance”>
<NamedLayer> <Name> poi </Name>
<UserStyle>

<FeatureTypeStyle>

<!– all the same –>

<Rule>

<PointSymbolizer>
<Graphic>
<Mark>
<WellKnownName>circle</WellKnownName>
<Fill>
<CssParameter name=”fill”>#FF0000</CssParameter>
<CssParameter name=”fill-opacity”>1.0</CssParameter>
</Fill>
</Mark>
<Size>11</Size>
</Graphic>

</PointSymbolizer>

<PointSymbolizer>
<Graphic>
<Mark>
<WellKnownName>circle</WellKnownName>
<Fill>
<CssParameter name=”fill”>#EDE513</CssParameter>
<CssParameter name=”fill-opacity”>1.0</CssParameter>
</Fill>
</Mark>
<Size>7</Size>
</Graphic>

</PointSymbolizer>
<TextSymbolizer>
<Label>
<ogc:PropertyName>PY</ogc:PropertyName>
</Label>

<Font>
<CssParameter name=”font-family”>Arial</CssParameter>
<CssParameter name=”font-style”>Normal</CssParameter>
<CssParameter name=”font-size”>14</CssParameter>
</Font>
<Fill>
<CssParameter name=”fill”>#000000</CssParameter>
</Fill>
</TextSymbolizer>

</Rule>

</FeatureTypeStyle>
</UserStyle>
</NamedLayer>
</StyledLayerDescriptor>

在FeatureType 配置中修改样式为:mypoi,然后点应用,再点保存,即可生效,下面是深圳地图的显示效果。

经过再次试验,将字体信息去掉,反而可以显示中文了,修改后的节选

<TextSymbolizer>
<Label>
<ogc:PropertyName>Name</ogc:PropertyName>
</Label>
<Font>
<CssParameter name=”font-style”>Normal</CssParameter>
<CssParameter name=”font-size”>14</CssParameter>
</Font>
<Fill>
<CssParameter name=”fill”>#0000ff</CssParameter>
</Fill>
</TextSymbolizer>

显示效果为:

6.2 查看图层的字段信息
在FeatureType 编辑器的最下方,可以看到该图层是字段信息,在写Style的时候,将使用到这些字段名,严格区分大小写。

将字段名改成英文之后,重新配置Style,
Style节选:
<TextSymbolizer>
<Label>
<ogc:PropertyName>NAME</ogc:PropertyName>
</Label>

<Font>
<CssParameter name=”font-style”>italic,bold</CssParameter>
<CssParameter name=”font-size”>14</CssParameter>
</Font>
<Fill>
<CssParameter name=”fill”>#FF0000</CssParameter>
</Fill>
</TextSymbolizer>

效果如下(中间有块图是google的没加载上):

6.3 在Tomcat上部署GeoServer
解压Tomcat到 E:\gis\apache-tomcat-6.0.14
将geoserver-1.6.0-RC2-war.zip中的geoserver.war解压到
E:\gis\apache-tomcat-6.0.14\webapps\geoserver
为了地图数据安全,将地图数据存放到指定的目录,比如:E:\gis\gisdata
将E:\gis\apache-tomcat-6.0.14\webapps\geoserver\data下的所有文件复制到E:\gis\gisdata,
再用文本编辑器打开,E:\gis\apache-tomcat-6.0.14\bin\ catalina.bat,在开头加上下面一行
set JAVA_OPTS=%JAVA_OPTS% -DGEOSERVER_DATA_DIR=E:/gis/gisdata,
保存catalina.bat.
(下面这行是不行的,实际不是环境变量,而是java的Properties,
set GEOSERVER_DATA_DIR=E:\gis\gisdata)
运行 E:\gis\apache-tomcat-6.0.14\bin\startup.bat来启动Tomcat,

控制太可以看到下面这样的信息:
2008-1-5 11:11:37 org.apache.catalina.core.StandardEngine start
信息: Starting Servlet Engine: Apache Tomcat/6.0.14
05 一月 11:11:44 ERROR [geoserver.global] –
———————————-
– GEOSERVER_DATA_DIR: E:\gis\gisdata
———————————-
log4j:WARN File option not set for appender [geoserverlogfile].
log4j:WARN Are you using FileAppender instead of ConsoleAppender?
05 一月 11:11:50 INFO [geoserver.global] – StdOut logging enabled.  Log file also output to ‘E:\gis\gisdata\logs\geoserver.log’

再浏览器中访问 http://www.618119.com:8080/geoserver,可以看到geoserver已经部署成功。

6.4 自定义名称空间
登录管理界面,配置数据,点“名称空间”。

点“新建”

前缀填写为: szditu,再点新建。

URI填写为: http://618119.com/tag/gis.然后点提交。

再点左上角的应用,再点保存。

将重新制作的深圳地图,复制到 E:\gis\gisdata\data\szditu.

重新配置后的datastore如下:

<datastore id = “Poi_Ashenzhen_point” enabled = “true” namespace = “szditu” >
<abstract>深圳地图兴趣点</abstract>
<connectionParams >
<parameter name = “memory mapped buffer” value = “true” />
<parameter name = “create spatial index” value = “true” />
<parameter name = “charset” value = “GBK” />
<parameter name = “url” value = “file:data/szditu/Poi/Ashenzhen_point.shp” />
<parameter name = “namespace” value = “szditu” />
</connectionParams>
</datastore>

7 参考资料

GeoServer不同服务器安按装配置、数据发布及客户端访问:
http://www.cnblogs.com/salonliudong/archive/2007/04/20/721453.html
Openlayers的 Overlays设置:
http://trac.openlayers.org/wiki/BaseLayersAndOverlays
FeatureTypeStyle参考
http://www.cnblogs.com/xiaotie/archive/2005/08/19/218509.html
Mapinfo的使用:
http://www.cnblogs.com/huhz1979/articles/534691.html

关于gis,重点推荐两个非常有价值的blog
Classicning Daily Log:
http://www.classicning.com/blog/
Java&GIS – BlogJava:
http://www.blogjava.net/siriusfx/

Geoserver 和 OpenLayers

第 31 页 共 30 页

2007年12月7日

在Tomcat 6.0.14中安装配置awstats

Filed under: Apache,DNS,IP,Tomcat — 标签:, , , , — lizongbo @ 18:30

在Tomcat 6.0.x中配置awstats
需要下载的文件有:

perl : http://downloads.activestate.com/ActivePerl/Windows/5.8/ActivePerl-5.8.8.822-MSWin32-x86-280952.msi
来源: http://www.activestate.com/store/activeperl/download/

http://update.cz88.net/soft/qqwry.rar
http://awstats.sourceforge.net/files/awstats-6.8.tar.gz

geoip插件相关:
http://www.maxmind.com/download/geoip/api/pureperl/Geo-IP-PurePerl-1.18.tar.gz
http://www.maxmind.com/download/geoip/database/GeoIP.dat.gz
http://www.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz
http://www.maxmind.com/download/geoip/database/asnum/GeoIPASNum.dat.gz

安装过程可参考

参考: http://blog.zhangjianfeng.com/article/317
PurePerl.pm的安装可参考:
http://topic.csdn.net/u/20070323/11/903dd121-10d8-42d2-b4eb-a6cb60a22e8a.html

其它配置可参考:
http://www.chedong.com/blog/archives/000410.html

http://blogger.org.cn/blog/more.asp?name=chenjiejacky&id=20464

安装perl之后,确认环境变量里PATH有perl的bin目录
Path=E:\oracle\product\10.2.0\client_1\bin;D:\Perl\bin;
D:\Java\jdk1.6.0_03\bin;E:\oracle\product\10.2.0\db_1\bin;
C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;
C:\Program Files\Microsoft SQL Server\80\Tools\BINN

1.为了控制查看awstats的权限,我在
E:\apache-tomcat-6.0.14\conf\tomcat-users.xml的内容配置为:

<?xml version=’1.0′ encoding=’utf-8′?>
<tomcat-users>
<role rolename=”awstats”/>
<user username=”awstats” password=”awstats” roles=”awstats”/>
</tomcat-users>

2.由于权限限制

E:\apache-tomcat-6.0.14\webapps\awstats\META-INF\context.xml,内容为:

<!– tomcat 6.0 need privileged is true for CGIServlet –>
<Context reloadable=”true” privileged=”true” >

</Context>

(注意目录是META-INF,不是WEB-INF)否则启动的时候会出下面的错误信息:

[ERROR]main-org.apache.catalina.startup.HostConfig-Error deploying web application directory awstats
java.lang.SecurityException: Servlet of class org.apache.catalina.servlets.CGIServlet is privileged and cannot be loaded by this web application
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1134)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:981)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4045)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4351)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:525)
at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:920)
at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:883)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:492)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1138)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:311)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:719)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
at org.apache.catalina.core.StandardService.start(StandardService.java:516)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
at org.apache.catalina.startup.Catalina.start(Catalina.java:566)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
3.配置web.xml,增加权限控制
web.xml的内容为:

<?xml version=”1.0″ encoding=”UTF-8″?>
<web-app xmlns=”http://java.sun.com/xml/ns/j2ee” xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xsi:schemaLocation=”http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd” version=”2.4″>
<servlet>
<servlet-name>cgi</servlet-name>
<servlet-class>org.apache.catalina.servlets.CGIServlet</servlet-class>
<init-param>
<param-name>clientInputTimeout</param-name>
<param-value>100</param-value>
</init-param>
<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-bin</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>
<!– Define reference to the user database for looking up roles –>
<resource-env-ref>
<description>
Link to the UserDatabase instance from which we request lists of
defined role names. Typically, this will be connected to the global
user database with a ResourceLink element in server.xml or the context
configuration file for the Manager web application.
</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 status</web-resource-name>
<url-pattern>/cgi-bin/*</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>awstats</role-name>
</auth-constraint>
</security-constraint>
<!– Define the Login Configuration for this Application –>
<login-config>
<auth-method>BASIC</auth-method>
<realm-name>Awstats status,username: awstats,password: awstats</realm-name>
</login-config>
<!– Security roles referenced by this web application –>
<security-role>
<description>
The role that is required to log in to the Manager Application
</description>
<role-name>awstats</role-name>
</security-role>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
</welcome-file-list>
</web-app>

4.调整文件夹目录

E:\APACHE~1.14\webapps\awstats 的目录

007-12-07 18:14 <DIR> .
007-12-07 18:14 <DIR> ..
007-12-07 08:48 <DIR> classes
007-12-07 08:48 <DIR> css
007-12-07 08:48 <DIR> docs
007-12-07 08:48 <DIR> icon
007-12-07 08:49 211 index.jsp
007-12-07 08:48 <DIR> js
007-12-07 08:56 <DIR> logs
007-12-07 08:48 <DIR> META-INF
007-11-24 22:05 6,721 README.TXT
007-12-07 08:47 <DIR> WEB-INF

E:\APACHE~1.14\webapps\awstats\WEB-INF 的目录

2007-12-07 08:47 <DIR> .
2007-12-07 08:47 <DIR> ..
2007-12-07 08:56 <DIR> cgi-bin
2007-12-07 08:47 <DIR> tools
2007-12-07 08:42 2,389 web.xml

E:\APACHE~1.14\webapps\awstats\WEB-INF\cgi-bin 的目录

007-12-07 08:56 <DIR> .
007-12-07 08:56 <DIR> ..
006-02-09 06:26 5,407 awredir.pl
007-12-07 08:56 2,343 awstats.localhost.conf
007-12-07 08:55 2,340 awstats.localhost.conf.bak
007-11-24 03:18 60,544 awstats.model.conf
007-11-24 03:18 556,625 awstats.pl
007-12-07 08:56 13,569 awstats122007.localhost.txt
006-07-27 09:37 1,847 awstatsext.conf
007-12-07 08:56 678 dnscachelastupdate.localhost.hash
007-12-03 12:18 1,079,842 GeoIP.dat
007-09-13 04:08 2,020,543 GeoIPASNum.dat
007-12-03 16:25 25,914,398 GeoLiteCity.dat
007-12-07 08:48 <DIR> lang
007-12-07 08:48 <DIR> lib
007-03-15 14:35 184 perl插件安装说明.txt
007-12-07 08:54 <DIR> plugins
007-12-05 17:58 6,812,739 QQWry.Dat

E:\APACHE~1.14\webapps\awstats\WEB-INF\cgi-bin\plugins 的目录

2007-12-07 08:54 <DIR> .
2007-12-07 08:54 <DIR> ..
2006-02-09 06:26 3,682 clusterinfo.pm
2006-02-09 06:26 2,960 decodeutfkeys.pm
2007-12-07 08:48 <DIR> example
2007-12-07 08:54 <DIR> geo
2006-05-06 11:51 7,203 geoip.pm
2006-02-09 06:26 3,736 geoipfree.pm
2006-09-04 15:04 112,953 geoip_city_maxmind.pm
2006-05-06 11:54 16,885 geoip_isp_maxmind.pm
2006-05-06 11:54 16,919 geoip_org_maxmind.pm
2006-05-06 11:54 22,283 geoip_region_maxmind.pm
2004-01-01 05:41 5,074 graphapplet.pm
2006-02-09 06:26 5,206 hashfiles.pm
2005-02-19 21:50 7,169 hostinfo.pm
2006-02-09 06:26 2,439 ipv6.pm
2005-04-11 05:08 2,501 qqhostinfo.pm
2005-03-28 11:29 7,603 qqwry.pl
2006-02-09 06:26 4,689 rawlog.pm
2006-02-09 06:26 1,890 timehires.pm
2006-02-09 06:26 2,954 timezone.pm
2006-07-30 03:20 8,212 tooltips.pm
2006-02-09 06:26 4,799 urlalias.pm
2006-02-09 06:26 3,616 userinfo.pm

我的awstats.localhost.conf配置如下:

Include=”common.conf”
PageCode=”GB2312″ # UTF-8
LogFile=”E:/apache-tomcat-6.0.14/logs/access.log”
SiteDomain=”618119.com”
LoadPlugin=”decodeutfkeys”
LoadPlugin=”hashfiles”
LoadPlugin=”geoip”
LoadPlugin=”tooltips”
LoadPlugin=”qqhostinfo”
LoadPlugin=”geoip_city_maxmind GEOIP_STANDARD GeoLiteCity.dat”
LoadPlugin=”geoip_org_maxmind GEOIP_STANDARD GeoIPASNum.dat”
LogFormat=1
HostAliases=”localhost 618119.com www.618119.com
DirIcons=”/awstats/icon”
DNSLookup=1
DirData=”.”
DirCgi=”/cgi-bin”
AllowToUpdateStatsFromBrowser=1

Include=”awstatsext.conf”

一个非常有用的参考地址: http://www.antezeta.com/awstats.html

扩展设置:
# form http://www.antezeta.com/awstats.html

ExtraSectionName1=”Google Searches – Top 50″
ExtraSectionCodeFilter1=”200 304″
ExtraSectionCondition1=”REFERER,(.*www\.google.*)”
ExtraSectionFirstColumnTitle1=”Search”
ExtraSectionFirstColumnValues1=”REFERER,p=([^&]+)||REFERER,q=([^&]+)||REFERER,as_p=([^&]+)||REFERER,as_q=([^&]+)”
ExtraSectionFirstColumnFormat1=”<a href=’http://www.google.cn/search?q=%s’ title=’Click to execute search’>%s</a>”
ExtraSectionStatTypes1=PHBL
ExtraSectionAddAverageRow1=0
ExtraSectionAddSumRow1=1
MaxNbOfExtra1=50
MinHitExtra1=1

ExtraSectionName2=”Google crawls – Top 50″
ExtraSectionCodeFilter2=”200 304″
ExtraSectionCondition2=”UA,(.*Googlebot.*)”
ExtraSectionFirstColumnValues2=”URL,(.*)”
ExtraSectionFirstColumnFormat2=”<a href=’http://618119.com%s’ title=’Item Crawled’>%s</a>”
ExtraSectionStatTypes2=PHBL
ExtraSectionAddAverageRow2=0
ExtraSectionAddSumRow2=1
MaxNbOfExtra2=50
MinHitExtra2=1

ExtraSectionName3=”sitemap.xml.gz downloads by Useragent”
ExtraSectionCodeFilter3=”200 304″
ExtraSectionCondition3=”URL,(^\/sitemap\.xml\.gz)”
ExtraSectionFirstColumnTitle3=”UA”
ExtraSectionFirstColumnValues3=”UA,(.*)”
ExtraSectionStatTypes3=HBL
ExtraSectionAddAverageRow3=0
ExtraSectionAddSumRow3=1
MaxNbOfExtra3=10
MinHitExtra3=1

ExtraSectionName4=”Referring Sites by domain – Top 25″
ExtraSectionCodeFilter4=”200 304″
# Filter on ANY REFERER except “mysite”. Change mysite to your domain name.
ExtraSectionCondition4=”REFERER,^(?!http:\/\/www\.618119\.com)”
ExtraSectionFirstColumnTitle4=”Site”
ExtraSectionFirstColumnValues4=”REFERER,^[hH][tT][tT][pP]:\/\/([^\/]+)\/”
ExtraSectionFirstColumnFormat4=”<a href=’http://%s/’ rel=’nofollow’ title=’http://%s/ [new window]’>%s</a>”
ExtraSectionStatTypes4=PHL
ExtraSectionAddAverageRow4=1
ExtraSectionAddSumRow4=1
MaxNbOfExtra4=25
MinHitExtra4=1

ExtraSectionName5=”Top 30 RSS Readers/Spiders”
ExtraSectionCodeFilter5=”200 304″
ExtraSectionCondition5=”URL,\.xml|\.rdf|\.rss|\/feed”
ExtraSectionFirstColumnTitle5=”RSS Reader/Spider”
ExtraSectionFirstColumnValues5=”UA,(.*)”
ExtraSectionStatTypes5=HBL
ExtraSectionAddAverageRow5=1
ExtraSectionAddSumRow5=1
MaxNbOfExtra5=30
MinHitExtra5=1

ExtraSectionName6=”Downloads (diff,doc,pdf,rtf,sh,tgz,zip) – Top 10″
ExtraSectionCodeFilter6=”200 304″
ExtraSectionCondition6=”URL,(.*((\.diff)|(\.doc)|(\.pdf)|(\.rtf)|(\.sh)|(\.tgz)|(\.zip)))”
ExtraSectionFirstColumnTitle6=”Download”
ExtraSectionFirstColumnValues6=”URL,(.*)”
ExtraSectionFirstColumnFormat6=”%s”
ExtraSectionStatTypes6=HBL
ExtraSectionAddAverageRow6=0
ExtraSectionAddSumRow6=1
MaxNbOfExtra6=10
MinHitExtra6=1

2007年12月4日

Tomcat遇到”Error listenerStart”或”Error filterStart”问题且无详细日志时的log配置.

Filed under: Java,Tomcat — 标签:, , — lizongbo @ 15:44

昨天部署web应用到Tomcat之后,无法成功启动,并且控制台没有详细的错误信息,
顶多就两行提示信息,例如:
严重: Error listenerStart
严重: Context [/lizongbo] startup failed due to previous errors

或者

严重: Error filterStart
org.apache.catalina.core.StandardContext start
严重: Context startup failed due to previous errors

查找logs目录下的信息,除了这两句话,也没别的辅助内容.
给查错带来了困难,在这种情况下,是因为Tomcat自身的默认日志没有将一些错误信息输出到控制台或文件,
这个时候则需要配置Tomcat自身的log,启用详细的调试日志.

在Tomcat 5.5和Tomcat 6.0中的配置基本一样,只是相关文件放的目录有所不同.

首先需要准备的文件为:

1.log4j.jar , 下载地址 : http://www.apache.org/dist/logging/log4j/1.2.15/apache-log4j-1.2.15.zip
2.Tomcat 5.5所需的 commons-logging.jar,下载地址: http://www.apache.org/dist/commons/logging/binaries/commons-logging-1.1.zip

3.log4j配置文件:
log4j.properties
配置内容为:

log4j.rootLogger=ERROR,R

log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
log4j.appender.CONSOLE.layout.ConversionPattern=[%p]%t-%c-%m%n

log4j.appender.R=org.apache.log4j.RollingFileAppender
log4j.appender.R.File=${catalina.home}/logs/lizongbo.log
log4j.appender.R.MaxFileSize=10MB
log4j.appender.R.MaxBackupIndex=10
log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=[%p]%t-%c-%m%n

log4j.logger.org.apache.catalina=INFO,R,CONSOLE

#日志级别不能太低,如果配置为debug的话,输出的日志信息太多,导致tomcat启动非常的慢.

4.Tomcat 6.0所需的juli替换文件:
http://www.apache.org/dist/tomcat/tomcat-6/v6.0.14/bin/extras/tomcat-juli-adapters.jar
http://www.apache.org/dist/tomcat/tomcat-6/v6.0.14/bin/extras/tomcat-juli.jar

在Tomcat6.0中,

将tomcat-juli-adapters.jar,log4j-1.2.15.jar,log4j.properties复制到D:\Java\ApacheTomcat6.0.14\lib下面.

将tomcat-juli.jar复制到D:\Java\apache-tomcat-6.0.14\bin\下面.

然后启动tomcat,就可以在D:\Java\apache-tomcat-6.0.14\logs下看到lizongbo.log了.

在 Tomcat5.5中,

将commons-logging-1.1.jar,log4j-1.2.15.jar,复制到D:\Java\apache-tomcat-5.5.25\common\lib下面.
将log4j.properties复制到D:\Java\apache-tomcat-5.5.25\common\classes下面.

然后启动tomcat,就可以在D:\Java\apache-tomcat-5.5.25\logs下看到lizongbo.log了.

在这个时候,再通过日志文件来分析,则会发现出现这种错误的情况可能有:
(以下是我遇到的出错情况,大多是些低级错误)
1.webapps要用到的classe文件根本没有复制到WEB-INF/classes目录下面
(java.lang.NoClassDefFoundError,而这个信息可能默认没输出到控制台,尤其是用了spring的,昨天就是这个粗心的低级错误)
2.要用到lib文件没有复制完,缺少lib
3.lib下的同一个库的jar文件存在多个不同版本,引起版本冲突.
4.lib下的jar与tomcat版本不相对应(我遇到的问题是web应用在Tomcat5.5上运行正常,换到Tomcat6.0上就出错,
例如一个用了struts的webapp在Tomcat 6上报下面的错误
“Parse Fatal Error at line 17 column 6: The processing instruction
target matching “[xX][mM][lL]” is not allowed” )

愿意看英文的可以参考官方网站说明:
http://tomcat.apache.org/tomcat-6.0-doc/logging.html
http://tomcat.apache.org/tomcat-5.5-doc/logging.html

Older Posts »

Powered by WordPress