weblogic自带一个非常强大 的脚本工具可以对weblogic进行自动化建域建实例等,还可以进行各种个性化配置,管理页面上可以实现的功能大多都可以用自动化脚本的方式来完成,工具名:wlst.sh
,脚本位于wls_home/common/bin/wlst.sh,12c中位于wls_home/oracle_common/common/bin/wlst.sh
将我们要配置的内容写入一个py文件中,执行wlst脚本读取py文件自动完成配置
注:本次使用环境为12c
命令格式:
sh wlst.sh createDomain.py
本次配置py文件内容如下:
readTemplate('/app/dufgtest/wls12/wls.jar')
(这里是复制12c环境下的wls_home/wlserver/common/templates/wls/wls.jar文件,对文件解压,修改config目录下的config.xml中的AdminServer为自己想设置的adminserver名,重新打包即可。11g下文件位置可能是wls_home/common/templates/domains/wls.jar,修改方式相同)
cd('Servers/adminserver')
set('ListenAddress','')
set('ListenPort', 20000)
cd('/')
cd('Security/base_domain/User/weblogic')
set('Name','weblogic')
set('Password','weblogic1234')
setOption('ServerStartMode', 'prod')
setOption('JavaHome','/app/mw/jdk1.8')
setOption('OverwriteDomain', 'true')
writeDomain('/app/base-domain')
closeTemplate()
startServer('adminserver','base-domain','t3://localhost:20000','weblogic','weblogic1234','/app/base-domain','true', 120000,jvmArgs='-Xms512m, -Xmx512m,-XX:MaxPermSize=256m')
connect('weblogic','weblogic1234','t3://localhost:20000')
edit()
startEdit()
cd('/Servers/adminserver/Log/adminserver')
set('RotationType','bySize')
set('FileMinSize','20480')
set('NumberOfFilesLimited','true')
set('FileCount','20')
save()
cd('/Servers/adminserver/SSL/adminserver')
set('Enabled','true')
set('ListenPort','7002')
save()
cd('/Servers/adminserver')
set('StuckThreadMaxTime','60')
save()
cd('/Servers/adminserver/OverloadProtection/adminserver/ServerFailureTrigger/')
create('adminserver')
cd('/Servers/adminserver/OverloadProtection/adminserver/ServerFailureTrigger/adminserver')
set('MaxStuckThreadTime','60')
save()
activate(block="true")
shutdown('adminserver','Server','true',0,block='false')
disconnect()
exit()
如果正常执行完成,12c环境下输出结果大致如下:
Initializing WebLogic Scripting Tool (WLST) ...
Welcome to WebLogic Server Administration Scripting Shell
Type help() for help on available commands
Starting weblogic server ...
WLST-WLS-1532510273741: Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=256m; support was removed in 8.0
WLST-WLS-1532510273741: <2018-7-25 下午05时17分54秒 CST> <Info> <Security> <BEA-090905> <Disabling the CryptoJ JCE Provider self-integrity check for better startup performance. To enable this check, specify -Dweblogic.security.allowCryptoJDefaultJCEVerification=true.>
WLST-WLS-1532510273741: <2018-7-25 下午05时17分54秒 CST> <Info> <Security> <BEA-090906> <Changing the default Random Number Generator in RSA CryptoJ from ECDRBG128 to HMACDRBG. To disable this change, specify -Dweblogic.security.allowCryptoJDefaultPRNG=true.>
WLST-WLS-1532510273741: <2018-7-25 下午05时17分54秒 CST> <Info> <WebLogicServer> <BEA-000377> <Starting WebLogic Server with Java HotSpot(TM) 64-Bit Server VM Version 25.131-b11 from Oracle Corporation.>
WLST-WLS-1532510273741: <2018-7-25 下午05时17分55秒 CST> <Info> <RCM> <BEA-2165021> <"ResourceManagement" is not enabled in this JVM. Enable "ResourceManagement" to use the WebLogic Server "Resource Consumption Management" feature. To enable "ResourceManagement", you must specify the following JVM options in the WebLogic Server instance in which the JVM runs: -XX:+UnlockCommercialFeatures -XX:+ResourceManagement.>
WLST-WLS-1532510273741: <2018-7-25 下午05时17分55秒 CST> <Info> <Management> <BEA-141107> <Version: WebLogic Server 12.2.1.3.0 Thu Aug 17 13:39:49 PDT 2017 1882952>
WLST-WLS-1532510273741: <2018-7-25 下午05时17分56秒 CST> <Notice> <WebLogicServer> <BEA-000365> <Server state changed to STARTING.>
WLST-WLS-1532510273741: <2018-7-25 下午05时17分57秒 CST> <Info> <WorkManager> <BEA-002900> <Initializing self-tuning thread pool.>
WLST-WLS-1532510273741: <2018-7-25 下午05时17分57秒 CST> <Info> <WorkManager> <BEA-002942> <CMM memory level becomes 0. Setting standby thread pool size to 256.>
WLST-WLS-1532510273741: <2018-7-25 下午05时17分57,823秒 CST> <Notice> <Log Management> <BEA-170019> <The server log file weblogic.logging.FileStreamHandler instance=1028749585
WLST-WLS-1532510273741: Current log file=/app/dufgtest/dufgtest-web-domain/servers/adminserver/logs/adminserver.log
WLST-WLS-1532510273741: Rotation dir=/app/dufgtest/dufgtest-web-domain/servers/adminserver/logs
WLST-WLS-1532510273741: is opened. All server side log events will be written to this file.>
WLST-WLS-1532510273741: <2018-7-25 下午05时17分57,960秒 CST> <Notice> <Security> <BEA-090946> <Security pre-initializing using security realm: myrealm>
WLST-WLS-1532510273741: <2018-7-25 下午05时17分58,816秒 CST> <Notice> <Security> <BEA-090947> <Security post-initializing using security realm: myrealm>
.WLST-WLS-1532510273741: <2018-7-25 下午05时17分59,965秒 CST> <Notice> <Security> <BEA-090082> <Security initialized using administrative security realm: myrealm>
WLST-WLS-1532510273741: <2018-7-25 下午05时18分00,547秒 CST> <Notice> <JMX> <BEA-149512> <JMX Connector Server started at service:jmx:iiop://20.26.28.125:20000/jndi/weblogic.management.mbeanservers.runtime.>
WLST-WLS-1532510273741: <2018-7-25 下午05时18分00,569秒 CST> <Notice> <JMX> <BEA-149512> <JMX Connector Server started at service:jmx:iiop://20.26.28.125:20000/jndi/weblogic.management.mbeanservers.domainruntime.>
WLST-WLS-1532510273741: <2018-7-25 下午05时18分00,587秒 CST> <Notice> <JMX> <BEA-149512> <JMX Connector Server started at service:jmx:iiop://20.26.28.125:20000/jndi/weblogic.management.mbeanservers.edit.>
WLST-WLS-1532510273741: <2018-7-25 下午05时18分02,112秒 CST> <Notice> <WebLogicServer> <BEA-000365> <Server state changed to STANDBY.>
WLST-WLS-1532510273741: <2018-7-25 下午05时18分02,112秒 CST> <Notice> <WebLogicServer> <BEA-000365> <Server state changed to STARTING.>
WLST-WLS-1532510273741: <2018-7-25 下午05时18分02,171秒 CST> <Notice> <Log Management> <BEA-170036> <The Logging monitoring service timer has started to check for logged message counts every 30 seconds.>
.WLST-WLS-1532510273741: <2018-7-25 下午05时18分05,209秒 CST> <Notice> <Log Management> <BEA-170027> <The server has successfully established a connection with the Domain level Diagnostic Service.>
WLST-WLS-1532510273741: <2018-7-25 下午05时18分06,480秒 CST> <Notice> <WebLogicServer> <BEA-000365> <Server state changed to ADMIN.>
WLST-WLS-1532510273741: <2018-7-25 下午05时18分06,688秒 CST> <Notice> <WebLogicServer> <BEA-000365> <Server state changed to RESUMING.>
WLST-WLS-1532510273741: <2018-7-25 下午05时18分06,743秒 CST> <Notice> <Server> <BEA-002613> <Channel "Default[1]" is now listening on 192.168.122.1:20000 for protocols iiop, t3, ldap, snmp, http.>
WLST-WLS-1532510273741: <2018-7-25 下午05时18分06,743秒 CST> <Warning> <Server> <BEA-002611> <The hostname "localhost", maps to multiple IP addresses: 127.0.0.1, 0:0:0:0:0:0:0:1.>
WLST-WLS-1532510273741: <2018-7-25 下午05时18分06,744秒 CST> <Notice> <Server> <BEA-002613> <Channel "Default" is now listening on 20.26.28.125:20000 for protocols iiop, t3, ldap, snmp, http.>
WLST-WLS-1532510273741: <2018-7-25 下午05时18分06,744秒 CST> <Notice> <Server> <BEA-002613> <Channel "Default[2]" is now listening on 0:0:0:0:0:0:0:1%lo:20000 for protocols iiop, t3, ldap, snmp, http.>
WLST-WLS-1532510273741: <2018-7-25 下午05时18分06,744秒 CST> <Notice> <Server> <BEA-002613> <Channel "Default[3]" is now listening on 127.0.0.1:20000 for protocols iiop, t3, ldap, snmp, http.>
WLST-WLS-1532510273741: <2018-7-25 下午05时18分06,745秒 CST> <Notice> <Server> <BEA-002613> <Channel "Default[1]" is now listening on 192.168.122.1:20000 for protocols iiop, t3, ldap, snmp, http.>
WLST-WLS-1532510273741: <2018-7-25 下午05时18分06,745秒 CST> <Notice> <WebLogicServer> <BEA-000329> <Started the WebLogic Server Administration Server "adminserver" for domain "dufgtest-web-domain" running in production mode.>
WLST-WLS-1532510273741: <2018-7-25 下午05时18分06,745秒 CST> <Notice> <Server> <BEA-002613> <Channel "Default" is now listening on 20.26.28.125:20000 for protocols iiop, t3, ldap, snmp, http.>
WLST-WLS-1532510273741: <2018-7-25 下午05时18分06,745秒 CST> <Notice> <Server> <BEA-002613> <Channel "Default[2]" is now listening on 0:0:0:0:0:0:0:1%lo:20000 for protocols iiop, t3, ldap, snmp, http.>
WLST-WLS-1532510273741: <2018-7-25 下午05时18分06,746秒 CST> <Notice> <Server> <BEA-002613> <Channel "Default[3]" is now listening on 127.0.0.1:20000 for protocols iiop, t3, ldap, snmp, http.>
WLST-WLS-1532510273741: <2018-7-25 下午05时18分06,766秒 CST> <Notice> <WebLogicServer> <BEA-000360> <The server started in RUNNING mode.>
WLST-WLS-1532510273741: <2018-7-25 下午05时18分06,775秒 CST> <Notice> <WebLogicServer> <BEA-000365> <Server state changed to RUNNING.>
Server started successfully.
Connecting to t3://localhost:20000 with userid weblogic ...
WLST-WLS-1532510273741: <2018-7-25 下午05时18分08,753秒 CST> <Notice> <JMX> <BEA-149535> <JMX Resiliency Activity Server=adminserver : Initializing callbacks>
WLST-WLS-1532510273741: <2018-7-25 下午05时18分08,755秒 CST> <Notice> <JMX> <BEA-149535> <JMX Resiliency Activity Server=adminserver : Added MBeanServerConnection in DomainRuntimeServiceMBean >
WLST-WLS-1532510273741: <2018-7-25 下午05时18分08,756秒 CST> <Notice> <JMX> <BEA-149535> <JMX Resiliency Activity Server=adminserver : Callback is done>
WLST-WLS-1532510273741: <2018-7-25 下午05时18分08,759秒 CST> <Notice> <JMX> <BEA-149535> <JMX Resiliency Activity Server=adminserver : Connection already exists for the server. Did not attempt to connect to the server>
Successfully connected to Admin Server "adminserver" that belongs to domain "dufgtest-web-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.
Location changed to edit tree.
This is a writable tree with DomainMBean as the root.
To make changes you will need to start an edit session via startEdit().
For more help, use help('edit').
Starting an edit session ...
Started edit session, be sure to save and activate your changes once you are done.
Saving all your changes ...
Saved all your changes successfully.
Saving all your changes ...
Saved all your changes successfully.
Saving all your changes ...
Saved all your changes successfully.
ServerFailureTrigger has been created successfully with its parents name since this mbean is an optional singleton MBean.
Saving all your changes ...
Saved all your changes successfully.
Activating all your changes, this may take a while ...
The edit lock associated with this edit session is released once the activation is completed.
WLST-WLS-1532510273741: <2018-7-25 下午05时18分23,308秒 CST> <Warning> <Management> <BEA-141239> <The non-dynamic attribute StuckThreadMaxTime on weblogic.management.configuration.ServerMBeanImpl@1678f865([dufgtest-web-domain]/Servers[adminserver]) has been changed. This may require redeploying or rebooting configured entities.>
WLST-WLS-1532510273741: <2018-7-25 下午05时18分23,308秒 CST> <Warning> <Management> <BEA-141238> <A non-dynamic change has been made which affects the server adminserver. This server must be rebooted in order to consume this change.>
WLST-WLS-1532510273741: <2018-7-25 下午05时18分23,309秒 CST> <Warning> <Management> <BEA-141239> <The non-dynamic attribute StuckThreadMaxTime on weblogic.management.configuration.ServerMBeanImpl@1678f865([dufgtest-web-domain]/Servers[adminserver]) has been changed. This may require redeploying or rebooting configured entities.>
WLST-WLS-1532510273741: <2018-7-25 下午05时18分23,309秒 CST> <Warning> <Management> <BEA-141239> <The non-dynamic attribute ServerFailureTrigger on weblogic.management.configuration.OverloadProtectionMBeanImpl@3de1d71f([dufgtest-web-domain]/Servers[adminserver]/OverloadProtection[adminserver]) has been changed. This may require redeploying or rebooting configured entities.>
WLST-WLS-1532510273741: <2018-7-25 下午05时18分23,309秒 CST> <Warning> <Management> <BEA-141238> <A non-dynamic change has been made which affects the server adminserver. This server must be rebooted in order to consume this change.>
WLST-WLS-1532510273741: <2018-7-25 下午05时18分23,310秒 CST> <Warning> <Management> <BEA-141239> <The non-dynamic attribute ServerFailureTrigger on weblogic.management.configuration.OverloadProtectionMBeanImpl@3de1d71f([dufgtest-web-domain]/Servers[adminserver]/OverloadProtection[adminserver]) has been changed. This may require redeploying or rebooting configured entities.>
The following non-dynamic attribute(s) have been changed on MBeans
that require server re-start:
MBean Changed : com.bea:Name=adminserver,Type=OverloadProtection,Server=adminserver
Attributes changed : ServerFailureTrigger
MBean Changed : com.bea:Name=adminserver,OverloadProtection=adminserver,Type=ServerFailureTrigger,Server=adminserver
Attributes changed : MaxStuckThreadTime
MBean Changed : com.bea:Name=adminserver,Type=Server
Attributes changed : StuckThreadMaxTime
Activation completed
Shutting down the server adminserver with force=false while connected to adminserver ...
WLST-WLS-1532510273741: <2018-7-25 下午05时18分23,484秒 CST> <Notice> <Server> <BEA-002638> <Graceful shutdown of adminserver was issued remotely from 20.26.28.125.>
WLST-WLS-1532510273741: <2018-7-25 下午05时18分23,494秒 CST> <Notice> <WebLogicServer> <BEA-000396> <Server shutdown has been requested by weblogic.>
WLST-WLS-1532510273741: <2018-7-25 下午05时18分23,495秒 CST> <Notice> <WebLogicServer> <BEA-000365> <Server state changed to SUSPENDING.>
The server shutdown task for server adminserver
is assigned to variable adminserverTask
You can call the getStatus(), getError(), getDescription()
or isRunning() methods on this variable to determine
the status of your server shutdown
Disconnected from weblogic server: adminserver
WLST-WLS-1532510273741: <2018-7-25 下午05时18分23,526秒 CST> <Notice> <WebLogicServer> <BEA-000365> <Server state changed to ADMIN.>
WLST-WLS-1532510273741: <2018-7-25 下午05时18分23,526秒 CST> <Notice> <WebLogicServer> <BEA-000365> <Server state changed to SHUTTING_DOWN.>
WLST-WLS-1532510273741: <2018-7-25 下午05时18分23,545秒 CST> <Notice> <Log Management> <BEA-170037> <The log monitoring service timer has been stopped.>
Disconnected from weblogic server:
Exiting WebLogic Scripting Tool.
到这里domain和adminserver都建好了,后面就是新建实例
新建实例的方法与新建域类似,都是将配置内容写入py文件,然后调用wlst脚本读取配置文件自动完成
新建createServers.py文件,内容如下:
servername = ['srv01', 'srv02', 'srv03', 'srv04']
serverport=[20001, 20002, 20003, 20004]
startServer('adminserver','base-domain','t3://localhost:20000','weblogic','weblogic1234','/app/base-domain','true', 120000,jvmArgs='-Xms512m, -Xmx512m,-XX:MaxPermSize=256m')
connect('weblogic','weblogic1234','t3://localhost:20000')
edit()
startEdit()
for i in list(range(0,len(serverport))):
name = servername[i]
port = serverport[i]
cd('/')
managedServer=create(name,'Server')
managedServer.setListenAddress('20.26.28.125')
managedServer.setListenPort(int(port))
cd('/Servers/'+name+'/Log/'+name)
set('RotationType','bySize')
set('FileMinSize','20480')
set('NumberOfFilesLimited','true')
set('FileCount','20')
save()
cd('/Servers/'+name+'/WebServer/'+name+'/WebServerLog/'+name)
set('LoggingEnabled','true')
set('RotationType','bySize')
set('NumberOfFilesLimited','true')
set('FileMinSize','5120')
set('FileCount','20')
cd('/Servers/'+name)
set('AcceptBacklog','1000')
cd('/Servers/'+name+'/OverloadProtection/'+name)
set('SharedCapacityForWorkManagers','90')
cd('/Servers/'+name+'/SSL/'+name)
set('Enabled','false')
cd('/Servers/'+name)
set('MaxOpenSockCount','6553200')
cd('/Servers/'+name)
set('StuckThreadMaxTime','60')
cd('/Servers/'+name+'/OverloadProtection/'+name+'/ServerFailureTrigger/')
create(name)
cd('/Servers/'+name+'/OverloadProtection/'+name+'/ServerFailureTrigger/'+name)
set('MaxStuckThreadTime','60')
cd('/Servers/'+name)
set('Cluster','cluster_1')
save()
activate(block="true")
命令参考:
sh wlst.sh /path/createServers.py