8i | 9i | 10g | 11g | 12c | 13c | 18c | Misc | PL/SQL | SQL | RAC | WebLogic | Linux

Home » Articles » Web » Here

Create a Managed Server Using WebLogic Scripting Tool (WLST)

WebLogic Scripting Tool (WLST) provides a command line scripting interface to manage WebLogic Server instances and domains. This article gives an example of creating managed servers in an existing domain using WLST. You will need to adjust the values in the properties file and may wish to alter the script to suit your needs.

The easiest way to generate WLST scripts is to use the "Record" functionality in the Administration Console. The WLST in this article was generated in that way, then amended to replace hard-coded values with parameters.

Script

Create a file called "create_managed_server.py" with the following contents.

#!/usr/bin/python
# Author : Tim Hall
# 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 -p <path-to-properties-file>'
   sys.exit(2)
for opt, arg in opts:
   if opt == '-h':
      print 'create_managed_server.py -p <path-to-properties-file>'
      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")
msCluster=configProps.get("ms.cluster")
msSSLPort=configProps.get("ms.sslport")
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 'msCluster=', msCluster
print 'msSSLPort=', msSSLPort
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))
cmo.getWebServer().setMaxRequestParamterCount(25000)

# Direct stdout and stderr.
cd('/Servers/' + msName + '/Log/' + msName)
cmo.setRedirectStderrToServerLogEnabled(true)
cmo.setRedirectStdoutToServerLogEnabled(true)
cmo.setMemoryBufferSeverity('Debug')

# Associate with a cluster.
cd('/Servers/' + msName)
cmo.setCluster(getMBean('/Clusters/' + msCluster))

# Enable SSL. Attach the keystore later.
cd('/Servers/' + msName + '/SSL/' + msName)
cmo.setEnabled(true)
cmo.setListenPort(int(msSSLPort))

# Associated with a node manager.
cd('/Servers/' + msName)
cmo.setMachine(getMBean('/Machines/' + msMachine))

# Build any data sources later.
cd('/Servers/' + msName + '/DataSource/' + msName)
cmo.setRmiJDBCSecurity(None)

# Manage logging.
cd('/Servers/' + msName + '/Log/' + msName)
cmo.setRotationType('byTime')
cmo.setFileCount(30)
cmo.setRedirectStderrToServerLogEnabled(true)
cmo.setRedirectStdoutToServerLogEnabled(true)
cmo.setMemoryBufferSeverity('Debug')
cmo.setLogFileSeverity('Notice')

save()
activate()

disconnect()
exit()

Properties

We will create two managed servers, so we will need two property files. This example assumes there is a pre-existing cluster defined in the domain.

Create a file called "myDomain-ms1.properties" with the following contents.

# AdminServer connection details.
admin.username=weblogic
admin.password=Password1
admin.url=t3://ol6.localdomain:7001

ms.name=myServer_1
ms.address=ol6.localdomain
ms.port=7002
ms.cluster=myCluster_1
ms.sslport=7502
ms.machine=ol6.localdomain

Create a file called "myDomain-ms2.properties" with the following contents.

# AdminServer connection details.
admin.username=weblogic
admin.password=Password1
admin.url=t3://ol6.localdomain:7001

ms.name=myServer_2
ms.address=ol6.localdomain
ms.port=7003
ms.cluster=myCluster_1
ms.sslport=7503
ms.machine=ol6.localdomain

Run It

Create the managed servers in an existing domain using the following commands.

# Set environment.
export MW_HOME=/u01/app/oracle/middleware
export WLS_HOME=$MW_HOME/wlserver_10.3
export WL_HOME=$WLS_HOME
export JAVA_HOME=/u01/app/oracle/jdk1.7.0_79
export PATH=$JAVA_HOME/bin:$PATH
export DOMAIN_HOME=/u01/app/oracle/config/domains/myDomain

. $DOMAIN_HOME/bin/setDomainEnv.sh

# Create the managed servers.
java weblogic.WLST create_managed_server.py -p myDomain-ms1.properties

java weblogic.WLST create_managed_server.py -p myDomain-ms2.properties

For more information see:

Hope this helps. Regards Tim...

Back to the Top.