WEBLOGIC ADMINISTRATION UND DEPLOYMENT MIT … · Oracle WebLogic Scripting Tool Best Practices....

Preview:

Citation preview

DOAG SIG Middleware, Köln, 29. Aug. 2012

Andreas KoopConsultant

Oracle Technologies

WEBLOGIC ADMINISTRATION UND DEPLOYMENT MIT WLST

„Infrastructure as Code“

Oracle WebLogic Scripting Tool

Best Practices

Andreas KoopConsultant

Oracle TechnologiesÜBER MICH

Beratung, Training Oracle TechnologieADF Certified Implementation Specialist

CommunityDOAG, ADF EMG, ADF German Community, Twitter @multikoop

BlogTechnical http://multikoop.blogspot.comSonstiges http://www.enpit.de/blog

2

Training DevelopmentConsultingOracle Fusion Middleware

OracleADF

OracleWebLogic

OracleWebCenter

Enable productive IT by Oracle Technologies

ENTERPRISE.PRAGMATIC.IT

Andreas Koop

AGENDA

Motivation „Infrastructure as Code“

Überblick WebLogic Scripting Tool

Best Practices Administration und Deployment

4

Andreas Koop

INFRASTRUCTURE AS CODE‣ Vision - Bereitstellung einer

lauffähigen Umgebung aus

‣ Source Code Repository

‣ Anwendungsdaten (Backup)

‣ Ressourcen (Physikalisch / Virtuell)

‣ In Zeiten von Cloud und steigendem Bedarf nach horizontal skalierbaren System ist IaC unabdingbar

5

Andreas Koop

RESTORE ENV FROM CODE

6

SCM

DB / Service Endpoints

App Artefacts

App Artefacts

App Artefacts

configuration /data /

backup

app source

infra source

Sh, Chef, WLST, ...

Andreas Koop

WAS BRAUCHT EINE ORACLE FMW UMGEBUNG?‣ WebLogic Installation, Domain

‣ Application Deployment

‣ System and Performance Monitoring

‣ WebLogic Konfiguration

‣ Data Sources

‣ Message Queues

‣ Logging

‣ Diagnostics (WLDF)

‣ Security Provider

‣ ...

7

App1 App2

Andreas Koop

MANUELLE KONFIGURATION IST KEINE LÖSUNG

8

Andreas Koop

WEBLOGIC SCRIPTING TOOL‣ Jython basierte Scriptsprache zur Automatisierung jeglicher WebLogic

Administrationsaufgabe

‣ Read / Write MBeans

‣ Offline

‣ ~ ConfigurationWizard

‣ Online

‣ ~ Administration Console

9

Andreas Koop

DOMAIN ERSTELLEN

10

readTemplate(os.environ['WL_HOME'] + '/common/templates/domains/wls.jar')cd('/')cmo.setName('my_domain')cd('Servers/AdminServer')cmo.setListenAddress( 'All Local Addresses' )cmo.setListenPort( int(ADMIN_PORT) )cd( '/' )cd( 'Security/'+DOMAIN_NAME+'/User/' + ADMIN_USER ) cmo.setPassword( ADMIN_PWD )cd('/')setOption( 'JavaHome', os.environ['JAVA_HOME'] ) setOption( "ServerStartMode", "prod")setOption( "OverwriteDomain", "true" )

writeDomain( DOMAIN_DIR )closeTemplate()

Current Management Object

Andreas Koop

DOMAIN ERWEITERN

11

# Z.B. um die ADF Runtime in Form der JRFreadDomain(DOMAIN_DIR)

addTemplate(MW_HOME + '/oracle_common/common/templates/applications/jrf_templ ate_11.1.1.jar')updateDomain()closeDomain()

exit()

Andreas Koop

WLST EXECUTIONBEST PRACTICE (OFFLINE)

12

#!/bin/sh

. $PRJ_HOME/env/env.sh

. $DOMAIN_HOME/bin/setDomainEnv.sh

cd $PRJ_HOME/bin/wlstjava weblogic.WLST create.domain.py

cd -

#!/bin/sh

export DOMAIN_HOME=/oracle/fmw \/11.1.1.6/user_projects/domains \/my_domainexport DOMAIN_NAME=my_domain...

readTemplate(os.environ['WL_HOME'] + '/common/templates/domains/wls.jar')cd('/')cmo.setName(os.environ['DOMAIN_NAME'])cd('Servers/AdminServer')cmo.setListenAddress( 'All Local Addresses' )cmo.setListenPort( int(WL_ADMIN_PORT) )...

writeDomain( DOMAIN_DIR )closeTemplate()

env/env.sh

bin/create.domain.sh bin/wlst/create.domain.py

Andreas Koop

WLST EXECUTIONBEST PRACTICE (OFFLINE)

13

Andreas Koop

WLST ONLINE

14

connect('weblogic', 'welcome1', 't3://adminhost:7001')

edit()startEdit()

# do something

save()activate()

disconnect()exit()

Andreas Koop

DOMAIN ERWEITERN

15

connect('weblogic', 'welcome1', 't3://adminhost:7001')edit()startEdit()

cmo.createServer(os.environ['MS_NAME'])

cd('/Servers/'+ os.environ['MS_NAME'])cmo.setListenAddress('')cmo.setListenPort(os.environ['MS_PORT'])cmo.setListenPortEnabled(true)cmo.setJavaCompiler('javac')cmo.setMachine(getMBean('/Machines/Machine1'))cmo.setCluster('Cluster1')

cd('/Servers/'+os.environ['MS_NAME']+'/SSL/'+os.environ['MS_NAME'])cmo.setEnabled(false)

cd('/Servers/'+os.environ['MS_NAME']+'/ServerStart/'+os.environ['MS_NAME'])cmo.setArguments('-Xms512M -Xmx1024M')

save()activate()disconnect()

bin/wlst/create.server.py

Andreas Koop

MODULARIZE WLST SCRIPTS

16

connect('weblogic', 'welco..)

execfile('connect.py')execfile('start.edit.session.py')

# do something

execfile('end.edit.session.py')execfile('disconnect.py')exit()

edit()startEdit()

try: save() activate()except .....

disconnect()

bin/wlst/myscriptX.py

execfile('connect.py')execfile('start.edit.session.py')

# do something

execfile('end.edit.session.py')execfile('disconnect.py')exit()

execfile('connect.py')execfile('start.edit.session.py')

# do something

execfile('end.edit.session.py')execfile('disconnect.py')exit()

Andreas Koop

MODULARIZE WLST SCRIPTS EVEN MORE

17

# Custom Functionsimport os

def getDomainName(): return os.environ['DOMAIN_NAME']

def startEditSession(): logInfo('start edit session') edit() startEdit()...

bin/wlst/modules/enpit.utils.py

$WL_HOME/common/wlst

..startEditSession()# do somethingsaveAndActivate()..

Custom Functionsstehen dann alle Skripten zur Verfügung

Andreas Koop

WLST DOMAIN INTERACTION

18

Quelle: Oracle FMW Doc Lib

Andreas Koop

DOMAIN STARTUP

19

nmConnect('Dh4bZwJNNP', 'welcome1', DOMAIN_NAME, NM_PORT)

nmStart('AdminServer')nmStart('WLS_FORMS')nmStart('WLS_REPORTS')nmStart('WLS_DISCO')nmStart('WLS_MY_APPS')..

nmDisconnect()exit()

bin/wlst/start.domain.py

Andreas Koop

WLST NODE MANAGER ENCRYPTED PASSWORD

20

nmConnect('Dh4bZwJNNP', 'welcome1', DOMAIN_NAME, NM_PORT)storeUserConfig(userConfigFile = .., userKeyFile = .., true)disconnect()

# Ab jetzt: Anmeldung ohne Passwort im KlartextnmConnect(userConfigFile = NM_HOME + '/userconfigNM.secure', userKeyFile = NM_HOME + '/userkeyNM.secure', domainName = DOMAIN_NAME, port='5556')exit()

Andreas Koop

DOMAIN SHUTDOWN

21

NM_HOME = WL_HOME + '/common/nodemanager'nmConnect(userConfigFile = NM_HOME + '/userconfigNM.secure', userKeyFile = NM_HOME + '/userkeyNM.secure', domainName = DOMAIN_NAME, port='5556')

nmKill('WLS_FORMS')nmKill('WLS_REPORTS')nmKill('WLS_DISCO')nmKill('WLS_MY_APPS')..nmKill('AdminServer')

nmDisconnect()exit()

bin/wlst/shutdown.domain.py

Andreas Koop

LOGGING LOGGING LOGGING‣ Never-Ending-Story

‣ Was tun? Was berücksichtigen?

‣ Log Rotating

‣ Domain Log

‣ Server Logs

‣ „Wo sind die Log-Files???“

22

Andreas Koop

LOGGING KONFIGURATION

23

execfile('connect.py')execfile('start.edit.session.py')

cd('/Servers/AdminServer/Log/AdminServer')cmo.setStacktraceDepth(5)cmo.setRotationType('bySize')cmo.setDomainLogBroadcasterBufferSize(10)cmo.setLog4jLoggingEnabled(false)cmo.setNumberOfFilesLimited(false)cmo.setDateFormatPattern('dd.MM.yyyy HH:mm\' Uhr \'z')cmo.setBufferSizeKB(8)cmo.setFileMinSize(5000)cmo.setLoggerSeverity('Info')cmo.setRotateLogOnStartup(false)..cmo.setRedirectStdoutToServerLogEnabled(true)cmo.setFileName('logs/AdminServer.log')execfile('end.edit.session.py')execfile('disconnect.py')exit()

Andreas Koop

DEPLOYMENT‣ Data Source vorbereiten

‣ Targets

‣ Deploy

‣ Application

‣ Shared Libs

‣ EJBs

24

App1 App2

Java EE App

deploy

Andreas Koop

DATA SOURCE ANLEGEN‣ JNDI Lookup

25

#connect(..), edit() startEdit()cd('/')create('myDataSource', 'JDBCSystemResource')cd('JDBCSystemResource/myDataSource/JdbcResource/myDataSource')create('myJdbcDriverParams','JDBCDriverParams')cd('JDBCDriverParams/myDSName')set('DriverName','oracle.jdbc.OracleDriver')set('URL','jdbc:oracle:thin:@localhost:1521:XE')set('Password', 'HR')set('UseXADataSourceInterface', 'false')create('myProps','Properties')cd('Properties/myDSName')create('user', 'Property')cd('Property/user')cmo.setValue('HR')..cd('/JDBCSystemResource/myDataSource/JdbcResource/myDataSource')create('myJdbcDataSourceParams','JDBCDataSourceParams')cd('JDBCDataSourceParams/myDSName')set('JNDIName', java.lang.String("jdbc/hrDS"))

Andreas Koop

DATA SOURCE ENCRYPTED PASSWORD

26

akmac2:doag1_domain ak$ . ./bin/setDomainEnv.sh akmac2:doag1_domain ak$ java weblogic.security.Encrypt HR

{AES}s77UdlHeZXMziW4i8WoPxBSN/DovWtnpYEPTJbBQ70M=

Shell

..cd('/')create('myDataSource', 'JDBCSystemResource')..set('PasswordEncrypted', '{AES}s77UdlHeZXMziW4i8WoPxBSN/DovWtnpYEPTJbBQ70M=')..

set('Targets',jarray.array([ObjectName('com.bea:Name=MS1,Type=Server')], ObjectName))

create.datasource.py

Andreas Koop

APPLICATION DEPLOYMENT‣ 2 Phasen

‣ Vorbereiten

‣ Deployment Durchführen

‣ Modi

‣ No Stage

‣ Stage

‣ External Stage

27

App1 App2

Java EE App

deploy

Andreas Koop

HOW TO DEPLOY

28

connect('weblogic', 'welcome1', ADMIN_URL)

deploy('myApp', '/path/to/myApp.ear', targets='Cluster1')# targets='Server1'startApplication('myApp')

disconnect()exit()

Andreas Koop

HOW TO UNDEPLOY

29

connect('weblogic', 'welcome1', ADMIN_URL)

stopApplication('myApp')undeploy('myApp')# default: from all targets

disconnect()exit()

Andreas Koop

DEPLOYMENT COMMANDS

30

Command

deploy(appName, path, [targets], [stageMode], [planPath], [options])

startApplication(appName, [options])

stopApplication(appName, [options])

undeploy(appName,[targets],[options])

updateApplication(appName, [planPath], [options])Mittels plan.xml aktualisieren

listApplications()

Andreas Koop

‣ ...falls das Deployment mal nicht reibungslos läuft?

‣ Deploy And Backup EAR

‣ Restore

HOW TO RELAX (CUSTOM SOLUTION)

31

deploy(...)shutil.copy(...)

2012-08-02-myapp.ear2012-08-02-myapp.ear2012-08-02-myapp.ear

Keep last 10 EARs

def restore(): #Get last EAR #deploy(lastEAR)

myapp

Andreas Koop

SIDE-BY-SIDY DEPLOYMENT

32

app v1.0 app v2.0

Bestehende Client-Verbindungen

Neue Client-Verbindungen

deploy('myApp', '/path/to/myApp.ear', ..,appVersion = '1.0')

deploy('myApp', '/path/to/myApp.ear', ..,appVersion = '2.0')

Andreas Koop

SERVER MONITORING

33

..state('<ServerName>')

..

domainConfig()serverNames = cmo.getServers()domainRuntime()for name in serverNames: cd("/ServerRuntimes/"+name.getName()+"/JVMRuntime/"+name.getName()) heapFree = int(get('HeapFreeCurrent'))/(1024*1024) heapTotal = int(get('HeapSizeCurrent'))/(1024*1024) heapUsed = (heapTotal - heapFree) print '%14s %4d MB %4d MB %4d MB' % (name.getName(),heapTotal, heapFree, heapUsed)

Andreas Koop

SERVER THREAD DUMP

34

..threadDump(writeToFile='true',fileName='/tmp/threaddump.txt', serverName='AdminServer')

..

Andreas Koop

DOMAIN CONFIG AS CODE

35

wls:offline>configToScript(configPath='$DH', pyPath='config.mydomain.py')

wls:online>exportMetadata(application='doag-demo', server='AdminServer', toLocation='/tmp/exportmds'

wls:online> domainRuntime() cd(‘/DomainServices/DomainRuntimeService/DomainConfiguration/<domain>/SecurityConfiguration/<domain>/DefaultRealm/myre alm/AuthenticationProviders/DefaultAuthenticator’)cmo.exportData('DefaultAtn', '/export.ldif', Properties())

Domain Configuration

MDS per Application

User / Groups Embedded LDAP

Andreas Koop

WLST RECORDING FEATURE‣ WebLogic Console Record (Aufzeichnen)-Button klicken

‣ Gewünschte Konfiguration vornehmen

‣ Generiertes WLST-Skript anpassen und integrieren

36

Andreas Koop

CONCLUSION‣ WLST RULEZ!

‣ MUST for every Oracle FMW Admin!

‣ Vollständige Automatisierung von

‣ Domainerstellung, -konfiguration

‣ Application, Library Deployment

‣ Export / Import MDS

‣ Server - Startup / Shutdown - Monitoring

37

VIELEN DANK FÜR IHRE AUFMERKSAMKEIT

HABEN SIE NOCH FRAGEN?

Recommended