A-A+

opencms使用总结

2016年05月12日 Opencms 暂无评论 阅读 444 次浏览 次

一、概述

公司网站改用了Opencms,后台数据库是sql server,opencms使用简单,但配置部署比较繁琐,所以在这里有必要总结一下以备不时之用。

二、安装

这个比较简单,但在安装前要有所准备,主要是tomcat的配置,建议安装tomcat安装版,那样界面使用比较友好。

1.安装前的准备

1.1 安装tomcat6.0,安装目录最好简单一点,建议直接安装在分区根目录,我就将其安装在了E:\Tomcat 6.0\下

1.2 配置server.xml文件,这个文件其实比较简单,只是注释比较多,哈

<?xml version='1.0' encoding='utf-8'?>

<Server port="8005" shutdown="SHUTDOWN"> 如果有两个tomcat使用,就要修改此端口

<Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />

<Listener className="org.apache.catalina.core.JasperListener" />

<Listener className="org.apache.catalina.mbeans.ServerLifecycleListener" />

<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />

下面是配置全局资源,JNDI也可以在此配置

<GlobalNamingResources>

<Resource name="UserDatabase" auth="Container"

type="org.apache.catalina.UserDatabase"

description="User database that can be updated and saved"

factory="org.apache.catalina.users.MemoryUserDatabaseFactory"

pathname="conf/tomcat-users.xml" />

</GlobalNamingResources>

下面才是重点 如果你对此不熟悉 可以看一下<tomcat启动流程>

<Service name="Catalina">

<Connector port="8080" protocol="HTTP/1.1" 如果有两个tomcat使用,就要修改此端口

connectionTimeout="20000" 

redirectPort="8443" />如果有两个tomcat使用,就要修改此端口

<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" /> 与apache链接时使用的ajp协议

<Engine name="Catalina" defaultHost="localhost"> 

<Realm className="org.apache.catalina.realm.UserDatabaseRealm"

resourceName="UserDatabase"/>

<Host name="localhost" appBase="webapps" 

unpackWARs="true" autoDeploy="true"

xmlValidation="false" xmlNamespaceAware="false">

</Host>

</Engine>

</Service>

</Server>

1.3 安装数据库,这里只说下mysql,配置的时候不要忘了选字符集为utf8就行

2. 开始安装opencms 将war包扔到tomcat下的wabapps中,启动tomcat,它将会自动解压部署,然后,打开浏览器,输入地址:

http://localhost:8080/opencms/setup 回车 next next

3.安装apache,使用安装版吧,附件中:httpd-2.2.17

4.去掉两个opencms(官方文档方法,此方法在使用时容易出现apache代理错误,使css找不到的问题)

4.1 tomcat_home/conf/server.xml

<Host name="localhost" appBase="webapps" 

unpackWARs="true" autoDeploy="false"

xmlValidation="false" xmlNamespaceAware="false" deployOnStartup="false">

<Context path="" docBase="..../webapps/opencms"/>

.......

</Host>

4.2 tomcat_home/webapps/opencms/web-inf/web.xml

<context-param>

<param-name>DefaultWebApplication</param-name>

<param-value>opencms</param-value>

</context-param>

这一步完成后重启tomcat 在浏览器中输入:http://localhost:8080/opencms看是否成功

4.3 apache2.2/conf/httpd.conf

启用代理模块

LoadModule proxy_module modules/mod_proxy.so

LoadModule proxy_http_module modules/mod_proxy_http.so

然后在此文件末尾加上下面:

### 在Apache2.2\conf\http.conf文件的结尾追加以下配置片断!

### 如果你的Tomcat安装的目录与此不同,请注意修改相关路径



NameVirtualHost *:80

<VirtualHost *:80>

<Directory "C:/apache-tomcat-5.5.25/webapps/opencms/">

Order allow,deny

Allow from all

</Directory> 

ServerName localhost

ServerAdmin test@test.com

DocumentRoot "C:/apache-tomcat-5.5.25/webapps/opencms/"

ErrorLog logs/error.log

SetEnvIf Request_URI "\/opencms\/*" redirect

CustomLog logs/localhost-access.log common env=!redirect

ProxyPass /opencms/ !

RedirectPermanent /opencms/ http://localhost/ 

ProxyPass /resources/ !

ProxyPass /export/ !

ProxyPass / http://localhost:8080/opencms/ 

ProxyPassReverse / http://localhost:8080/opencms/

</VirtualHost>

4.4 opencms/web-inf/config/opencms-importexport.xml

<vfs-prefix>${CONTEXT_NAME}${SERVLET_NAME}</vfs-prefix> 删掉红色部分

4.5 opencms/web-inf/config/opencms-system.xml

<sites> 

<workplace-server>http://localhsot:8080</workplace-server> 删掉红色部分

<site server="http://localhsot:8080" uri="/sites/default"/> 删掉红色部分

</sites>

4.6 tomcat_home/conf/server.xml

<Connector port="8080" protocol="HTTP/1.1"

connectionTimeout="20000" 

redirectPort="8443" 

proxyName="localhost" proxyPort="80"/> 添加红色部分

4.7 重启tomcat再重启apache 在浏览器中输入 http://localhost测试

注意:如果测试不成功,请首先查看tomcat日志和apache日志;如没发现问题,请在按此方法配置一遍

5.去掉两个opencms的另类的方法(利用urlrewritefilter,此jar在google code 上有,地址:http://code.google.com/p/urlrewritefilter/

记得要下3.2版本,别的可能有问题。此方法在tomcat 7.0.6下测试成功)

5.1 将附件中的urlrewrite-3.2.0.jar文件放到opencms/web-inf/lib/下

5.2 在opencms/web-inf/下新建文件urlrewrite.xml,文件内容如下

<?xml version="1.0" encoding="utf-8"?>

   <!DOCTYPE urlrewrite PUBLIC "-//tuckey.org//DTD UrlRewrite 3.2//EN" "http://tuckey.org/res/dtds/urlrewrite3.2.dtd">

   <urlrewrite>

   <rule>

   <from>^/tc-mgr/(.*){1}amp;lt;/from>

   <to>/tc-mgr/1</to>

   </rule>

   <rule>

   <condition type="request-uri" operator="notequal">^/export/.*{1}amp;lt;/condition>

   <condition type="request-uri" operator="notequal">^/resources/.*{1}amp;lt;/condition>

   <condition type="request-uri" operator="notequal">^/opencms-errorhandler/.*{1}amp;lt;/condition>

   <condition type="request-uri" operator="notequal">^/webdav/.*{1}amp;lt;/condition>

   <condition type="request-uri" operator="notequal">^/opencms/.*{1}amp;lt;/condition>

   <condition type="request-uri" operator="notequal">^/setup/.*{1}amp;lt;/condition>

   <from>^/(.*){1}amp;lt;/from>

   <to>/opencms/1</to>

   </rule>

   </urlrewrite>

5.3 修改opencms/WEB-INF/web.xml文件,添加一个过滤



<listener>

   <listener-class>org.opencms.main.OpenCmsListener</listener-class>

   </listener>

之后添加以下内容:

<filter>

   <filter-name>UrlRewriteFilter</filter-name>

   <filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>

   <init-param>

   <param-name>confReloadCheckInterval</param-name>

   <param-value>-1</param-value>

   </init-param>

   <init-param>

   <param-name>logLevel</param-name>

   <param-value>ERROR</param-value>

   </init-param>

   <init-param>

   <param-name>statusEnabled</param-name>

   <param-value>false</param-value>

   </init-param>

   <init-param>

   <param-name>statusPath</param-name>

   <param-value>/status</param-value>

   </init-param>

   </filter>

   <filter-mapping>

   <filter-name>UrlRewriteFilter</filter-name>

   <url-pattern>/*</url-pattern>

   </filter-mapping>

5.4 opencms/web-inf/config/opencms-importexport.xml

<vfs-prefix>${CONTEXT_NAME}${SERVLET_NAME}</vfs-prefix> 删掉红色部分

5.5 重启tomcat,测试

6. OpenCMS建站过程

6.1 修改host文件(可省略) 如: 127.0.0.1 xiaoxie

6.2 在opencms工作区的sites下新建站点文件夹 /sites/xiaoxie 选择自动创建首页,否则测试时会找不到文件

6.3 修改opencms/web-inf/config/opencms-system.xml

<sites> 

<workplace-server>http://localhsot</workplace-server> 

<default-uri>/sites/default/</default-uri> 修改成自己的站点目录

<site server="http://localhsot" uri="/sites/default"/> 修改成自己的站点目录

</sites>

6.4 重启tomcat http://localhost/ 测试

7.创建网站模板(以cn.lvbang.muban为例)

7.1 在工作区新建模板 一般名称与java包名的命名方式类似,如cn.lvbang.muban

模板文件夹全选即可,别的默认就可以。最后点ok,生成。

7.2 生成的模板可以在 /system/modules/目录下找到

模板下一版有下面几个目录,分别存放不同类型的文件

|__classes 一般存放对应项目源码编译后的class文件 

|_____|___cn

|__________|___lvbang

|________________|___muban

|__elements 存放页面子元素的jsp代码,如页头 页尾 导航条等

|__lib 对应本地(eclipse开发时的)WEB-INF/lib/目录下的jar包

|__resources 存放与项目有关的静态文件,如css js img文件

|__templates 存放与模板主体相关的模板文件,都是jsp类型

|__schemas 非系统产生,存放xsd文件

|....

7.3 模板的使用

html文件使用模板,可在文件template属性中指定

jsp文件使用模板,必须使用完整的模板文件,即定义了模板快的文件,在文件template-elements属性中指定

例如下面就是引入模板头和模板尾的标签:

<cms:include property="template" element="head"/>

<cms:include property="template" element="foot"/>

8.网站内容管理

8.1 创建XSD文件 

一般将xsd文件放在对应模块的schemas目录下,下面是cn.lvbang.muban中的xsd文件,定义了网站

发布新闻时的内容格式:

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"> 

<xsd:include schemaLocation="opencms://opencms-xmlcontent.xsd"/> 

<xsd:element name="ArticleTypes" type="OpenCmsArticleTypes"/> 

<xsd:complexType name="OpenCmsArticleTypes">

<xsd:sequence>

<xsd:element name="ArticleType" type="OpenCmsArticleType" minOccurs="0" maxOccurs="unbounded"/>

</xsd:sequence>

</xsd:complexType>

<xsd:complexType name="OpenCmsArticleType">

<xsd:sequence>

<xsd:element name="Title" type="OpenCmsString" />

<xsd:element name="Keywords" type="OpenCmsString" maxOccurs="3"/>

<xsd:element name="DateTime" type="OpenCmsDateTime" minOccurs="1" /> 

<xsd:element name="Text" type="OpenCmsHtml" />

</xsd:sequence>

<xsd:attribute name="language" type="OpenCmsLocale" use="required"/>

</xsd:complexType> 

<xsd:annotation> 

<xsd:appinfo> 

<defaults> 

<default element="DateTime" value="${currenttime}"/> 

</defaults> 

<layouts>

<layout element="Text" widget="HtmlWidget" configuration="formatselect,link,anchor,source,imagegallery,downloadgallery, linkgallery,htmlgallery,tablegallery,image"></layout>

</layouts>

</xsd:appinfo> 

</xsd:annotation> 

</xsd:schema> 

8.2 XSD文件控制的XML文件(workplace.properties 放在cn/lvbang/muban下,字符集要设置一下 为iso-8859-1 content-encoding):

fileicon.myarticletype = 我的文章类型

title.newmyarticle = 创建一篇文章

label.ArticleType.Title = 标题

label.ArticleType.Keywords = 关键词

label.ArticleType.DateTime =日期

label.ArticleType.Text = 正文

8.3 修改opencms/web-inf/config/opencms-modules.xml文件

在其中找到cn.lvbang.muban模板块的定义,添加内容。模板块定义文件比较大,用查找的方式找比较快

<module>

<name>com.lvbang.muban</name>

<nicename><![CDATA[绿邦模板]]></nicename>

<class/>

<description><![CDATA[绿邦模板]]></description>

<version>0.1</version>

<authorname><![CDATA[xiaoxie]]></authorname>

<authoremail><![CDATA[yangchangwen@lvbang.cn]]></authoremail>

<datecreated/>

<userinstalled/>

<dateinstalled/>

<dependencies/>

<exportpoints>

<exportpoint uri="/system/modules/com.lvbang.muban/lib/" destination="WEB-INF/lib/"/>

<exportpoint uri="/system/modules/com.lvbang.muban/classes/" destination="WEB-INF/classes/"/>

</exportpoints>

<resources>

<resource uri="/system/modules/com.lvbang.muban/"/>

</resources>

<parameters/>

<!--在此添加以下内容-->

<resourcetypes>

<type class="org.opencms.file.types.CmsResourceTypeXmlContent" name="myarticle" id="7001"> id是新建的xml标识,标识值最好大于1000

<param name="schema">/system/modules/com.lvbang.muban/schemas/Article.xsd</param> 对应的xsd文件路径

</type>

</resourcetypes>

<explorertypes>

<explorertype name="myarticle" key="fileicon.myarticletype" icon="article.gif" reference="xmlcontent">

<newresource page="structurecontent" uri="newresource_xmlcontent.jsp?newresourcetype=myarticle" 这句是固定的不用修改

order="7001" autosetnavigation="false" autosettitle="false"/>

<accesscontrol> 定义权限内容

<accessentry principal="GROUP.Administrators" permissions="+r+v+w+c"/>

<accessentry principal="GROUP.Projectmanagers" permissions="+r+v+w+c"/>

<accessentry principal="GROUP.Users" permissions="+r+v+w+c"/>

</accesscontrol>

</explorertype>

</explorertypes>

<!--添加的内容--> 

</module>

修改完后保存,然后重启tomcat,进入工作区新建个结构化文件,看有没有“我的文章类型”这种类型

8.4 在站点目录下创建“我的文章类型”类型的文件 article1.html,创建一个display.jsp文件,使article1.html文件绑定它,即

设置article1.html文件的template属性为模板/system/modulescn/lvbang/muban/templates/xxx

template-elements属性为/display.jsp

displsy.jsp文件的内容大体如下:

<cms:include property="template" element="head"/>

<cms:contentload collector="singleFile" 显示单个文件 

param="%(opencms.uri)" url请求的文件

editable="true" > 页面可编辑

<cms:contentshow element="Title"/> 显示新闻题目

<cms:contentshow element="DateTime" /> 显示日期

<cms:contentshow element="Text"/> 显示新闻内容

</cms:contentload>

<cms:include property="template" element="foot"/>



9.OpenCMS备份及恢复方法(三种)

9.1 利用webdev方法(此方法不完整,后发布的新闻无法恢复,并且导入后,还需要再次配置)

9.2 系统备份恢复方法(推荐,这种如果导出所有即导出时选择根目录恢复成功;如果导出时只选择单个项目,测试时没有成功)

9.3 数据库备份方法(不推荐,数据库如果更换就完了)

直接使用数据库提供的备份功能。但是这种方法会缺少与系统文件相配的配置信息。如果对所做配置比较清楚,可以使用这种方法备份。

利用数据库提供的数据恢复功能后,再修正配系统配置文件即可。

10.附录:(页面对应的模板)

1.aboutlb AboutLB.jsp Honor.jsp /system/modules/com.lvbang.muban/templates/ablvbangtemplate.jsp

2.case display.jsp /system/modules/com.lvbang.muban/templates/secondtemplates.jsp /rel/../display.jsp

3.contactus.jsp /system/modules/com.lvbang.muban/templates/contactus.jsp

4.emp /system/modules/com.lvbang.muban/templates/emptemplate.jsp /rel/emp/display.jsp

5.Investor gonggao guanxi Investor.jsp mail.jsp tousu /system/modules/com.lvbang.muban/templates/investortemplate.jsp

6.Investor/gonggaolist /rel/Investor/gonggaolist/display.jsp

7.ITservice ConsutingService.jsp content.jsp Service.jsp Software.jsp System.jsp /system/modules/com.lvbang.muban/templates/ITservicetemplate.jsp

8.news news.jsp /system/modules/com.lvbang.muban/templates/newstemplate.jsp /rel/news/display.jsp

9.RelationNews /system/modules/com.lvbang.muban/templates/newstemplate.jsp /rel/RelationNews/display.jsp

10.Search result.jsp /system/modules/com.lvbang.muban/templates/SearchResult.jsp

11.Sitemap netquicknav.jsp /system/modules/com.lvbang.muban/templates/netquicknav.jsp

12.index.jsp /system/modules/com.lvbang.muban/templates/indextemplates.jsp 

13.ITService.jsp /system/modules/com.lvbang.muban/templates/ITservicetemplate.jsp

14.second.jsp /system/modules/com.lvbang.muban/templates/secondtemplates.jsp


 

评论已关闭!

Copyright © 香港虚拟主机_美国虚拟主机_香港服务器_美国服务器租用托管 保留所有权利.   Theme  Ality 蜀ICP备14006632号-1

用户登录