weblogic wlst的研究和使用(weblogic script tool)

为了让运维部署方便,减少部署步骤和人为出错,研究使用wlst来实现静默安装部署,方便快捷,一边学习,一边研究,一边使用。

1、wlst的脚本如何运行?下面是Oracle官方给出的方法

  • Include the script in the wlst.cmd or wlst.sh command:

    wlst.sh  /oracle/middleware/wlserver/common/templates/scripts/wlst/distributedQueues.py
    
  • Include the script in the java weblogic.WLST command. You can either include the full path to the script, as shown here:

    java weblogic.WLST c:/Oracle/Middleware/wlserver/common/templates/scripts/wlst/distributedQueues.py
    
    
    

2、在线添加集群和被管服务器

下面是weblogic安装后自带的一个添加集群和被管服务器的脚本(weblogic版本 11g Release 10.3.6)

cluster_creation.py

# This example script:
# * connects WLST to the Admin Examples Server
# * starts an edit session
# * creates 10 managed servers.
# * It creates 2 clusters and assigns the servers to the respective clusters

from java.util import *
from javax.management import *
import javax.management.Attribute

print 'starting the script ....'
username = 'weblogic'
password = 'welcome1'
clusters = 'cluster1','cluster2'
ms1 = {'managed1':7701,'managed2':7702,'managed3':7703,'managed4':7704,'managed5':7705}
ms2 = {'managed6':7706,'managed7':7707,'managed8':7708,'managed9':7709,'managed10':7710}

connect(username,password,'t3://localhost:7001')

clustHM = HashMap()
edit()
startEdit()

for c in clusters:
    print 'createing cluster ' + c
    clu = create(c,'Cluster')
    clustHM.put(c,clu)

cd('..\..')

clus1 = clustHM.get(clusters[0])
clus2 = clustHM.get(clusters[1])

for m, lp in ms1.items():
    managedServer = create(m,'Server')
    print 'creating managed server '+m
    managedServer.setListenPort(lp)
    managedServer.setCluster(clus1)

for m1, lp1 in ms2.items():
    managedServer = create(m1,'Server')
    print 'creating managed server '+m1
    managedServer.setListenPort(lp1)
    managedServer.setCluster(clus2)

save()
activate(block="true")
disconnect()
print 'End of script ...'
 

-------------------------------------------------

上面是集群创建的脚本

3、集群的删除

cluster_deletion.py

# This example script corresponds to the cluster_creation.py script:
# * connects WLST to the Admin Examples Server
# * starts an edit session
# * For each cluster created in cluster_creation.py, it deletes the
# * managed servers and the migratabletargets.
# * Lastly, it deletes the clusters.

print 'starting the script ....'
username = 'weblogic'
password = 'welcome1'
clusters = 'cluster1','cluster2'
ms1 = {'managed1':7701,'managed2':7702,'managed3':7703,'managed4':7704,'managed5':7705}
ms2 = {'managed6':7706,'managed7':7707,'managed8':7708,'managed9':7709,'managed10':7710}

connect(username,password,'t3://localhost:7001')

edit()
startEdit()
s = " (migratable)"

for m, lp in ms1.items():
    print 'deleting managed server '+m
    serverMBean = getMBean("Servers/"+m)
    serverMBean.setCluster(None)
    managedServer = delete(m,'Server')
    
for m1, lp1 in ms2.items():
    print 'deleteing managed server '+m1
    serverMBean = getMBean("Servers/"+m1)
    serverMBean.setCluster(None)
    managedServer = delete(m1,'Server')
    
for c in clusters:
    print 'deleting cluster '+c
    clu = delete(c,'Cluster')
    

save()
activate(block="true")
print 'Saved Changes ...'

print 'End of script ...'

disconnect()

 

--------------上面是删除集群和被管服务器的脚本------------------

4、部署应用的脚本

部署可以采用weblogic.Deployer,这个是weblogic提供的命令行的部署工具,如果运行不起来,可能需要将weblogic.jar添加到java的classpath中,比如下面

java -classpath "./weblogic.jar" weblogic.Deployer -adminurl t3://localhost:7001 -username weblogic
   -password weblogic -deploy -targets companyHost c:\localfiles\myWebApp.ear

注意上面的红色部分,经过实际验证,原来的http://localhost:7001是不能连接的

5、删除部署

java weblogic.Deployer -user weblogic -adminurl t3://10.1.73.7:8001 -password nclesb123 -undeploy -name myweb-1.0-SNAPSHOT (会自动停止并删除,注意当应用不存在的时候会报错)

 

先写到这,可能会有问题,我先实践一下,有问题再修正本文

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值