As you might know, weblogic has the ability to store the weblogic-, and nodemanager user credentials in a UserConfig-file (See other post on this blog to see how to create these).
Using these stores can make our lives a lot easier in managing multiple weblogic environments and create a sort of 'write-once-run-anywhere'-possibility for our home-made wlst-scripts.
Most important here, is to have a uniform location for the userconfig stores.
You probably have a location like /u01 for the weblogic instances on your servers, but you could also use a common place like /var/somedir. As long as the path to the location is equal on all machines and the location itself is a safe place (we don't want to expose these files!!!), you're good.
In this example I make the following assumptions:
We have a machine that hosts 4 domains, each having it's own nodemanager (I know, not necessary, could do with one. Just for the example...)
We have a user oracle managing the weblogic server.
We have a directory /u01 in which weblogic is running.
We have stored our userconfigstores in /u01/app/wl_userconfig/${DOMAIN_NAME}
First of all, we need a file called /home/oracle/wlconfig/wlDomainList
This file contains all the data needed for loading the environment settings. As this data is bound to the server, we can place it in our home directory.
The file in our example contains the following:
# domainname domaindir adminurl nmhost nmport nmhome nmtype
1 domain1 /u01/app/domains/domain1 t3s://server.domain.com:27021 server.domain.com 7020 /u01/app/nodemanagers/MACHINE1 ssl
2 domain2 /u01/app/domains/domain2 t3s://server.domain.com:28021 server.domain.com 8020 /u01/app/nodemanagers/MACHINE2 ssl
3 domain3 /u01/app/domains/domain3 t3s://server.domain.com:25021 server.domain.com 5020 /u01/app/nodemanagers/MACHINE3 plain
4 domain4 /u01/app/domains/domain4 t3s://server.domain.com:26021 server.domain.com 6020 /u01/app/nodemanagers/MACHINE4 ssl
Make sure that you have one line per domain in the file containing:
domainname = name of the domain
domaindir = location of the domainhome
adminurl = the url to the admin server
nmhost = the servername running the nodemanager
nmport = nodemanager port number
nmhome = location of the nodemanagerhome
nmtype = plain or ssl nodemanager connection
Now, create a file /u01/app/wl_userconfig/bin/wlenvaps containing the following code.
This script will be loaded at login and will load the domain specific environment.
#declarere variabes
wlDomainList=$HOME/wlconfig/wlDomainList
wlConfigPath=/u01/app/wl_userconfig
wlConfigFile=wlconfigfile.secure
wlKeyFile=wlkeyfile.secure
nmConfigFile=nmconfigfile.secure
nmKeyFile=nmkeyfile.secure
showDomains (){
if [ -e $wlDomainList ]
then
awk '{print $1,$2}' $wlDomainList
else
echo "DomainListfile does not exist!" && exit
fi
}
enterNumber (){
echo "Please, enter the number of the domain home you wich to use:"
}
readDomain (){
read DOMAINCHOICE
}
validateDomainChoice (){
case $DOMAINCHOICE in
''|*[!0-9]*) echo "You did not enter a valid number."
playAgain;;
*) processDomain ;;
esac
}
processDomain (){
DOMHOME=$(awk "\$1 ~ /$DOMAINCHOICE/ {print \$3 }" $wlDomainList)
DOMNAME=$(awk "\$1 ~ /$DOMAINCHOICE/ {print \$2 }" $wlDomainList)
ADMINURL=$(awk "\$1 ~ /$DOMAINCHOICE/ {print \$4 }" $wlDomainList)
NMHOST=$(awk "\$1 ~ /$DOMAINCHOICE/ {print \$5 }" $wlDomainList)
NMPORT=$(awk "\$1 ~ /$DOMAINCHOICE/ {print \$6 }" $wlDomainList)
NMHOME=$(awk "\$1 ~ /$DOMAINCHOICE/ {print \$7 }" $wlDomainList)
NMTYPE=$(awk "\$1 ~ /$DOMAINCHOICE/ {print \$8 }" $wlDomainList)
if [[ ! -z $DOMHOME ]]
then
export WLDOMHOME=$DOMHOME
export WLDOMNAME=$DOMNAME
export WLCONFIGPATH=$wlConfigPath/$DOMNAME
export WLCONFIGFILE=$wlConfigPath/$DOMNAME/$wlConfigFile
export WLKEYFILE=$wlConfigPath/$DOMNAME/$wlKeyFile
export WLADMINURL=$ADMINURL
export WLNMCONFIGFILE=$wlConfigPath/$DOMNAME/$nmConfigFile
export WLNMKEYFILE=$wlConfigPath/$DOMNAME/$nmKeyFile
export WLNMHOST=$NMHOST
export WLNMPORT=$NMPORT
export WLNMHOME=$NMHOME
export WLNMTYPE=$NMTYPE
export WLSTHOME=$DOMHOME/bin
export PATH=$WLSTHOME:$PATH
echo $DOMHOME " has been loaded as your domainhome."
PS1="${USER}[${WLDOMNAME}](\${PWD})$ "
echo "Setting domain environment settings..."
. $WLDOMHOME/bin/setDomainEnv.sh
clear
else
echo "No valid Domain was loaded!"
playAgain
fi
}
playAgain (){
echo "Wanna play again? y or n"
read PLAYAGAIN
if [[ $PLAYAGAIN == 'y' ]]
then
. /w001/nfs/wl_userconfig/bin/wlenvaps
fi
}
showDomains
enterNumber
readDomain
validateDomainChoice
#Some weblogic specific aliases
alias serverstate='wlst.sh /u01/app/wlstscripts/serverState.py'
alias clusterstate='wlst.sh /u01/app/wlstscripts/clusterState.py'
alias stopallclusters='wlst.sh /u01/app/wlstscripts/stopAllClusters.py'
alias startallclusters='wlst.sh /u01/app/wlstscripts/startAllClusters.py'
alias startnm='wlst.sh /u01/app/wlstscripts/startNodeManager.py'
alias stopnm='wlst.sh /u01/app/wlstscripts/stopNodeManager.py'
alias startadmin='wlst.sh /u01/app/wlstscripts/startAdmin.py'
alias stopadmin='wlst.sh /u01/app/wlstscripts/killAdmin.py'
alias stopapp='wlst.sh /u01/app/wlstscripts/stopapp.py -a'
alias startapp='wlst.sh /u01/app/wlstscripts/startapp.py -a'
alias startcluster='wlst.sh /u01/app/wlstscripts/startCluster.py -a'
alias stopcluster='wlst.sh /u01/app/wlstscripts/stopCluster.py -a'
alias domhome='cd $WLDOMHOME'
alias nmhome='cd $WLNMHOME'
alias serverhome='cd $WLDOMHOME/servers'
Next step is to make sure that this script is called at login.
For the oracle user, in the .profile or .bash_profile (depending on your OS) in the homedir, set the following:
#LOAD WEBLOGIC DOMAIN SETTINGS
. /u01/app/wl_userconfig/bin/wlenvaps
Now, logout and login again to the oracle user. You will get the following menu:
# domainname
1 domain1
2 domain2
3 domain3
4 domain4
Please, enter the number of the domain home you wich to use:
Choose your domain. The environment settings will be loaded.
Check your variables with env | sort
You will see a bunch of WL... variables that are now available. Use them wisely ;)
At the bottom of the wlenvaps, you see I created a few aliases to wlst scripts.
Of course, these will be different in your environment.
The thing here is, that you can have a folder (/u01/app/wlstscripts/ in the example) were you can store your wlst scripts.
Make sure the location of this folder is the same on all machines. You could even create this on shared storage like nfs or so.
Now that we have set our environment variables, we can use these in our wlst scripts, so you can create the scripts once and run them on all systems that conform to these 'standards'. For example, here is the startAllClusters.py script.
Notice the Variables bit at the top. These make the scripts flexible and usable on all systems.
import os
#Variables
domain=os.getenv("WLDOMNAME")
adminUrl=os.getenv("WLADMINURL")
nmConfigFile=os.getenv("WLNMCONFIGFILE")
nmKeyFile=os.getenv("WLNMKEYFILE")
nmHost=os.getenv("WLNMHOST")
nmPort=os.getenv("WLNMPORT")
nmConnType=os.getenv("WLNMTYPE")
#Connect to NodeManager and start the admin server....
nmConnect(userConfigFile=nmConfigFile, userKeyFile=nmKeyFile, host=nmHost, port=nmPort, domainName=domain, nmType=nmConnType)
nmStart('AdminServer')
oraoas[UPA_GAT](/w001/app/wlstscripts)$ cat startAllClusters.py
import os
#Variables
adminUrl=os.getenv("WLADMINURL")
wlConfigFile=os.getenv("WLCONFIGFILE")
wlKeyFile=os.getenv("WLKEYFILE")
#Connect to Admin
print 'Connecting to AdminServer...'
connect(userConfigFile=wlConfigFile,userKeyFile=wlKeyFile,url=adminUrl)
#Get Serverstates
clusterNames = cmo.getClusters()
for clusterName in clusterNames:
cd('/')
start(clusterName.getName(),'Cluster')
disconnect()
exit()
No comments:
Post a Comment