dev2dev 首页 > 资源中心 > 专家Blog > 专家Blog文章
WLST——BEAWorld大会,第一部分
在今年的BEAWorld大会上(Santa Clara),我有一场主标题为“New and Enhanced WebLogic Scripting Tool”、副标题为“Automate the mundane and slay the difficult”的演讲。当时的情景我还记忆犹新。在开始演讲之前,我调查了一下听众对WLST的熟悉情况,听众中举起的众多只手另我十分惊喜。我知道这主要是由于我们在dev2dev上发布了用于WLS 7.0和8.1(所有的服务包)的WLST。BEA非常理解许多客户不愿使用不受支持的工具,因此BEA最近宣布支持WLST 7.0和8.1。新用户可以从dev2dev上获取该工具,并开始使用。
在我的演讲中,我演示了9.0中开箱即用的WLST的一些新特性,并且答应听众会在我的文章中给出演示脚本。演示包括,如何只通过很少的或一个简单的WLST脚本,从头开始创建一个由集群中的服务器组成的完善的域。演示一开始,首先是一个简单的脚本,它用于加载典型的WLS 9.0安装所附带的默认模板。脚本设置了管理用户名和密码,将管理服务器名设置为“myserver”,并将域写入一个目录。下面是设置默认域的脚本:
# Read the default template that comes with WLS installation
print "Read the default domain"
readTemplate("d:/bea/load47/weblogic90/common/templates/domains/wls.jar")
# set the password for default administration user
cd("Security/base_domain/User/weblogic")
cmo.setUserPassword("weblogic")
setOption('OverwriteDomain', "true")
cd("/")
cd("Servers/AdminServer")
cmo.setName("myserver")
writeDomain("d:/bea/mydomain")
print "Done creating and writing the domain"
closeTemplate()
我们来看看如何改进这个脚本,让它实现更多的功能。我们将配置几个托管服务器,创建一个集群,并将这些托管服务器添加到集群中。在演示中,这些都是在启动服务器之后、连接到服务器时完成的。现在我们要在启动管理服务器之前做这些。脚本如下:
# Read the default template that comes with WLS installation
print "Read the default domain"
readTemplate("d:/bea/load47/weblogic90/common/templates/domains/wls.jar")
# set the password for default administration user
cd("Security/base_domain/User/weblogic")
cmo.setUserPassword("weblogic")
setOption('OverwriteDomain', "true")
cd("/")
cd("Servers/AdminServer")
cmo.setName("myserver")
cd("/")
create("ms1","Server")
create("ms2","Server")
create("mycluster","Cluster")
cd("Servers/ms1")
cmo.setListenPort(8001)
cd("/")
cd("Servers/ms2")
cmo.setListenPort(9001)
assign("Server", "ms1,ms2", "Cluster", "mycluster")
writeDomain("d:/bea/mydomain")
print "Done creating and writing the domain"
closeTemplate()
设置了最小域后,我启动了一个Node Manager(全部使用默认值)。默认情况下,Node Manager Server在端口5556启动,并且所有的日志都将写入运行WLST的目录下。更多选项请通过help('startNodeManager')查看startNodeManager帮助。现在,启动并运行Node Manager之后,我使用命令行nmConnect连接到Node Manager,并启动管理服务器。启动之后,连接到该服务器。下面是我所使用的脚本:
# start the Node Manager, this starts at
# default port 5556
startNodeManager()
# connect to the NodeManager, the default admin
# username and password can be used
nmConnect("weblogic","weblogic")
# start the server via the NM
nmStart("myserver")
# now disconnect from NM
nmDisconnect()
# connect to the administration server that we just started
connect("weblogic","weblogic")
不知您是否注意到了:我使用了管理用户名和密码来连接到NodeManager server。这是因为,默认情况下,在开发模式中,用户名和密码被设置为管理服务器的用户名和密码。如果您设置域使其运行生产模式,那么就必须显式地通过SecurityConfigurationMBean的NodeManagerUsername和NodeManagerPassword属性来设置用户名和密码。下面是运行这两种脚本后的WLST控制台输出。
D:\bea\mydomain>java weblogic.WLST
Initializing WebLogic Scripting Tool (WLST) ...
Welcome to WebLogic Server Administration Scripting Shell
Type help() for help on available commands
wls:/offline> execfile("d:/bea/domain.py")
Read the default domain
Done creating and writing the domain
wls:/offline>execfile("d:/bea/start.py")
Launching Node Manager ...
Successfully launched the Node Manager.
The Node Manager process is running independent of the WLST process
Exiting WLST will not stop the Node Manager process. Please refer
to the Node Manager logs for more information.
The Node Manager logs will be under D:\bea\mydomain\.
Connecting to Node Manager ...
Successfully connected.
Starting server myserver
Server myserver started successfully
Successfully disconnected from Node Manager
Connecting to weblogic server instance running at t3://localhost:7001 as username weblogic ...
Successfully connected to Admin Server 'myserver' that belongs to domain 'mydomain'.
Warning: An insecure protocol was used to connect to the server.
To ensure on-the-wire security, the SSL port or Admin port
should be used instead.
wls:/mydomain/serverConfig>
总结一下我们都做了什么:从一个(BEA WebLogic Server附带的)模板创建了一个最小域,启动一个Node Manager Server,连接到它,并启动我们所创建的域中的管理服务器,从Node Manager Server断开,并连接到启动的管理服务器。
下一篇文章我将继续介绍该演示。
原文出处:http://dev2dev.bea.com/blog/sghattu/archive/2005/10/wlst_beaworld_s.html
作者其它文章
|