摘要:直接执行该脚本即可运行工具。有离线和在线两种模式,通过命令可以从进入,按照目录形式对资源进行管理,甚至连操作的命令都和高度相似,比如是切换到指定资源路径下,是列出该目录下所有资源。
说明
weblogic安装目录下有一个创建Managed Server的脚本,脚本位于/u01/app/Oracle/Middleware/oracle_common/common/bin/config.sh下,但脚本会启动一个GUI界面程序,在Linux下需要安装图形界面程序,非常不方便。wlst(WebLogic Scripting Tools,WebLogic)是一个用来管理和配置weblogic的CLI命令行工具,可以运行Jython脚本,本文介绍如何通过该工具创建Managed Server。
WLST介绍wlst位于/u01/app/Oracle/Middleware/wlserver_10.3/common/bin/wlst.sh目录下,其中/u01/app/Oracle/Middleware/wlserver_10.3目录为$WEBLOGIC_HOME,所以严谨的讲,是安装在$WEBLOGIC_HOME/common/bin/wlst.sh下。直接执行该脚本即可运行wlst工具。
$ cd /u01/app/Oracle/Middleware/wlserver_10.3/common/bin/ $ ./wlst.sh Initializing WebLogic Scripting Tool (WLST) ... Welcome to WebLogic Server Administration Scripting Shell Type help() for help on available commands wls:/offline> connect("weblogic","weblogic1","t3://localhost:7001") Connecting to t3://localhost:7001 with userid weblogic ... Successfully connected to Admin Server "AdminServer" that belongs to domain "base_domain". 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:/base_domain/serverConfig> cd("/") wls:/base_domain/serverConfig> ls() dr-- AdminConsole dr-- AppDeployments dr-- BridgeDestinations dr-- Clusters dr-- CoherenceClusterSystemResources dr-- CoherenceServers ....
wlst有offline(离线)和online(在线)两种模式,通过connect命令可以从offline进入online,wlst按照Linux目录形式对weblogic资源进行管理,甚至连操作的命令都和Linux高度相似,比如cd是切换到指定资源路径下,ls()是列出该目录下所有资源。如要了解更多关于wlst的内容,可以查看官方文档。
wlst脚本本脚本原作者为Tim Hall,本文这里稍作修改,以下为脚本代码
create_managed_server.py
#!/usr/bin/python # Author : Tim Hall # Modified : Jianfeng.Zheng # Save Script as : create_managed_server.py import time import getopt import sys import re # Get location of the properties file. properties = "" try: opts, args = getopt.getopt(sys.argv[1:],"p:h::",["properies="]) except getopt.GetoptError: print "create_managed_server.py -pproperties文件" sys.exit(2) for opt, arg in opts: if opt == "-h": print "create_managed_server.py -p " sys.exit() elif opt in ("-p", "--properties"): properties = arg print "properties=", properties # Load the properties from the properties file. from java.io import FileInputStream propInputStream = FileInputStream(properties) configProps = Properties() configProps.load(propInputStream) # Set all variables from values in properties file. adminUsername=configProps.get("admin.username") adminPassword=configProps.get("admin.password") adminURL=configProps.get("admin.url") msName=configProps.get("ms.name") msAddress=configProps.get("ms.address") msPort=configProps.get("ms.port") msMachine=configProps.get("ms.machine") # Display the variable values. print "adminUsername=", adminUsername print "adminPassword=", adminPassword print "adminURL=", adminURL print "msName=", msName print "msAddress=", msAddress print "msPort=", msPort print "msMachine=", msMachine # Connect to the AdminServer. connect(adminUsername, adminPassword, adminURL) edit() startEdit() # Create the managed Server. cd("/") cmo.createServer(msName) cd("/Servers/" + msName) cmo.setListenAddress(msAddress) cmo.setListenPort(int(msPort)) # Associated with a node manager. cd("/Servers/" + msName) cmo.setMachine(getMBean("/Machines/" + msMachine)) save() activate() disconnect() exit()
脚本所需参数通过properties文件传入,以下是properties文件
api-api-managed-server.properties
# AdminServer connection details. admin.username=weblogic admin.password=weblogic1 admin.url=t3://10.1.11.71:7001 ms.name=api-server ms.address=0.0.0.0 ms.port=7002 ms.machine=api-server-machine
admin.username: weblogic管理员用户名
admin.password: weblogic管理员密码
admiin.url: weblogic控制台地址需要加上t3协议字段
ms.name: managed server名称,可以自定义
ms.address: managed server监听地址
ms.port: managed server监听端口号
ms.machine: managed server关联的计算机名称
ms.machine需要提前创建好,可以在weblogic控制台页面http://localhost:7001/console/console.portal?_nfpb=true&_pageLabel=CoreMachineMachineTablePage创建
运行将create_managed_server.py和api-api-managed-server.properties文件上传到服务器,这里上传到目录~/shell下
$ cd /u01/app/Oracle/Middleware/user_projects/domains/base_domain/bin $ . ./setDomainEnv.sh $ java weblogic.WLST ~/shell/create_managed_server.py -p ~/shell/api-managed-server.properties
ps:. ./setDomainEnv.sh第一个点(.)不能省略
执行完毕后登录console查看结果。
参考https://oracle-base.com/articles/web/wlst-create-managed-server
https://docs.oracle.com/cd/E13222_01/wls/docs90/config_scripting/using_WLST.html
文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。
转载请注明本文地址:https://www.ucloud.cn/yun/73327.html
阅读 974·2021-11-24 10:42
阅读 3522·2021-11-19 11:34
阅读 2658·2021-09-29 09:35
阅读 2543·2021-09-09 09:33
阅读 688·2021-07-26 23:38
阅读 2531·2019-08-30 10:48
阅读 1399·2019-08-28 18:07
阅读 433·2019-08-26 13:44