您的位置:首页>平台软件>应用服务器,中间件>

静寂模式下创建 WebLogic 域

[ 来源:Marius Larsen, Vidar Moe | 更新日期:2007-7-15 20:28:23 | 评论 0 条 | 我要投稿 ]
部署在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模式中)。 字串8

  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=
字串3


在Unix/Linux中:
   ./config.sh ?mode=silent ?silent_script=

   所有这一切发生在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是模板文件。现在,我们读入默认的服务器域中所包含的所有数据: 字串2

//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; 字串4
   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";
字串4

//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;
字串4

   set u1.password "weblogic";

   现在,我们将把域写入磁盘。将域写到指定的路径中。路径中的最后一个文件夹是域的名称。该域的名称是wls:

//Write out the domain.
   set OverwriteDomain "true";
   将域写到“C:bea/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端口等。

字串4


   现在,在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域的好方法。 字串7

参考资料
? 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编译文件
字串2

  
   Builds a new domain from the template-config specified in the domain.properties file
  


  
  
  
  


  
  
  

   description="copy buildfiles to build dir" >
  
  

字串7



   description="replace buildfiles with properties" >
  
  
  
  
  
  
  
  
  
  

字串6


  
  
  
  
  
  
  
  
  
  
  
   字串3
  
  
  
  
  
  

   description="builds the domain using the config.cmd file from BEA in silent mode" >
  
  
  
  
  
  
  
字串5



  
  
  
  
  
  
  
  

清单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 字串2
   #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 字串4
   ##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 字串7
   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 "@BEAHOME@/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 @ADMIN_NAME@ as admin; 字串4
   set admin.Name "@ADMIN_NAME@";
   set admin.ListenAddress "@ADMIN_ADDR@";
   set admin.ListenPort "@ADMIN_PORT@";
   set admin.SSL.Enabled "@SSLENABLED@";
   set admin.SSL.ListenPort "@ADMIN_SSL_PORT@";
  
   //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 "@MS1_NAME@" as ms1;
   set ms1.ListenAddress "@MS1_ADDR@";
   set ms1.ListenPort "@MS1_PORT@";
   set ms1.SSL.Enabled "@SSLENABLED@";
   set ms1.SSL.ListenPort "@MS1_SSL_PORT@";


   //Create and configure the 2. managed server
字串4

   //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 "@MS2_NAME@" as ms2;
   set ms2.ListenAddress "@MS2_ADDR@";
   set ms2.ListenPort "@MS2_PORT@";
   set ms2.SSL.Enabled "@SSLENABLED@";
   set ms2.SSL.ListenPort "@MS2_SSL_PORT@";
  
   //We create the cluster which is a cluster of the two managed servers created above.
   //Create a Cluster.
  
   create Cluster "@CLUSTER_NAME@" as cluster;
   set cluster.MulticastPort "@MULTICAST_PORT@";
   set cluster.MulticastAddress "@MULTICAST_ADDR@";
   set cluster.ClusterAddress "@MS1_ADDR@:@MS1_PORT@,@MS2_ADDR@:@MS2_PORT@"; 字串6
   assign Server "@MS1_NAME@, @MS2_NAME@" to Cluster "@CLUSTER_NAME@";
  
//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 "@ORACLESID@";
//required attribute 字串7
   set cgPool.DbmsHost "@ORACLEHOST@";
//required attribute
   set cgPool.DbmsPort "@ORACLEPORT@";
//required attribute
   set cgPool.UserName "@ORACLEUSER@";
//required attribute
   set cgPool.Password "@ORACLEPASSWORD@";

//Updating settings for "bpmArchPool"
   find JDBCConnectionPool "bpmArchPool" as bpmArchPool;
//required attribute
   set bpmArchPool.DriverName "weblogic.jdbc.oracle.OracleDriver";
//required attribute
   set bpmArchPool.DbmsName "@ORACLESID@";
//required attribute
   set bpmArchPool.DbmsHost "@ORACLEHOST@";
//required attribute
   set bpmArchPool.DbmsPort "@ORACLEPORT@";
//required attribute
   set bpmArchPool.UserName "@ORACLEUSER@"; 字串4
//required attribute
   set bpmArchPool.Password "@ORACLEPASSWORD@";

//target the JDBC connection pools to the cluster

assign JDBCConnectionPool "*" to target "@CLUSTER_NAME@";

//Create the admin user and password.

find User "weblogic" as weblogic;
   set weblogic.password "@WEBLOGICPASSWORD@";

//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;
字串4
//The domain has now been created.

原文出处:
http://www.sys-con.com/story/?storyid=47097&DE=1


Tags:
责任编辑:
您的评论
用户名: 新注册) 密码: 匿名评论 [所有评论]

·用户发表意见仅代表其个人意见,并且承担一切因发表内容引起的纠纷和责任
·本站管理人员有权在不通知用户的情况下删除不符合规定的评论信息或留做证据
·请客观的评价您所看到的资讯,提倡就事论事,杜绝漫骂和人身攻击等不文明行为