作者:Marius Larsen, Vidar Moe
部署在WebLogic平台上的企业开发项目在项目开发、测试和部署阶段需要维护几种不同的域配置方式。对于不同的环境而言,版本控制和连续推出不断变化的域配置是一项富有挑战性的任务。Domain Configuration Wizard有助于降低任务的挑战性,因为该向导比人眼所及可提供更多的功能。
WebLogic 5.1版还没有正式提出WebLogic域这一概念,但现在已成为运行在最新版本的WebLogic Platform上的所有企业应用程序的基础。域定义应用程序运行时环境的至关重要的部分,例如决定应用程序是否将在集群中运行,以及通过连接池定义使用哪个物理数据库。
域概念首次出现在WebLogic Server 6.0中。开始创建新的域对平台本身而言并没有太大的帮助。建议创建新域的方法是复制安装时默认的域,在复制的域中启动服务器,并使用Administration Console对其修改。第1版Domain Configuration Wizard是在WebLogic Server 7.0中引入的。这一版本的向导不支持WebLogic Integration或者 WebLogic Portal域。在最新版的WebLogic 中,利用WebLogic安装中的各种工具,有许多创建域的方法:您可以使用Domain Configuration Wizard、WebLogic.Server命令,或者有wlserver 和wlconfig Ant任务的Ant脚本。这表明BEA认真地听取了开发者的建议:帮助我们更容易地创建WebLogic域。本文将详细介绍Domain Configuration Wizard,集中讨论如何利用它的3种运行模式中文档最少的一种(直到现在)——静寂模式(Silent Mode)(此外,正如您可能知道的一样,它还可以运行在GUI模式和Console模式中)。
Domain Configuration Wizard已经成熟,现在默认包括域的全部内容。GUI模式相对容易使用,即使您必须为很多配置屏幕做好准备,比如用几个连接池和一些JMS目的地配置集群门户域时。我们以为在企业项目中,这种方法主要面临的挑战是要为几种类似的环境(如开发、测试和生产)维护几种不断变化的域配置。除此之外,开发者通常拥有他们自己的带有本地数据库设置的本地服务器和本地JMS目的地。对于所有的项目,但特别小的项目除外,我们不能通过Domain Configuration Wizard手工创建这些域配置。对不同的部署目标,我们需要能够采用一致的方法从头开始重复创建域。我们也希望能够将我们的各种域配置置入源控制之下。Domain Configuration Wizard的静寂模式为我们提供了通过域配置脚本实现这种功能机会。
Domain Configuration Wizard位于WL_HOME/common/bin子目录下,其中WL_HOME是BEA_HOME/weblogic81。运行config.cmd可以启动它。为了在静寂模式中运行它,您要将模式参数设置为静寂,然后告诉它查找静寂配置脚本的地方。
在 Windows中:
config.cmd ?mode=silent ?silent_script=<silent script file>
在Unix/Linux中:
./config.sh ?mode=silent ?silent_script=<silent script file>
所有这一切发生在silient脚本文件中。该脚本文件含有完整的域配置。即使此文件中使用的语言是专有的,但它相当容易理解。 在BEA的电子文档中有完整说明。
默认安装带有一个示例静寂脚本文件,该文件位于:WL_HOME/common/templates/domains/silent_scripts,我们将逐步讲解该示例文件。
WebLogic域可以是5种不同类型的域之一,通过域模板可以访问。要做的第一件事是通过选择希望使用的域模板文件来确定域的类型。域模板文件位于WL_HOME/common/templates/domains/目录中。不同的域模板是:
Workshop域(wlw.jar)
Integration域(wli.jar)
Portal域(wlp.jar)
Server域(wls.jar)
WebLogic Platform域(platform.jar)
域模板文件包含在BEA WebLogic Platform 8.1的安装中。对于本示例,我们选择WebLogic Server域,因而wls.jar是模板文件。现在,我们读入默认的服务器域中所包含的所有数据:
//Read in a domain template.
read template from "WL_HOME/weblogic81/common/templates/domains/wls.jar";
默认服务器域已经配置了一台称为“myserver”的管理服务器。现在,我们设置地址、端口和SSL:
//Find and configure the Admin Server.
find Server "myserver" as s1;
set s1.ListenAddress "localhost";
set s1.ListenPort "7001";
set s1.SSL.Enabled "true";
set s1.SSL.ListenPort "7002";
我们希望在该域中创建一个JMSQueue。首先,我们创建一个JMSServer,然后创建JMSQueue,并设置该队列的属性。最后,我们将“wls.jar”模板文件中默认的服务器“myserver”做为JMSServer的目标。
//Create a JMSQueue.
//A JMSServer has to be created first.
create JMSServer "myJMSServer" as jmsserver;
create JMSQueue "myJMSQueue" as myq;
//required attribute
set myq.JNDIName "jms/myjmsqueue";
//required attribute
set myq.JMSServer "myJMSServer";
//optional attribute
//set myq.StoreEnabled "false";
//target "myJMSServer" to server "myserver"
assign JMSServer "myJMSServer" to target "myserver";
我们希望在该WebLogic Server域中创建创建一个连接池。在此示例中,我们使用BEA Weblogic Platform 8.1安装中的PointBase数据库。创建连接池并设定目标为“myserver”。
//Create a JDBCConnectionPool.
create JDBCConnectionPool "demoPool" as mypool;
//required attribute
set mypool.DriverName "com.pointbase.jdbc.jdbcUniversalDriver";
//required attribute
set mypool.URL "jdbc:pointbase:server://localhost:9092/demo";
//required attribute
set mypool.Password "PBPUBLIC";
//optional attribute (but it's recommended you set the db user...)
set mypool.Properties "user=PBPUBLIC";
//target all JDBC connection pools to server "myserver"
assign JDBCConnectionPool "*" to target "myserver";
在配置域的过程中,将应用程序的目标设定为服务器是可能的。“wls.jar”模板没有包含任何应用程序,因而该代码被注释掉了。
//target existing applications.
//target applications only when they exist in current domain template
//assign application "*" to target "myserver";
We now want to change the password for the webloic user. We find the user and then sets the password.
//Create the admin user and password.
find User "weblogic" as u1;
set u1.password "weblogic";
现在,我们将把域写入磁盘。将域写到指定的路径中。路径中的最后一个文件夹是域的名称。该域的名称是wls:
//Write out the domain.
set OverwriteDomain "true";
将域写到“C:ea/user_projects/domains/wls”中:
最后关闭模板文件:
//Close domain template to indicate completion of work.
close template;
在清单3中,我们添加了一个更复杂的示例。下面我们在WebLogic Platform域中创建一个拥有一台管理服务器和两台受管理服务器的集群。使用的数据库是Oracle 9i数据库。
为了能够方便地处理不同的域配置,我们已经用标记代替了脚本文件的值。我们使用Ant脚本建立该域并用实际的属性替代标记。提取域配置文件中的值到属性文件中,可以使处理不同域配置简单化,而且很容易将其置入源控制之下。在Ant编译文件的顶部引用Ant脚本的属性文件,在此示例中,属性文件名是“domain.properties”。必须修改属性文件以适应所选的环境,该环境包括域名的属性、域文件夹、门户数据库属性(如URL、用户名、密码等)和所有服务器的属性,例如服务器的URL、端口、SSL端口等。
现在,在Ant编译文件中运行“build.domain”目标可以很容易地创建域。由于Ant编译文件中的依赖性,下面的目标将被依次调用:
1. init目标: 创建临时编译文件夹
2. copy目标:复制原始的静寂脚本文件到临时编译文件夹中
3. replace.silentfile目标:用“domain.properties”文件中给出的值替代静寂脚本文件中的所有标记
4. build.domain目标:用新创建的静寂脚本文件作为参数调用Configuration Wizard Program(config.cmd)
5. clean目标:删除所有的临时文件和文件夹
现在,我们在“domain.properties”文件中所指定的路径和名称中创建了一个域,并已准备好可以用了。Ant脚本和示例属性文件如清单2和4所示。
结束语
域这个概念已经成为BEA WebLogic Platform至关重要的一部分,它定义应用程序的运行时环境。在需要重复部署各种目标的项目中,重要的是要能够用高效一致的方法创建和重新创建WebLogic域。将这些域配置置于源控制之下也很重要。Domain Configuration Wizard的静寂模式通过支持脚本形式的域配置实现这一功能。本文介绍了使用脚本形式的域配置的优点,以及通过解释脚本形式的域配置来如何使用静寂模式。也说明了提取静寂模式脚本的值到属性文件中的方法,以及使用Ant脚本控制创建域的方法。我们在多个项目中使用了静寂模式,并且相信这是高效一致地创建WebLogic域的好方法。
参考资料
· BEA 电子文档:http://edocs.bea.com
清单 1 创建连接池
//Create a JDBCConnectionPool.
create JDBCConnectionPool "demoPool" as mypool;
//required attribute
set mypool.DriverName "com.pointbase.jdbc.jdbcUniversalDriver";
//required attribute
set mypool.URL "jdbc:pointbase:server://localhost:9092/demo";
//required attribute
set mypool.Password "PBPUBLIC";
//optional attribute (but it's recommended you set the db user...)
set mypool.Properties "user=PBPUBLIC";
//target all JDBC connection pools to server "myserver"
assign JDBCConnectionPool "*" to target "myserver";
清单2 Ant编译文件
<project name="silent config" default="build.domain" basedir=".">
<description>
Builds a new domain from the template-config specified in the domain.properties file
</description>
<!-- set properties for this build -->
<property file="domain.properties"/>
<property name="propertyfile" value="domain.properties"/>
<property name="build" location="build"/>
<property name="silent_config" value="silent_config_build.txt"/>
<target name="init" depends="clean,clean.domain">
<!-- Create the temp catalog for scripts -->
<mkdir dir=""/>
</target>
<target name="copy" depends="init"
description="copy buildfiles to build dir" >
<copy file="theproject_silent.txt" tofile="/"/>
</target>
<target name="replace.silentfile" depends="copy"
description="replace buildfiles with properties" >
<replace file="/" propertyfile="">
<replacefilter token="@" property="beahome"/>
<replacefilter token="@" property="domainspath"/>
<replacefilter token="@" property="domainname"/>
<replacefilter token="@" property="oraclesid"/>
<replacefilter token="@" property="oraclehost"/>
<replacefilter token="@" property="oracleport"/>
<replacefilter token="@" property="oracleuser"/>
<replacefilter token="@" property="oraclepassword"/>
<replacefilter token="@" property="weblogicpassword"/>
<replacefilter token="@" property="sslenabled"/>
<replacefilter token="@" property="adminname"/>
<replacefilter token="@" property="adminadress"/>
<replacefilter token="@" property="adminport"/>
<replacefilter token="@" property="adminsslport"/>
<replacefilter token="@" property="server1name"/>
<replacefilter token="@" property="server1adress"/>
<replacefilter token="@" property="server1port"/>
<replacefilter token="@" property="server1sslport"/>
<replacefilter token="@" property="server2name"/>
<replacefilter token="@" property="server2adress"/>
<replacefilter token="@" property="server2port"/>
<replacefilter token="@" property="server2sslport"/>
<replacefilter token="@" property="clustername"/>
<replacefilter token="@" property="clustermuliticastport"/>
<replacefilter token="@" property="clustermuliticastadress"/>
</replace>
</target>
<target name="build.domain" depends="replace.silentfile"
description="builds the domain using the config.cmd file from BEA in silent mode" >
<exec vmlauncher="false" executable="/weblogic81/common/bin/config" failonerror="true">
<arg value="-mode=silent"/>
<arg value="-silent_script=/"/>
<arg value="-logfile=log.log"/>
</exec>
<antcall target="clean"/>
</target>
<target name="clean" description="clean up" >
<!-- Delete the -->
<delete dir=""/>
</target>
<target name="clean.domain" description="clean up domain" >
<!-- Delete the -->
<delete dir="/"/>
</target>
</project>
清单3 domain.properties
#The folder where the domains are placed
#for example C:/bea/user_projects
domainspath=C:/theproject/domains
#The name of the domain you want to create
#for example development
domainname=theproject
#The common WLS STUFF
#Where your bea home is
#for example C:/bea
beahome=C:/bea
#The Weblogic user's password
weblogicpassword=password
#The ORCLE STUFF
#The SID of the Oracle database server used in the platform
oraclesid=THEPROJECT
#The ipadress of the Oracle database
oraclehost=development.theproject.com
#The port used by the Oracle database
oracleport=1521
#The Oracle user used by the platform
oracleuser=CLUSTER
#The Oracle user's password
oraclepassword=password
#The ADMIN server STUFF
#The name of the adminserver
adminname=cgServer
#The ipadress of the WLP
adminadress=localhost
#The port of the WLP
adminport=7001
##if SSL is enabled (true / false
sslenabled=true
##The SSL listning port
adminsslport=7002
#The 1.managed server STUFF
#The name of the 1.managed server
server1name=managedServer1
#The ipadress of the 1.managed server
server1adress=127.0.0.1
#The port of the WLP
server1port=7003
##The SSL listning port
server1sslport=7004
#The 2.managed server STUFF
#The name of the 2.managed server
server2name=managedServer2
#The ipadress of the 2.managed server
server2adress=127.0.0.1
#The port of the WLP
server2port=7005
##The SSL listning port
server2sslport=7006
#The cluster STUFF
#the name of the cluster
clustername=theCluster
#the multicast prt of the cluster
clustermuliticastport=7777
#the mulitcast adress og the cluster
clustermuliticastadress=localhost
清单4 BEA WebLogic Platform集群的静寂模式脚本文件
//Read in a domain template.
read template from "@/weblogic81/common/templates/domains/platform.jar";
//Find and configure the Admin Server.
//The default platform domain has configured an admin server called cgServer.
//We now set the address, the port, and SSL.
find Server @ as admin;
set admin.Name "@";
set admin.ListenAddress "@";
set admin.ListenPort "@";
set admin.SSL.Enabled "@";
set admin.SSL.ListenPort "@";
//Create and configure the 1. managed server
//We create a new server which is the first of the managed servers.
//The address, ports and SSLenabled are set as in the configuration of the admin server.
create Server "@" as ms1;
set ms1.ListenAddress "@";
set ms1.ListenPort "@";
set ms1.SSL.Enabled "@";
set ms1.SSL.ListenPort "@";
//Create and configure the 2. managed server
//We create a new server which is the second of the managed servers.
//The address, ports and SSL are set as in the configuration of the admin server.
create Server "@" as ms2;
set ms2.ListenAddress "@";
set ms2.ListenPort "@";
set ms2.SSL.Enabled "@";
set ms2.SSL.ListenPort "@";
//We create the cluster which is a cluster of the two managed servers created above.
//Create a Cluster.
create Cluster "@" as cluster;
set cluster.MulticastPort "@";
set cluster.MulticastAddress "@";
set cluster.ClusterAddress "@,@";
assign Server "@, @" to Cluster "@";
//Change the settings for the JDBCConnectionPools "cgPool" and "bpmArchPool"
//We now want to change the connection pools that are configured in the WebLogic Platform domain.
//There are two connection pools that we have to change, these are the pools used by WebLogic Portal
//and WebLogic Integration. In this example we use an Oracle 9i database.
//It is also possible to create new database connection pools and new datasources.
//Updating settings for "cgPool"
find JDBCConnectionPool "cgPool" as cgPool;
//required attribute
set cgPool.DriverName "weblogic.jdbc.oracle.OracleDriver";
//required attribute
set cgPool.DbmsName "@";
//required attribute
set cgPool.DbmsHost "@";
//required attribute
set cgPool.DbmsPort "@";
//required attribute
set cgPool.UserName "@";
//required attribute
set cgPool.Password "@";
//Updating settings for "bpmArchPool"
find JDBCConnectionPool "bpmArchPool" as bpmArchPool;
//required attribute
set bpmArchPool.DriverName "weblogic.jdbc.oracle.OracleDriver";
//required attribute
set bpmArchPool.DbmsName "@";
//required attribute
set bpmArchPool.DbmsHost "@";
//required attribute
set bpmArchPool.DbmsPort "@";
//required attribute
set bpmArchPool.UserName "@";
//required attribute
set bpmArchPool.Password "@";
//target the JDBC connection pools to the cluster
assign JDBCConnectionPool "*" to target "@";
//Create the admin user and password.
find User "weblogic" as weblogic;
set weblogic.password "@";
//Load Database.
//The database is loaded with all tables and content needed in Weblogic Integration
//and Weblogic Portal
//load database version "9i" using cgPool;
//Close domain template to indicate completion of work.
//Finally we close the configuration template file.
close template;
//The domain has now been created. |