August 2025
M T W T F S S
 123
45678910
11121314151617
18192021222324
25262728293031

Categories

August 2025
M T W T F S S
 123
45678910
11121314151617
18192021222324
25262728293031

Automation of Monitoring Weblogic Server Runtime using WLST


Automation of Monitoring Weblogic Server Runtime using WLST

In a production environment, the health and the runtime of the Weblogic server instances must be pro-actively monitored in order to prevent the outage/interruption of the service to customers.In this post I am explaining how theWLST (WebLogic Scripting Tool) can be used to automate the monitoring of Weblogic Domains. WLST is based on Jython which is a Java implementation of Python.Since WLST is using the syntax of Python, indentation must be strictly followed.Here in the below script, we are using WLST Online mode to connect to the Admin Server of the Weblogic domain and then interact with the servers’ MBeans. Weblogic server stores the Runtime information in a hierarchical data model called MBean. Its like UNIX file system and you can use cd(), ls() and pwd() commands to navigate to the directories of Weblogic instances which are part of the domain and then you can read various Runtime attributes using the cmo.getXXXX() function. cmo stands for the Current Management Object. Below is an example statement to get the state of a Weblogic server instance.

cd(‘domainRuntime:/ServerLifeCycleRuntimes/’+serverName)
serverState=cmo.getState()

Connect() function can be used to connect to the admin server and then the serverRuntime() function can be used to switch to the domain’s runtime MBean tree. Following is the syntax for the connect function.

connect(“username”,”password”,”admin_server_url”)

Following Weblogic domain runtime attributes are monitored by this wlst script.

  • Server State
  • Server Health
  • Idle Thread Count
  • Application Status
  • JDBC Datasouce State
  • JMS Pending Messages
 
####################################################################################
# Name : weblogic_report.py
# Author  : T.Sivashanker
# Purpose   : To generate a report of various weblogic runtime attributes
####################################################################################
import thread
import sys
import string
import java.util.Date as Date
import reusername=’weblogic’
password=’admin123′
admin_url=’t3://localhost:7001’#Connect to the admin server.
try:
connect(username,password,admin_url)
except:
#Disconnect from the admin server.
disconnect()
#Exit the wlst scripting tool.
exit()
#Exit the python program.
sys.exit(0)reportStatus=’GREEN’#To get the names of all the servers in the weblogic domain.
servers = [‘admin_server’,’Managed_Server-01′,’Managed_Server-02′,’Managed_Server-03′]# Open the html file
fo = open(‘/usr/siva/reportContent.html’,’w+’);########################################################################################
###                      To get the State  of the servers                            ###
########################################################################################
for server in servers:stateColor=’lime’try:
cd(‘domainRuntime:/ServerLifeCycleRuntimes/’+server)
serverState=cmo.getState()
if(serverState != ‘RUNNING’):
stateColor=’red’
except:
serverState=’UNKNOWN’
stateColor=’red’
reportStatus=’RED’########################################################################################
###                      To get the Health of the servers                            ###
########################################################################################
for server in servers:healthColor=’lime’

try:
cd(‘domainRuntime:/ServerRuntimes/’+server)
serverStateX=cmo.getState()
tempHealthState=cmo.getHealthState().getState()
if (tempHealthState == 0):
serverHealthState=’OK’
except:
serverHealthState=’FAILED’
healthColor=’red’
reportStatus=’RED’

########################################################################################
###                          To get the Idle Thread count                            ###
########################################################################################
domainRuntime()

for server in servers:

if( string.find(server,’admin’) != -1):
continue
color=’lime’

try:
cd(‘domainRuntime:/ServerRuntimes/’+server+’/ExecuteQueueRuntimes/weblogic.kernel.Default’)
idlecount=get(‘ExecuteThreadCurrentIdleCount’)

except:
idlecount=0
color=’red’
reportStatus=’RED’

if (idlecount < 10):
color=’red’
elif(idlecount >= 10 and idlecount <20):
color=’#F8A136′
reportStatus=’AMBER’
else:
color=’lime’

########################################################################################
###                          To get the Application status                           ###
########################################################################################
domainRuntime()

cd(‘domainRuntime:/AppRuntimeStateRuntime/AppRuntimeStateRuntime’)
AppList = cmo.getApplicationIds()

for App in AppList:
color=’lime’
AppState=cmo.getIntendedState(App)

if (AppState!=’STATE_ACTIVE’):
color=’red’
reportStatus=’RED’

if( AppState == None ):
#continue
AppState=’None’

########################################################################################
###                          To get JDBC DataSource status                           ###
########################################################################################
totalCount1=0
currentCount1=0
highCount1=0
jdbcstate1=”

for server in servers:

if( string.find(server,’admin’) != -1):
continue
#currentcolor1=’lime’
jdbccolor1=’lime’

totalCount1=0
currentCount1=0
highCount1=0
jdbcstate1=”

try:
cd(‘domainRuntime:/ServerRuntimes/’+server+’/JDBCServiceRuntime/’+server+’/JDBCDataSourceRuntimeMBeans/<jdbc_name>’)

totalCount1=get(‘ConnectionsTotalCount’)
currentCount1=get(‘ActiveConnectionsCurrentCount’)
highCount1=get(‘ActiveConnectionsHighCount’)
jdbcstate1=get(‘State’)

except:
currentcolor=’red’
reportStatus=’RED’

if(jdbcstate1 != ‘Running’):
jdbcstate1=’FAILED’
jdbccolor1=’red’

########################################################################################
###                          To get JMS Pending Messages                             ###
########################################################################################
runningServers = domainRuntimeService.getServerRuntimes();
count=0

#To get the count of JMS Destinations
for server in runningServers:
tempname=str(server)
if( string.find(tempname,’admin’) != -1):
continue
jmsRuntime = server.getJMSRuntime();
jmsServers = jmsRuntime.getJMSServers();
for jmsServer in jmsServers:
destinations = jmsServer.getDestinations();

for destination in destinations:
count=count+1

break

x=0
while (x < count):
x = x + 1
print(“\
Destination”+str(x)+”\
\
“);

pendingColor=’lime’

for server in runningServers:
tempname=str(server.getName())
if( string.find(tempname,’admin’) != -1):
continue
fo.write(“\
<tr>\n\
<td>”+tempname+”</td>\n\
“);
jmsRuntime = server.getJMSRuntime();
jmsServers = jmsRuntime.getJMSServers();
for jmsServer in jmsServers:
destinations = jmsServer.getDestinations();
for destination in destinations:
pendingMessages=destination.getMessagesPendingCount()
if(pendingMessages != 0):
pendingColor=’red’
print str(pendingMessages)

for server in runningServers:
tempname=str(server.getName())
if( string.find(tempname,’admin’) != -1):
continue
jmsRuntime = server.getJMSRuntime();
jmsServers = jmsRuntime.getJMSServers();
for jmsServer in jmsServers:
destinations = jmsServer.getDestinations();

for destination in destinations:

x=destination.getName()
x = x[x.find(‘@’)+1:len(x)]

fo.write(“\
<li>\n\
“+str(x)+”\
</li>\n\
“);
break

#Disconnect from the admin server.
disconnect()
#Exit the wlst scripting tool.
exit()
#Exit the python program.
sys.exit(0)
print “the END”

Above wlst script can be run using the command javac by specifying the classpath of the weblogic.jar.

java -cp /<MIDDLE_WARE_HOME>/server/lib/weblogic.jar weblogic.WLST wls_report.py
weblogic wlst workmanager monitoring
import thread
from java.util import Date
from java.text import SimpleDateFormat
# Configured user credentials with storeUserConfig

def monitorThrds():
connect(“weblogic”, “pwd”, “t3://IP:Port”);
serverNames = getRunningServerNames()
domainRuntime()

for i in range(10000):
print ‘[‘ + SimpleDateFormat(‘d MMM yyyy HH:mm:ss’).format(java.util.Date()) + ‘]’
for sname in serverNames:
try:
cd(“domainRuntime:/ServerRuntimes/” + sname.getName() + “/MaxThreadsConstraintRuntimes/MaxThreadConstraint-oms”)
automaxexecnt=get(‘ExecutingRequests’)
automaxdefcnt = get(‘DeferredRequests’)
cd(“domainRuntime:/ServerRuntimes/” + sname.getName() + “/MaxThreadsConstraintRuntimes/MaxThreadsConstraint-oms.ws.jms”)
jmsmaxexecnt=get(‘ExecutingRequests’)
jmsmaxdefcnt = get(‘DeferredRequests’)
cd(“domainRuntime:/ServerRuntimes/” + sname.getName() + “/MinThreadsConstraintRuntimes/MinThreadsConstraint-oms.automation”)
autominexecnt=get(‘ExecutingRequests’)
autominpendcnt = get(‘PendingRequests’)
cd(“domainRuntime:/ServerRuntimes/” + sname.getName() + “/MinThreadsConstraintRuntimes/MinThreadsConstraint-oms.ws.jms”)
jmsminexecnt=get(‘ExecutingRequests’)
jmsminpendcnt = get(‘PendingRequests’)
print ‘%8s %10s  Min = ( E:%4d    P:%4d )    Max = ( E:%4d        D:%4d )’ %  (“(auto)”, sname.getName(), autominexecnt, autominpendcnt, automaxexecnt, automaxdefcnt)
print ‘%8s %10s  Min = ( E:%4d    P:%4d )    Max = ( E:%4d        D:%4d )’ %  (“(jms)”, sname.getName(), jmsminexecnt, jmsminpendcnt, jmsmaxexecnt, jmsmaxdefcnt)
except WLSTException,e:
# this typically means the server is not active, just ignore
pass
print ‘======================================================================’
print ”
import time
time.sleep(3)
def getRunningServerNames():
domainConfig()
return cmo.getServers()
if __name__== “main”:
monitorThrds()
disconnect()

weblogic wlst jms monitoring
import thread
from java.util import Date
from java.text import SimpleDateFormat
# Configured user credentials with storeUserConfig

def monitorJMS():
connect(“weblogic”, “pwd”, “t3://IP:Port”);
servers = domainRuntimeService.getServerRuntimes();
for i in range(10000):
print ‘[‘ + SimpleDateFormat(‘d MMM yyyy HH:mm:ss’).format(java.util.Date()) + ‘]’
if (len(servers) > 0):
for server in servers:
print ‘  Server Name           ‘ , server
jmsRuntime = server.getJMSRuntime();
jmsServers = jmsRuntime.getJMSServers();
for jmsServer in jmsServers:
destinations = jmsServer.getDestinations();
for destination in destinations:
print destination.getName()
print ‘  MessagesCurrentCount        ‘ ,  destination.getMessagesCurrentCount()
print ‘  MessagesHighCount           ‘ ,  destination.getMessagesHighCount()
print ‘  MessagesMovedCurrentCount   ‘ ,  destination.getMessagesMovedCurrentCount()
print ‘  MessagesPendingCount        ‘ ,  destination.getMessagesPendingCount()
print ‘  MessagesReceivedCount       ‘ ,  destination.getMessagesReceivedCount()
print ”
import time
time.sleep(10)
if __name__== “main”:
monitorJMS()
disconnect()

weblogic wlst thread monitoring
from java.util import Date
from java.text import SimpleDateFormat
# Configured user credentials with storeUserConfig

def monitorThrds():
connect(“weblogic”, “pwd”, “t3://IP:Port”);
serverNames = getRunningServerNames()
domainRuntime()

for i in range(10000):
print ‘[‘ + SimpleDateFormat(‘d MMM yyyy HH:mm:ss’).format(java.util.Date()) + ‘]’
print ‘======================================================================’
print ‘| Execute     Total    Idle    Pending     Hogging    Queue     StdBy’
print ‘| QueueName   Count    Count    Count       Count     Length    Count’
print ‘======================================================================’
for sname in serverNames:
try:
cd(“domainRuntime:/ServerRuntimes/” + sname.getName() + “/ThreadPoolRuntime/ThreadPoolRuntime”)
totcnt=get(‘ExecuteThreadTotalCount’)
idlecnt = get(‘ExecuteThreadIdleCount’)
pndcnt =get(‘PendingUserRequestCount’)
sevcnt = get(‘HoggingThreadCount’)
queuelength = get(‘QueueLength’)
stdbycnt = get(‘StandbyThreadCount’)
print ‘| %10s  %4d    %4d       %4d        %4d     %4d      %4d’ %  (sname.getName(), totcnt, idlecnt, pndcnt, sevcnt, queuelength, stdbycnt)
except WLSTException,e:
# this typically means the server is not active, just ignore
pass
print ‘======================================================================’
print ”
import time
time.sleep(3)
def getRunningServerNames():
domainConfig()
return cmo.getServers()
if __name__== “main”:
monitorThrds()
disconnect()

weblogic wlst SAF monitoring
from java.util import Date
from java.text import SimpleDateFormat
# Configured user credentials with storeUserConfig

def monitorThrds():
connect(“weblogic”, “pwd”, “t3://IP:Port”);
serverNames = getRunningServerNames()
serverRuntime()
for i in range(10000):
print ‘[‘ + SimpleDateFormat(‘d MMM yyyy HH:mm:ss’).format(java.util.Date()) + ‘]’
print ‘======================================================================’
for sname in serverNames:
try:
cd(“domainRuntime:/ServerRuntimes/” + sname.getName() + “/SAFRuntime/” +sname.getName() + “.saf/Agents”)
try:
agents=cmo.getAgents()
for agName in agents:
#print agName.getName()
cd(agName.getName())
msgpend=cmo.getMessagesPendingCount()
msgcur=cmo.getMessagesCurrentCount()
msgtot=cmo.getMessagesReceivedCount()
#print ‘%s messages received %s  = %d  %d  %d’ % (agName.getName(), sname.getName(), msgcur, msgpend, msgtot)
#print ‘%-30s %s  CUR:%5d   PEND:%5d   RECV:%5d’ % (agName.getName(), sname.getName(), msgcur,msgpend,msgtot )
print ‘%-30s  CUR:%5d   PEND:%5d  RECV:%8d’ % (agName.getName(),  msgcur,msgpend,msgtot )
cd(“..”)
except WLSTException,e:
pass
except WLSTException,e:
# this typically means the server is not active, just ignore
pass
print ‘======================================================================’
print ”
import time
time.sleep(10)
def getRunningServerNames():
domainConfig()
return cmo.getServers()
if __name__== “main”:
monitorThrds()
disconnect()

 

 

weblogic wlst jms monitoring

import thread
from java.util import Date
from java.text import SimpleDateFormat
# Configured user credentials with storeUserConfigdef monitorJMS():
connect(“weblogic”, “pwd“, “t3://IP:Port”);
servers = domainRuntimeService.getServerRuntimes();
for i in range(10000):
print ‘[‘ + SimpleDateFormat(‘d MMM yyyy HH:mm:ss’).format(java.util.Date()) + ‘]’
if (len(servers) > 0):
for server in servers:
print ‘  Server Name           ‘ , server
jmsRuntime = server.getJMSRuntime();
jmsServers = jmsRuntime.getJMSServers();
for jmsServer in jmsServers:
destinations = jmsServer.getDestinations();
for destination in destinations:
print destination.getName()
print ‘  MessagesCurrentCount        ‘ ,  destination.getMessagesCurrentCount()
print ‘  MessagesHighCount           ‘ ,  destination.getMessagesHighCount()
print ‘  MessagesMovedCurrentCount   ‘ ,  destination.getMessagesMovedCurrentCount()
print ‘  MessagesPendingCount        ‘ ,  destination.getMessagesPendingCount()
print ‘  MessagesReceivedCount       ‘ ,  destination.getMessagesReceivedCount()
print ”
import time
time.sleep(10)
if __name__== “main”:
monitorJMS()
disconnect()

WLST to monitor all Datasources on all Managed Servers by connecting only to the Admin

#connect to the admin server

domainRuntime()
allservers=ls('/ServerRuntimes/', returnMap='true')
for server in allservers:
    allds = ls('/ServerRuntimes/' + server + '/JDBCServiceRuntime/' + server + '/JDBCDataSourceRuntimeMBeans', returnMap='true')
    for ds in allds:
        cd ('/ServerRuntimes/' + server + '/JDBCServiceRuntime/' + server + '/JDBCDataSourceRuntimeMBeans/' + ds)
        print server, ds, cmo.getActiveConnectionsCurrentCount()



WLST to dump free heap memory

from java.io import FileWriter
from java.io import BufferedWriter
from java.util import Date
connect(eval('username'),eval('password'),eval('url'))
domainRuntime()
cd('/ServerRuntimes/' + eval('managedServerName') + '/JVMRuntime/' + eval('managedServerName'))
heapFreeCurrentPerOld = str(cmo.getHeapFreePercent())
heapFreeCurrentValOld = str(cmo.getHeapFreeCurrent())
cmo.runGC()
java.lang.Thread.sleep(int(eval('sleepTime')))

heapFreeCurrentPerNew = str(cmo.getHeapFreePercent())
heapFreeCurrentValNew = str(cmo.getHeapFreeCurrent())
newDate = Date()
fstream = FileWriter(eval('outputFile'),true)
out =  BufferedWriter(fstream)
out.write(eval('managedServerName') + "," + str(newDate.getTime()) + "," + heapFreeCurrentPerOld + "," + heapFreeCurrentValOld + "," + heapFreeCurrentPerNew + "," + heapFreeCurrentValNew + "\n");
out.close();
disconnect()
exit()

There is also a property file which contains the configuration information

managedServerName=<MANAGED>
username=<USER>
password=<PASSWORD>
url=<URL>
sleepTime=<PAUSE>
outputFile=<PathToFile.csv>

And finally to run

$WL_SERVER_HOME/common/bin>wlst -loadProperties

 

 

 

 

Monitoring the JCA Adapter’s through WLST script – Oracle SOA 11g

Sometimes we may need to monitor the runtime performance of the JCA adapters, the monitoring is possible through EM console for limited details, the below WLST script will help us to monitor the required details of the JCA adapter (the scrip should be extended to monitor more details).

The below script can be used for monitoring only the DBAdapter’s and MQAdapter’s; the same can be extended to monitor other JCA Adapters (like FileAdapter) .

Before executing the script change the below condition according to your server name.

if server.getName().strip().startswith(‘S’) | server.getName().strip().startswith(‘O’)

The Adapters are only available in SOA and OSB servers so that I am filtering the other servers  based on the name(AdminServer or MS servers) .The exception will be thrown if we are trying to cd the MBean related to Adapters in others servers.

 

 

 

def monitorDBAdapter(serverName):
cd(“ServerRuntimes/”+str(serverName)+”/ApplicationRuntimes/DbAdapter/ComponentRuntimes/DbAdapter/ConnectionPools”)
connectionPools = ls(returnMap=’true’)
print ‘————————————————————————————–‘
print ‘DBAdapter Runtime details for ‘+ serverName
print ‘                                                                                      ‘
print ‘                                                                                      ‘
print ‘————————————————————————————–‘

print ‘%10s %13s %15s %18s’ % (‘Connection Pool’, ‘State’, ‘Current’, ‘Created’)
print ‘%10s %10s %24s %21s’ % (”, ”, ‘Capacity’, ‘Connections’)
print ‘                                                                                      ‘
print ‘————————————————————————————–‘
for connectionPool in connectionPools:
if connectionPool!=’eis/DB/SOADemo’:
cd(‘/’)
cd(“ServerRuntimes/”+str(serverName)+”/ApplicationRuntimes/DbAdapter/ComponentRuntimes/DbAdapter/ConnectionPools/”+str(connectionPool))
print ‘%15s %15s %10s %20s’ % (cmo.getName(), cmo.getState(), cmo.getCurrentCapacity(), cmo.getConnectionsCreatedTotalCount())

print ‘                                                                                      ‘
print ‘————————————————————————————–‘

def monitorMQAdapter(serverName):
cd(“ServerRuntimes/”+str(serverName)+”/ApplicationRuntimes/MQSeriesAdapter/ComponentRuntimes/MQSeriesAdapter/ConnectionPools”)
connectionPoolsMQ = ls(returnMap=’true’)
print ‘————————————————————————————–‘
print ‘MQAdapter Runtime details for ‘+ serverName
print ‘                                                                                      ‘
print ‘                                                                                      ‘
print ‘————————————————————————————–‘

print ‘%15s %17s %15s %18s’ % (‘Connection Pool’, ‘State’, ‘Current’, ‘Created’)
print ‘%15s %15s %24s %21s’ % (”, ”, ‘Capacity’, ‘Connections’)
print ‘                                                                                      ‘
print ‘————————————————————————————–‘
for connectionPoolMQ in connectionPoolsMQ:
cd(‘/’)
cd(“ServerRuntimes/”+str(serverName)+”/ApplicationRuntimes/MQSeriesAdapter/ComponentRuntimes/MQSeriesAdapter/ConnectionPools/”)
cd(connectionPoolMQ)
print ‘%15s %20s %10s %20s’ % (cmo.getName(), cmo.getState(), cmo.getCurrentCapacity(), cmo.getConnectionsCreatedTotalCount())

print ‘                                                                                      ‘
print ‘————————————————————————————–‘

def main():
#connect(username, password, admurl)
connect(‘weblogic’,’password’,’t3://<<SOA Host>>:<<SOA Port>>’)
servers = cmo.getServers()
domainRuntime()
for server in servers:
cd(“/ServerLifeCycleRuntimes/” + server.getName())
if cmo.getState() == ‘RUNNING’:
if server.getName().strip().startswith(‘S’) | server.getName().strip().startswith(‘O’) :
monitorDBAdapter(server.getName())
for server in servers:
cd(‘/’)
cd(“/ServerLifeCycleRuntimes/” + server.getName())
if cmo.getState() == ‘RUNNING’:
if server.getName().strip().startswith(‘S’) | server.getName().strip().startswith(‘O’) :
monitorMQAdapter(server.getName())
disconnect()

main()

 

 

 

 

 

 

Server State using WLST

While trouble shooting administrator need to check the status of all server instances. This is the basic need when the all the servers are in bounced for production code move. This same script can be applicable for the pre-production or staging environment too. WLST provides the built-in methods, which gives the status of the Server instance or servers in a Cluster. Here we will deal with individual instance wise data.

ServerLifeCycle

 

Using above shown MBean hierarchy we can fetch the all WebLogic domain server instance’s states. If your production WebLogic domain consists of two digit (eg. 60 instances) or three digit number (eg. 120 instances) of managed server then, it is difficult to see all server’s state at once. Weblogic Administration console is unable to show all the servers in the domain on a single page. Navigating in between also a time eating process so think! think better way!! WLST has the solution. 

To get the status of all servers in the domain can be obtained with the following steps
1. Connect to the Admin Server
2. Fetch the server list from the domain runtime MBean
3. Iterate the loop and get the state of each managed server with Server Life Cycle Runtime MBean 
4. Repeat if required the step 3 as per the user input
5. Finally disconnect 

##################################################
# This script is used to check the status of all WL instances including the admin
###########################################################

def conn():
UCF=’/path/.AdminScripts/userConfigFile.sec’
UKF=’/path/.AdminScripts/userKeyFile.sec’
admurl = “t3://hostname:wlport”

try:
connect(userConfigFile=UCF, userKeyFile=UKF, url=admurl)
except ConnectionException,e:
print ‘\033[1;31m Unable to find admin server…\033[0m’
exit()

def ServrState():
print ‘Fetching state of every WebLogic instance’
#Fetch the state of the every WebLogic instance
for name in serverNames:
cd(“/ServerLifeCycleRuntimes/” + name.getName())
serverState = cmo.getState()
if serverState == “RUNNING”:
print ‘Server ‘ + name.getName() + ‘ is :\033[1;32m’ + serverState + ‘\033[0m’
elif serverState == “STARTING”:
print ‘Server ‘ + name.getName() + ‘ is :\033[1;33m’ + serverState + ‘\033[0m’
elif serverState == “UNKNOWN”:
print ‘Server ‘ + name.getName() + ‘ is :\033[1;34m’ + serverState + ‘\033[0m’
else:
print ‘Server ‘ + name.getName() + ‘ is :\033[1;31m’ + serverState + ‘\033[0m’
quit()

def quit():
print ‘\033[1;35mRe-Run the script HIT any key..\033[0m’
Ans = raw_input(“Are you sure Quit from WLST… (y/n)”)
if (Ans == ‘y’):
disconnect()
stopRedirect()
exit()
else:
ServrState()

if __name__== “main”:
redirect(‘./logs/Server.log’, ‘false’)
conn()
serverNames = cmo.getServers()
domainRuntime()
ServrState()

 

 

Monitor Weblogic using WLST in java

Here is the code i used to monitor the weblogic server details written in java using WLST. At times the weblogic console doesnt respond or is very slow. The script helps getting the important data needed during issues and help monitoring the server.Main parameters that we normally want to monitor :
– JVM Stats
– JMS stats
– JTA stats
– Thread Pool
– Deployed Application stateHere goes the java file , it fetches this data and writes to a text file.

Utility method to write the data to file
   public static void writeFile(StringBuffer data) {
     try {
       FileWriter outFile = new FileWriter(“C:\\ServerStats\\serverinfo.txt”);
       BufferedWriter out = new BufferedWriter(outFile);
       out.write(data.toString());
       out.close();
     }catch(Exception e){e.printStackTrace();}
  }
Main code to fetch server info :
The code is pretty simple and additional code for other parameters can be added easily.
  StringBuffer data= new StringBuffer(“Data”);
            MBeanHome home = null;
           String url = “t3://serverurl:port”;
           String username = “weblogic”;
           String password = “welcome1”;
            try {
                Environment env = new Environment();
                env.setProviderUrl(url);
                env.setSecurityPrincipal(username);
                env.setSecurityCredentials(password);
                Context ctx = env.getInitialContext();
                home = (MBeanHome) ctx.lookup(MBeanHome.ADMIN_JNDI_NAME);
            } catch (Exception e) {System.out.println(“Exception caught: ” + e);}
            try {
                data.append(“DOMAIN NAME :  ” +  home.getActiveDomain().getName() +”\n”);
            } catch (Exception e) {System.out.println(“Exception: ” + e);}
           Set mbeanSet = home.getMBeansByType(“ServerRuntime”);
           data.append(“Number of servers in the domain: ” + mbeanSet.size() +”\n”);
            Iterator mbeanIterator = mbeanSet.iterator();
            int cls=1;
            while(mbeanIterator.hasNext()) {
                ServerRuntimeMBean serverRuntime =  (ServerRuntimeMBean)mbeanIterator.next();
              if(cls==1)
              {
              try{
              ClusterRuntimeMBean clusterruntime = serverRuntime.getClusterRuntime();
              data.append(“————- CLUSTER INFORMATION—————” + “\n”);
              data.append(“1. Cluster Name :  “+clusterruntime.getName()+”\n”);
              data.append(“2. Cluster MulticastMessagesLostCount : “+clusterruntime.getMulticastMessagesLostCount()+”\n”);
              data.append(“3. Cluster Server Names  “+”\n”);
                  for(int j=0;j<clusterruntime.getServerNames().length;j++) {
                    data.append(” Server :  “+(clusterruntime.getServerNames())[j] + “\n”);
                  }
              data.append(“—————————————————————————- “+”\n”);
              }catch(Exception e){e.printStackTrace();}
              }
              //if(cls==1)
              //{
              try{
                data.append(“————- WEB SERVER INFORMATION—————” + “\n”);
              WebServerRuntimeMBean[] webserverruntime = serverRuntime.getWebServerRuntimes();
              for(int j=0;j<webserverruntime.length;j++) {
                data.append(“1. Web server info : Web server Names  “+webserverruntime[j].getWebServerName()+”\n”);
              }
                data.append(“—————————————————————————- “+”\n”);
              }catch(Exception e){e.printStackTrace();}
            if(serverRuntime.getState().equals(ServerStates.RUNNING)){
              data.append(“—————————————————————————- “+”\n”);
              data.append(” INFO STARTS FOR SERVER “+serverRuntime.getName()+” ******”+”\n”);
              data.append(“—————————————————————————- “+”\n”);
                     data.append(“1. Server Name = ” + serverRuntime.getName()+”\n”);
                     data.append(“2. Server ListenAddress = ” +  serverRuntime.getListenAddress()+”\n”);
                     data.append(“3. Server ListenPort = ” +  serverRuntime.getListenPort()+”\n”);
                     data.append(“4. Admin server Host = ” +  serverRuntime.getAdminServerHost()+”\n”);
                     data.append(“5. Health state = ” +  serverRuntime.getHealthState()+”\n”);
                  data.append(“—————————————————————————- “+”\n”);
                  data.append(” JVM Parameters For SERVER “+serverRuntime.getName()+”\n”);
                  data.append(“—————————————————————————- “+”\n”);
                  JVMRuntimeMBean jvmruntime = serverRuntime.getJVMRuntime();
                  data.append(“1. JVM Current Heap size = ” + jvmruntime.getHeapSizeCurrent()+”\n”);
                  data.append(“2. JVM  Heap free Current  = ” + jvmruntime.getHeapFreeCurrent()+”\n”);
                  data.append(“3. JVM  Heap free Percent = ” + jvmruntime.getHeapFreePercent()+”%”+”\n”);
                  data.append(“4. JVM  Heap size max = ” + jvmruntime.getHeapSizeMax()+”\n”);
                  data.append(“5. JVM  JavaVersion = ” + jvmruntime.getJavaVersion()+”\n”);
                  data.append(“6. JVM  JavaVendor = ” + jvmruntime.getJavaVendor()+”\n”);
                  try{
                    ExecuteQueueRuntimeMBean[] executeQueueRuntime =serverRuntime.getExecuteQueueRuntimes();
                    data.append(“—————————————————————————- “+”\n”);
                    data.append(” Execute Queue Runtime parameters “+”\n”);
                    data.append(“—————————————————————————- “+”\n”);
                      for(int j =0;j<executeQueueRuntime.length;j++)
                      {
                        data.append(“1. Execute Queue ThreadTotalCount =  “+executeQueueRuntime[j].getExecuteThreadTotalCount()+”\n”);
                        data.append(“2. Execute Queue ThreadCurrentIdleCount =  “+executeQueueRuntime[j].getExecuteThreadCurrentIdleCount()+”\n”);
                        data.append(“3. Pending RequestCurrentCount =  “+executeQueueRuntime[j].getPendingRequestCurrentCount()+”\n”);
                        data.append(“4. PendingRequestOldestTime =  “+executeQueueRuntime[j].getPendingRequestOldestTime()+”\n”);
                      }
                  }catch(Exception e){e.printStackTrace();}
                  data.append(“—————————————————————————- “+”\n”);
                  data.append(”  JTA STATS FOR SERVER “+serverRuntime.getName() +”\n”);
                  data.append(“—————————————————————————- “+”\n”);
                  JTARuntimeMBean jtaruntime= serverRuntime.getJTARuntime();
                   data.append( “1. Total Trx = ” + jtaruntime.getActiveTransactionsTotalCount()+”\n”);
                   data.append( “2. Total Abondened Trx = ” + jtaruntime.getTransactionAbandonedTotalCount()+”\n”);
                   data.append( “3. Total Commited Trx = ” + jtaruntime.getTransactionCommittedTotalCount()+”\n”);
                  data.append(“—————————————————————————- “+”\n”);
                  data.append(” JMS Parameters FOR SERVER  “+serverRuntime.getName()+”\n”);
                  data.append(“—————————————————————————- “+”\n”);
                  JMSRuntimeMBean jmsruntime= serverRuntime.getJMSRuntime();
                  JMSServerRuntimeMBean[] jmsservers= jmsruntime.getJMSServers();
                  for(int i=0;i<jmsservers.length;i++)
                  {
                     data.append( “1. JMS Server Name = “+jmsservers[i].getName()+”\n”);
                     data.append( “2. MessagesHighCount = “+jmsservers[i].getMessagesHighCount()+”\n”);
                     data.append( “3. MessagesPendingCount = “+jmsservers[i].getMessagesPendingCount()+”\n”);
                     data.append( “3. DestinationsCurrentCount = “+jmsservers[i].getDestinationsCurrentCount()+”\n”);
                  }
                  data.append(“4. JMS Health : ” + jmsruntime.getHealthState()+”\n”);
                  data.append(“—————————————————————————- “+”\n”);
                  data.append(“—————————————————————————- “+”\n”);
                  data.append(” Application Runtime Data FOR SERVER  “+serverRuntime.getName()+”\n”);
                  data.append(“—————————————————————————- “+”\n”);
                 ApplicationRuntimeMBean[] appruntime = serverRuntime.getApplicationRuntimes();
                 for(int j=0;j<appruntime.length;j++)
                 {
                   if(appruntime[j].isEAR())
                   {
                    data.append(“Application Name : ” +appruntime[j].getApplicationName() +”\n”);
                    data.append(“Application Name : ” +appruntime[j].getHealthState() +”\n”);
                   }
                 }
                 // ThreadPoolRuntimeMBean tpoolruntime=serverRuntime.getThreadPoolRuntime();
                    data.append(” INFO ENDS FOR SERVER “+serverRuntime.getName() +”\n”);
                }
              cls++;
            }//while ends
            writeFile(data);

 

 

WEBLOGIC MONITORING SCRIPT in WLST Tool

Web Logic Monitoring Script in WLST which would monitor JVM, Execute Queue, JDBC and JMS resources of all the Web Logic instances running in a domain. Please feel free to modify the script as necessary.

WLST Script:


# WLST WebLogic Server Monitoring Scriptusername=’wxyz’
password=’******’
urldict={}
connect(username,password,’t3://kyarpt5q:9001′)
serverlist=adminHome.getMBeansByType(‘Server’)
for svr in serverlist:
urldict[svr.getName()]=’t3://’+svr.getListenAddress()+’:’+str(svr.getListenPort())
disconnect()

for svr,url in urldict.items():
try:
connect(username,password,url)
jvmrtlist=home.getMBeansByType(‘JVMRuntime’)
print ‘ ‘
print ‘ ‘ 
print ‘The Runtime Stats of Server: ‘+svr 
print ‘ ‘
print ‘JVM’
print ‘ ‘
print ‘FreeJVM TotalJVM UsedJVM’ 
print ‘ ‘
for jvmRT in jvmrtlist:
freejvm = jvmRT.getAttribute(“HeapFreeCurrent”)
totaljvm = jvmRT.getAttribute(“HeapSizeCurrent”)
usedjvm = (totaljvm – freejvm)
print freejvm,’ ‘,totaljvm,’ ‘,usedjvm
print ‘ ‘

eqrtlist=home.getMBeansByType(‘ExecuteQueueRuntime’)
print ‘ ‘
print ‘ ‘
print ‘EXECUTE QUEUES’
print ‘ ‘
print ‘ExecuteQueueName TotalCount CurrIdleCount PendRequestCurrCount ServicedRequestTotalCount’
print ‘ ‘
for eqRT in eqrtlist:
eqname = eqRT.getAttribute(“Name”)
eqtthreads = eqRT.getAttribute(“ExecuteThreadTotalCount”)
eqithreads = eqRT.getAttribute(“ExecuteThreadCurrentIdleCount”)
eqqc = eqRT.getAttribute(“PendingRequestCurrentCount”)
eqthrougp = eqRT.getAttribute(“ServicedRequestTotalCount”)
print eqname,’ ‘,eqtthreads,’ ‘,eqithreads,’ ‘,eqqc,’ ‘,eqthrougp
print ‘ ‘

poolrtlist=home.getMBeansByType(‘JDBCConnectionPoolRuntime’)
print ‘ ‘
print ‘ ‘
print ‘JDBC CONNECTION POOLS’
print ‘ ‘
print ‘Name Maxcapacity ActiveCurrent ActiveHighCount WaitSecondsHighCount WaitingCurrentCount State’
print ‘ ‘
for poolRT in poolrtlist:
pname = poolRT.getName()
pmaxcapacity = poolRT.getAttribute(“MaxCapacity”)
paccc = poolRT.getAttribute(“ActiveConnectionsCurrentCount”)
pachc = poolRT.getAttribute(“ActiveConnectionsHighCount”)
pwshc = poolRT.getAttribute(“WaitSecondsHighCount”)
pwfccc = poolRT.getAttribute(“WaitingForConnectionCurrentCount”)
pstate = poolRT.getAttribute(“State”)
print pname,’ ‘,pmaxcapacity,’ ‘,paccc,’ ‘,pachc,’ ‘, pwshc,’ ‘,pwfccc,’ ‘,pstate
print ‘ ‘

jmsrtlist=home.getMBeansByType(‘JMSDestinationRuntime’)
print ‘ ‘
print ‘ ‘
print ‘JMS DESTINATIONS’
print ‘ ‘
print ‘Name ByteCurr Pending Received High MsgCurr Pending High Received ConsumersTotal’ 
print ‘ ‘
for jmsRT in jmsrtlist:
jmsname = jmsRT.getAttribute(“Name”)
jmsbcc = jmsRT.getAttribute(“BytesCurrentCount”)
jmsbpc = jmsRT.getAttribute(“BytesPendingCount”)
jmsbrc = jmsRT.getAttribute(“BytesReceivedCount”)
jmsbhc = jmsRT.getAttribute(“BytesHighCount”)
jmsmcc = jmsRT.getAttribute(“MessagesCurrentCount”)
jmsmpc = jmsRT.getAttribute(“MessagesPendingCount”)
jmsmhc = jmsRT.getAttribute(“MessagesHighCount”)
jmsmrc = jmsRT.getAttribute(“MessagesReceivedCount”)
jmsctc = jmsRT.getAttribute(“ConsumersTotalCount”)
print jmsname,’ ‘,jmsbcc,’ ‘,jmsbpc,’ ‘,jmsbrc,’ ‘,jmsbhc,’ ‘,jmsmcc,’ ‘,jmsmpc,’ ‘,jmsmhc,’ ‘, jmsmrc,’ ‘,jmsctc
print ‘ ‘

disconnect()
except:
print “Skipping “+svr
continue

 

T3 Protocol

Handling weblogic T3 protocol message size issues

Do not be surprised when you see an error like below in weblogic server logs.

Incoming message of size: ‘10000080’ bytes exceeds the configured maximum of: ‘10000000’ bytes for protocol: ‘t3

In nutshell, above error happens when weblogic server is trying to process a message of size more than 10MB.

Most of the times it is JMS message processing of course, it  need not be always JMS.

First lets understand what is T3 and how it works.

T3 is a proprietary communication protocol being used by WLS to handle data traffic between java to java applications or JVM to JVM

WLS has a mechanism to keep track of JVMs with which it is connected and always creates just one connection to the connected JVM.

These connected JVMs could be server JVM to server JVM or client JVM to server JVM.

For example, if a Java client accesses JSP page  and a JDBC connection pool on WebLogic Server, a single network connection is established between the WebLogic Server JVM and the client JVM. This eliminates the need of creating multiple connections and managing them.T3 protocol also does multiplexing data packets invisibly on the single connection

Features of T3 protocol

  • High performance for various above said reasons
  • Multiplexes various data sources data packets into single connection
  • Minimizes the packet size

By default T3 protocol is configured to handle messages of size 10 MB, if server receives messages more than 10 MB size then it can not handle.

As per my knowledge there are three options to handles this.

Option#1(Preferable)

Try to analyze why server is receiving that huge payload, who is sending it.In general it is not advisable to handle huge messages unless really really required.

10 MB set by WLS is reasonable value and most appropriate for many environments.

so solution is try to reduce the payload size.

Before sending  huge message I suggest transform it to condensed form.

XML is verbose.So lets be very careful about it.

Solution to reduce paylaod size:

Transform from source element to target element only if source element has data in it.This has to be done for each element.This will reduce the size.

Option#2(Chunked messages)

There are some ways to send big messages in small pieces.For example in http, we can use chunked mode transfer and OSB also supports transferring messages in chunked mode.

Option#3(Increasing message size)

If option#1 and 2 does not help you then you can try out this.

  1. Go to servers—>protocols—>general—>max message size—>change it to required value (Do it for both the admin and the soa servers)
  1. Go to servers—>configuration—>server start—>arguments—>-Dweblogic.MaxMessageSize = same value given in previous step

bounce the servers.

WebLogic server Administration

  WebLogic server Administration

 

WebLogic Server: Oracle WebLogic is a server software application that runs on a middle tier, between back-end databases and related applications an browser-based thin clients. WebLogic is a leading e-commerce online transaction processing (OLTP) platform, developed to connect users in a distributed computing environment and to facilitate the integration of mainframe applications with distributed corporate data and applications.
WebLogic server is based on Java2 Platform, Enterprise Edition (J2EE), the standard platform used to create Java-based multi-tier enterprise applications.
Oracle WebLogic Server 12c is the industry’s best application server for building and deploying enterprise Java EE applications with support for new features for lowering cost of operations, improving performance, enhancing scalability and supporting the Oracle Applications portfolio.

WebLogic Server 12c (12.1.1) – March 2012
WebLogic Server 12c (12.0) – December 1, 2011
WebLogic Server 11gR1 PS5 (10.3.6) – February 2012
WebLogic Server 11gR1 PS4 (10.3.5) – May 16, 2011
WebLogic Server 11gR1 PS3 (10.3.4) – January 15, 2011
WebLogic Server 11gR1 PS2 (10.3.3) – April 2010
WebLogic Server 11gR1 PS1 (10.3.2) – November 2009
WebLogic Server 11g (10.3.1) – July 2009
WebLogic Server 10.3 – August 2008
WebLogic Server 10.0 – March 2007
WebLogic Server 9.2
WebLogic Server 9.1
WebLogic Server 9.0 – November 2006
WebLogic Server 8.1 – July 2003
WebLogic Server 7.0 – June 2002
WebLogic Server 6.1
WebLogic Server 6.0 – file date March 2001 on an old CD
WebLogic Server 5.1 (code name: Denali) First version supporting hot deployment for applications (via command line)
WebLogic Server 4.0
WebLogic Tengah 3.1 – June 1998
WebLogic Tengah 3.0.1 – March 1998
WebLogic Tengah 3.0 – January 1998
WebLogic Tengah – November 1997

The table below lists major standards supported by WebLogic Server product version.

Standard WLS 7.0 WLS 8.1 WLS 9.0 WLS 10.0 WLS 10.3 WLS 12c
Java 1.3 1.4 5 5 6 (7 in 10.3.6+) 7
Java EE 1.3 1.3 1.4 5 5 6
Servlet 1.2 2.3 2.4 2.5 2.5 3.0
JSP 1.2 1.2 2.0 2.1 2.1 2.2
EJB 2.0 2.0 2.1 3.0 3.0 3.1
JDBC 2.0 2.0 3.0 3.0 3.0 4.0

Difference between web server and application server:

                      Webserver
1) Webserver handles the HTTP protocol. When
the Web server receives an HTTP request,
it responds with an HTTP response, such as
sending back an HTML page.
2) Web Server serves static HTML pages or
gifs, jpegs, etc., and can also run code written
in CGI, JSP etc.
3) Web Server only supports Servlets and JSP.

 

                  Application Server

1) It serves business logic to application
programs through any number of protocols

2) Application server is more capable of
dynamic behavior than webserver. We can
also configure application server to work
as a webserver. Simply application server is a
superset of webserver.

3)Application Server supports distributed
transaction and EJB.

4) An Application Server is used to run business logic
or dynamically generated presentation code.
It can either be .NET based or J2EE based

Domain: An Oracle WebLogic Server administration domain is a logically related group of Oracle WebLogic Server resources. Domains include a special Oracle WebLogic Server instance called the Administration Server, which is the central point from which you configure and manage all resources in the domain. Usually, you configure a domain to include additional Oracle WebLogic Server instances called Managed Servers. You deploy Web applications, EJBs, Web Services, and other resources onto the Managed Servers and use the Administration Server for configuration and management purposes only.
Node Manager:
 Node Manager is a WebLogic Server utility that enables you to start, shut down, and restart Administration Server and Managed Server instances from a remote location. Although Node Manager is optional, it is recommended if your WebLogic Server environment hosts applications with high availability requirements.

A Node Manager process is not associated with a specific WebLogic domain but with a machine. You can use the same Node Manager process to control server instances in any WebLogic Server domain, as long as the server instances reside on the same machine as the Node Manager process. Node Manager must run on each computer that hosts WebLogic Server instances—whether Administration Server or Managed Server—that you want to control with Node Manager.

WebLogic Server provides two versions of Node Manager, Java-based and script-based, with similar functionality. However, each version has different configuration and security considerations.

Java-based Node Manager: Java-based Node Manager runs within a Java Virtual Machine (JVM) process. It is recommended that you run it as a Windows service on Windows platforms and as an operating system service on UNIX platforms, allowing it to restart automatically when the system is rebooted.

Oracle provides native Node Manager Libraries for Windows, Solaris, HP UX, Linux on Intel, Linux on Z-Series, and AIX operating systems.

Note: Node Manager is not supported on Open VMS,OS/390,AS400,UnixWare/Tru64 UNIX.

Script-based Node Manager: For UNIX and Linux systems, WebLogic Server provides a script-based version of Node Manager. This script is based on UNIX shell scripts, but uses SSH for increased security. SSH uses user-id based security. For information on configuring the script version of Node Manager, see Configuring Script Node Manager.


Note: 
It is recommended that you run script-based Node Manager as Operating System services, which allows to restart automatically when the system is rebooted.This version does not provide as much security as the Java-based version. However, the advantage of the script-based Node Manager is that it can remotely manage servers over a network that has been configured to use SSH. No additional server installation is required. The scripts merely have to be copied to the remote machine.

Administration Server: Admin Server is an instance of Weblogic server. The Administration Server operates as the central control entity for the configuration of the entire domain. It maintains the domain’s configuration documents and distributes changes in the configuration documents to Managed Servers. You can also use the Administration Server as a central location from which to monitor all resources in a domain.

Managed server: Apart from Admin Server any weblogic server instance is called Managed server. To prevent the Administration Server from becoming a single point of failure, Managed Servers can always function without the presence a running Administration Server. When a Managed Server starts, it contacts the Administration Server to retrieve its configuration information. If a Managed Server is unable to connect to the specified Administration Server during startup, it can retrieve its configuration directly by reading a copy of the config.xml file and other files located on the Managed Server’s own file system.

Cluster: A WebLogic Server cluster consists of multiple WebLogic Server instances running simultaneously and working together to provide increased scalability and reliability. A cluster appears to clients to be a single WebLogic Server instance. The server instances that constitute a cluster can run on the same machine, or be located on different machines. You can increase a cluster’s capacity by adding additional server instances to the cluster on an existing machine, or you can add machines to the cluster to host the incremental server instances. Each server instance in a cluster must run the same version of WebLogic Server.

A cluster is defined as a group of application servers that transparently run a J2EE application as if it were a single entity.  There are two methods of clustering:  vertical scaling and horizontal scaling

Horizontal clustering: It involves running multiple Java application servers that are run on two or more separate physical machinesHorizontal scaling is more reliable than vertical scaling, since there are multiple machines involved in the cluster environment, as compared to only one machine.
Vertical clustering: However, consists of multiple Java application servers on a single physical machine. With vertical scaling, the machine’s processing power, CPU usage, and JVM heap memory configurations are the main factors in deciding how many server instances should be run on one machine

Proxy Server: Proxy Server is an intermediary server between your web browser (client) which requests for some information/data and your server (web server/Application server) that process the data.

Types of Proxy Server: They are three different types of proxy servers. They are as follows

1) Forward Proxy Servers: Forward Proxy Server is a server which forwards the request from the intranet clients (web browser) to the internet servers. These proxy servers are present in the same network of your client.

2) Open Proxy Server: An open proxy is a proxy server which is accessible by any Internet user. Any proxy server that doesn’t restrict its client base to its own set of clients and allows any other client to connect to it is known as an “Open Proxy”. An anonymous open proxy allows users to conceal their IP address while browsing the Web or using other Internet services. They are in numerous open proxy servers present in Internet. For converting any flavor of proxy servers to Open Proxy servers we just have to enable the flag “ProxyRequests On” in the configuration file.

3) Reverse Proxy Server: A Proxy Server which takes requests from external clients (web browsers) or Internet and forwards them to servers in an internal network is called as Reverse Proxy Server. Generally, the reverse proxy servers are present in the same network where we have our App/Web servers.

Advantages of using Reverse Proxy Servers: The various advantages of using the proxy servers are as follows

1)      Filtering

2)      Caching

3)      Bypassing filters and censorship

4)      Logging and eavesdropping

5)      Gateways to private networks

6)      Accessing services anonymously

Fire wall: It provide filtering, autherization& Authentication services.

It can act as proxy servers.

Mapping port requests.

Machine: A machine is a computer that host WebLogic server.

A machine runs a supported o.s platform.

Can host multiple WebLogic server instances.

WebLogic server Life Cycle:

Starting state: During the starting state that instances ready the domain configuration data from its configuration directory. Whereas the Manager server will get their configuration data from Admin server. It is in this state that the instance the basic services such as the kernal and execute queues, the container service for logging and Node manager service. The server also deploy during this phase.

Stand by: In this state the server Instance will allow you to issue just to administrative requests. You can me the server state either running or shutdown state. Normally the server instance will automatically transition through the stand by state to next stage unless you start the instance with the start in stand by command.

Note: All ports are closed in this stat. But you can quickly transition to a running state.

Admin mode: The admin mode permits only Administrative task, deploying applications with those applications being able to only request from users with the admin and App tester roles. Running a server in admin mode is also useful when trying to diagnose problems with application gone badly.

Note: Servers will run in admin mode when there is problem with deployed application or JDBC connection pool.we can resume the server from Admin state to resume state.

Resuming state: This is purely transitional state the server instance goes through after it transitions automatically through Admin state or you issue the resume command after first placing the instance in the stand by or Admin state. You can do this state change from command line or through the Admin console.

Running state: This is off course final state the server instance reaches after you either issue a start up command or resume command to move the server out of the Admin or stand by state. It is in the running state that the server can accept the service client request for it services.

WebLogic Installation: There are 3 types of installations

  1. GUI mode.
  2. Console mode.
  3. Silent mode.

1) GUI Mode:

Step1: welcome screen

Step2: Accept license agreement.

Step3: Create new BEA home directory

C:\bea10.3

Step4: Choose installation- Complete (or) Custom

Step5.Select complete

Step6.Select product installation directory

C:\bea10.3\wlserver_10.3

2) Console Mode:

server10.3_win32.exe  -mode = console

3) Silent Mode:   It is a way of setting installation configuration only once and then using those configurations to duplicate the installation on many machines.

The installation programs read the settings for your configuration from an xml file.(silent.xml)

server10.3_win32.exe -mode=silent -silent.xml=c:\bea10.3\silent.xml  -log=c:\10.3\silent.log

Step1: Create silent.xml file

<?xml version=”1.0″ encoding=”ISO-8859-1″ ?>

<bea-installer>

<input-fields>

<data-value name=”BEAHOME” value=”C:\bea10.3″ />

<data-value name=”USER_INSTALL_DIR” value=”C:\bea10.3\wlserver_10.3″ />

</input-fields>

</bea-installer>

Step2: Save this file as silent.xml file in C:\bea10.3 folder

Step3: Copy the WebLogic software under C:\bea10.3 folder

Step4: Create a sub folder wlserver_10.3 under c:\bea10.3

Step5: Execute the below command

server103_win32.exe -mode=silent -silent_xml=C:\bea10.3\ silent.xml  -log=C:\10.3\silent.log

Domain creation using configuration wizard:

Step1: Goto the below path and execute config.cmd script

C:\bea10.3\wlserver_10.3\common\bin>config.cmd

Step2: Select – Create new WebLogic domain

Step3: Select – Base this domain on an existing template

Step4: Configure Administrator username and password.

Step5: Configure server start mode and JDK

Development mode   —- SunJdk

Production mode   —– Jrocket

Select development mode and SunJdk

Step6: Customize environment & services settings

Select yes if you would like to configure resources

Step7: Configure Admin server

Name : AdminServer

Listen address: localhost

Listen port : 7001

SSL listen:  None

** Default port number for AdminServer-7001

** Default ssl listen port : 7002

Step8: Configure managed servers

name    listen address     listen port   ssl listen port

ms1      localhost              7003            None

ms2      localhost               7004           None

Step9: Configure cluster

Name Multicast address  multicast port  cluster address

c1          239.192.0.0        7010            localhost:7003, localhost:7004

Step 10: Assign servers to clusters

Step 11: Configure machines

Name   NodeManagerListenAddress   NodeManagerListenPort

m1                 localhost                                5556

Step 12: Assign servers to machines

Step 13: Create WebLogic domain

Enter the name and location for the domain

Domain name : dev_domain

Domain location : c:\bea10.3\user_projects\domains

Step 14:  Click on Create

  1. Q) How to start Admin server?

C:\bea10.3\user_projects\domains\dev_domain\bin>startWebLogic.cmd

  1. Q) How to Access Admin console?

http://localhost:7001/console

  1. Q) Starting managed servers without node manager?

If Adminserver is in another machine: c:\bea\user_projects\domains\webdomain\bin>startmanagedWebLogic.cmd ms1 http://localhost:7001 (Adminserver port number)

If Adminserver is in same machine: c:\bea\user_projects\domains\maindomain\bin>startmanagedWebLogic.cmd ms1

  1. Q) How to stop Admin server?

StopWebLogic.cmd   —–Windows

StopWebLogic.sh   ——-Unix

  1. Q) How To stop managed server?

StopManagedWebLogic.cmd ms1

  1. Q) How to start Nodemanager?

C:\bea10\wlserver_10.3\server\bin>startNodemanager.cmd

Creating managed servers from console:

Step1: Click on Lock& Edit

Step2: Navigate to servers and then click on new

Step3: Create a new server

Step4: Provide server properties

Server name : ms3

Server listen address: localhost

Server listen port: 7005

Step5: Select – this is a stand alone server

Step6: Review choices

Step7: Activate changes

Assigning server to cluster:

Step1: Navigate to cluster-cluster name-servers

Step2:  Click on Lock & Edit

Step3:  Add

Add server to cluster

Select existing server and add it as a cluster

Step4: Activate changes

Adding servers to machines:

Step1: Navigate to machines-m1-servers

Step2: Lock& Edit

Step3: Add

Step4: Activate changes

How to check Node manager status from console:

We can’t Start Node manager from console

Step1: Click on machines

Step2: Select m1

Step3: Click on monitoring

Clone: It creates other server with same properties.

we can clone servers machines and clusters.

we should not cluster managed server while the server is running.

–>boot.properties-it contains username and password

–>Development mode-automatically creates boot.properties file

–> Production mode-we have to create boot.properties file.

–> setDomainEnv -we can change the mode from development to production or production to development modedoing changes in this file.

Different between development mode and production mode

                Development mode

1) The default JDK for development domain
is SunHotSopt.(SunJdk)
2) It uses demo certificate for SSL

3) In this mode Auto deployment is enabled.

4) Server instances rotate their log files on startup.

5) Admin server uses an automatically
created boot.properties during startup.

6) The default maximum capacity for JDBC
Data source is 15.

7) The debug flag which is used to start
Weblogic workshop debugger is enabled.

                      Production mode

1) The default JDK for production domain
is JRocket.

2) It is used demo certificate for SSL a warning
is displayed.

3) In this mode Auto deployment is disabled.

4) Server instances states their log files when
it reaches 5Mb

5) Admin server prompt for username
and password during startup.

6) The default maximum capacity for JDBC                 Data source is 25.

7) The debug flag which used to start
WebLogic workshop debugger is disabled.

Deployments

Deployment an application involves the following tasks:

Preparing:  Choosing weather to package the application as an archived file or keep in an exploded directory.

Configuring: Creating a deployment plan to maintain the configuration changes without changes the deployment descriptors.

Deploying: Targeting and distributing the application to servers in an OracleWebLogicServer domain.

Deploment Methods: WLS (WebLogic scripting) supports three types of deployment methods.

  1.  Auto-deployment
  2. Console deployment
  3. Command-line Deployment

You can deploy:

  1.  Enterprise, Web, and EJB applications
  2. Web services
  3.  J2EE libraries
  4.  JDBC, JMS and Diagnostic Framework modules
  5.  Resource adapters
  6. Optional packages
  7. Client application archives

Applications and EJBs can be deployed:

  1.  In an archived file(.ear, .war, .jar)
  2.  In an exploded(open)directory format

Archive Files: There are three archive files to deployed in Oracle WebLogic Server.

1) JAR(Java Archive): Jar is java archive file. It contains all class file, image, sound and other files which will needed in whole application. Computer users can create or extract JAR files using the jar command that comes with the JDK. They can also use zip tools. The JavaTM Archive (JAR) file format enables you to bundle multiple files into a single archive file. jar was designed mainly to facilitate the packaging of java applets or applications into a single archive.

Creating Jar File:

jar  -cvf   filename.jar “.”

Extracting Jar file:

            Jar   -xvf  filename.jar

2) WAR(web Archive): Web Archive (WAR) file is a Java archive file used to store jsp, servlets, classes, meta data information, images and Sound and tag libraries etc. It is standard file extension is .war. WAR files are used to package Web modules. A WAR file is for a Web application deployed to a servlet/jsp engine.

Creating war File:

jar  -cvf   filename.war “.”

Extracting Jar file:

            jar   -xvf  filename.war

3)  Ear(Enterprise Archive): An Enterprise Archive file represents a J2EE application that can be deployed in a Web Sphere application server. EAR files are standard Java archive files and have the file extension .ear. EAR file contain ejb, web or application client module. ear file is complete j2ee application file that contain all(jar +war)

Creating Ear File:

jar  -cvf   filename.ear “.”

Extracting Ear file:

            Jar   -xvf  filename.ear

In shot we can say
EAR = WAR(Web module) + JAR(can be EJB module or application client module)

Deployment Tools: Several methods are available to deploy the Oracle WebLogic Server applications and shared libraries, including:

  1.  Administration console
  2. WebLogic Scripting Tool(WLST)
  3. WebLogic.Deployer java class
  4. wldeploy Ant task
  5. Auto-deployment folder

1) Auto-deployment: Auto-deployment is a method for quickly deploying an application to a stand-alone server (Administration Server) for evaluation or testing. It is recommended that this method be used only in a single-server development environment.

If auto-deployment is enabled, when an application is copied into the \auto-deploy directory of the Administration Server, the Administration Server detects the presence of the new application and deploys it automatically (if the Administration Server is running). If WebLogic Server is not running when you copy the application to the \auto-deploy directory, the application is deployed the next time the WebLogic Server Administration Server is started. Auto-deployment deploys only to the Administration Server.

You can run a WebLogic Server domain in two different modes: development and production. Only development mode allows you use the auto-deployment feature

Development mode enables a WebLogic Server instance to automatically deploy and update applications that are in the domain_name/auto-deploy directory (where domain_name is the name of a WebLogic Server domain).

Production mode disables the auto-deployment feature and prevents any applications you place in the auto-deploy directory after you switch to production mode from being deployed. When you switch from development mode to production mode, any applications that were previously deployed via the auto-deploy directory remain deployed; if you wish to undeploy or redeploy such applications after you have switched to production mode, you must undeploy or redeploy them manually (for instance, with the WebLogic. Deployer command and the -undeploy or -redeploy options, as described inWebLogic. Deployer Command-Line Reference).

To auto-deploy an archived application, copy its archive file to the /autodeploy directory. WebLogic Server automatically sets the application’s deployment mode to stage mode.

A deployment unit that was auto-deployed can be dynamically redeployed while the server is running. To dynamically redeploy, copy the new version of the archive file over the existing file in the /auto-deploy directory.

To undeploy an archived deployment unit that was auto-deployed, delete the application from the /autodeploy directory. WebLogic Server stops the application and removes it from the configuration.

2) Console Deployment: If we deploy an application in console deployment first we create domain, and start the Admin server.

Console deployment steps:

            Step1: Click on Deployments

2: Click on Lock And Edit

3: Click on Install

4: Select Location Deployed Application

5: Click on Next

6: Choose Targeting Style

Select  Install this deployment as an application

7: Click on Next

8: Select Deployment Targets

Admin server   or   Cluster

9: Click on Next

10: Select security rules and policies

Select DD only

Select Stage or No-Stage Mode

11: Click on Next

12: Click on Finish

13: Click on Activate Changes

You can test your application from within the Administrative Console by following the steps below:

  1. In the Domain Structure section of the console, click ‘Deployments’.
  2. In the Summary of Deployments page, click on the name of the deployed Web application.
  3. Select the ‘Test’ tab. Here, you’ll find the URL to the deployed Web application. Click the link to launch it in a separate browser window.

Table of Deployable Modules:

Application or Module Archive Extension Key J2EE Deployment Descriptor
Enterprise Application .ear META-INF/application.xml
Enterprise JavaBean Module .jar META-INF/ejb-jar.xml
Web Application .war WEB-INF/web.xml
Web Service .ear or .war WEB_INF/web-services.xml
Connector Module .rar META-INF/ra.xml
Startup or Shutdown Class n/a No deployment descriptor (Class file only)

WebLogic server provides three different modes  for staging archive files.
1) Stage mode       2) No-stage mode         3) External stage mode

1) Stage mode: The administrator server copies the deployment unit files to the staging directories of target servers and they are deployed using local copy.

1.This mode is useful when deploying small or moderate size applications and prevents having a single point of failure if the original copy is not accessible.

  1. This is the default staging mode for managed server.

2) No-stage mode: The deployment units are deployed using the same physical copy, which must be accessible by the Administrator  server and target servers.

  1. The administrator server does not copy the deployment unit files to the target server.
  2. This mode is useful when deploying very large deployments to multiple targets and for deployment that require dynamic updates.
  3. This is the default staging mode for the Administrator server.

3) External stage mode: In the External stage mode you must copy the deployment units manually to the correct staging directories before deployments.

1.Use this staging mode for deployments where you want to manually control the distribution of deployment files to target servers.

2.This mode prevents deployment information beginning dynamically updated . In this case the administration server  access the original deployment unit for validation.

3) Command Line Deployment:

  1. i) Java WebLogic.Deployer:Deployer is a Java-based deployment tool that provides a command-line interface to the WebLogic Server deployment API.  WebLogic.Deployer is intended for administrators and developers who want to perform interactive, command-line based deployment operations.

To set up your environment to use the WebLogic.Deployer utility:

  1.  Install and configure the WebLogic Server software, as described in the WebLogic Server Installation Guide.
  2. Add the WebLogic Server classes to the CLASSPATH environment variable, and ensure that the correct JDK binaries are available in your PATH. You can use the setDomainEnv.cmd[setWLSEnv.sh orsetWLSEnv.cmd] script, located in the server/bin subdirectory of the WebLogic Server installation directory, to set the environment.
  3. If you are connecting to an Administration Server via a configured Administration channel, you must also configure SSL on the machine on which you run WebLogic.Deployer. See SeeUsing the SSL Protocol to Connect to WebLogic Server from WebLogic.Adminin Managing WebLogic Security for instructions about configuring SSL.

    Deploy:

Syntax: java WebLogic.Deployer [-adminurl] [specifiedurl(t3://localhost:7001)] [-username] [username]
[-password] [password] [-name] [appname] [-source] [app source path] [-targets] [targets servers] -deploy

Ex:java WebLogic.Deployer -adminurl t3://localhost:7001 –username WebLogic -password  WebLogic
-name benefits -source C:\course\labs\Lab08\exercise\applications\benefits.war -targets  ms1, ms2  -deploy

Redeploy:

Syntax:  java WebLogic.Deployer [-adminurl] [specifiedurl(t3://localhost:7001)] [-username] [username]
[-password] [password] [-name] [appname] [-targets] [targets servers] –redeploy

Ex:java WebLogic.Deployer -adminurl t3://localhost:7001 –username  WebLogic   -password  WebLogic   -name  benefits -targets  ms1, ms2  -redeploy


Undeploy: 

Syntax:  java WebLogic.Deployer [-adminurl] [specifiedurl(t3://localhost:7001)] [-username] [username] [-password] [password] [-name] [appname] [-targets] [targets servers] –undeploy

Ex: java WebLogic.Deployer -adminurl t3://localhost:7001 –username WebLogic -password  WebLogic    -name  benefits -targets  ms1, ms2  -undeploy

To display list of applications:

Syntax: java WebLogic.Deployer [-adminurl] [specifiedurl(t3://localhost:7001)] [-username] [username]
[-password] [password] -listapps

Ex: java WebLogic.Deployer -adminurl t3://localhost:7001 –username WebLogic  -password  WebLogic   -listapps

To display list tasks:

Syntax:java WebLogic.Deployer [-adminurl] [specifiedurl(t3://localhost:7001)] [-username] [username]
[-password] [password] [-listtasks]

Ex:java WebLogic.Deployer -adminurl t3://localhost:7001 –username  WebLogic -password  WebLogic
-listtasks

To check the server status:

Syntax: java WebLogic.Deployer [-adminurl] [specifiedurl(t3://localhost:7001)] [-username] [username]
[-password] [password] [GETSTATE] [server name]

Ex: java WebLogic.Deployer -adminurl t3://localhost:7001 –username WebLogic -password  WebLogic   GETSTATE   ms1

WebLogic Scripting Tool(WLST): Wlst is a kind of scripting tool which is a combination of jython and python language.

The WebLogic Scripting Tool (WLST) is a command-line scripting environment that you can use to create, manage, and monitor WebLogic Server domains. It is based on the Java scripting interpreter, Jython. In addition to supporting standard Jython features such as local variables, conditional variables, and flow control statements, WLST provides a set of scripting functions (commands) that are specific to WebLogic Server.

You can use WLST as the command-line equivalent to the WebLogic Server. Administration Console (WLST online) or as the command-line equivalent to the Configuration Wizard (WLST offline).

Three types of modes : 1) Interactive mode. 2) Scripting 3) Embedded.

Interactive mode, in which you enter a command and view the response at a command-line prompt, is useful for learning the tool, prototyping command syntax, and verifying configuration options before building a script. Using WLST interactively is particularly useful for getting immediate feedback after making a critical configuration change. The WLST scripting shell maintains a persistent connection with an instance of WebLogic Server.

Script Mode: Scripts invoke a sequence of WLST commands without requiring your input, much like a shell script. Scripts contain WLST commands in a text file with a .py file extension, for example, filename.py. You use script files with the Jython commands for running script.

Embedded mode, you instantiate the WLST interpreter in your Java code and use it to run WLST commands and scripts. All WLST commands and variables that you use in interactive and script mode can be run in embedded mode.  We don’t use this mode generally.

To invoke the wlst go to C:/bea9/WebLogic91/common/bin/wlst.cmd  and execute wlst.cmd

You can use WLST as the command-line equivalent to the WebLogic Server Administration Console (WLST online) or as the command-line equivalent to the Configuration Wizard (WLST offline).

Offline: Without connecting to a running WebLogic Server instance, you can use WLST to create domain templates, create a new domain based on existing templates, or extend an existing, inactive domain. You cannot use WLST offline to view performance data about resources in a domain or modify security data (such as adding or removing users).

Online: You can use WLST to connect to a running Administration Server and manage the configuration of an active domain, view performance data about resources in the domain, or manage security data (such as adding or removing users). You can also use WLST to connect to Managed Servers, but you cannot modify configuration data from Managed Servers.

 

Display help information for WLST commands by entering the help command:

help(‘online’)

help(‘offline’)

wls:/offline> help()

WLST is a command line scripting tool to configure and administer WebLogic Server.

To invoke the wlst go to /bea/WebLogic91/common/bin /wlst.cmd  and execute wlst.cmd

Connect to WLST:

Step 1: Set class path first (C:\bea9\user_projects\domains\ram_domain\bin\SetDomainEnv.cmd)

Step 2:  enter WLST.cmd (C:\bea9\WebLogic91\common\bin\WLST.cmd)

Installing WLST and goto offline mode.

Step 3: connect(‘username’,’password’,’url’)    enter

Ex: connect(‘WebLogic’,’WebLogic’,’t3://localhost:9001’)

To connect to the domain specified port number. And goto online mode.

Wls:/ram_domain/serverCofig>

Step 4: edit()

Step 5: startEdit()

You goto edit mode and deploy an application after this.

Step 6: deploy an application

Syntax: deploy(‘appname’,’app path’,targets=’servers’)

Step 7: activate()

Step 8: disconnect()   disconnect and come to offline state.

Step 9: exit()  come out to the WLST.

Deploying a file using WLST in different ways: In this ways to deploy an application by using script based.

  1. a) java WebLogic.WLST

Syntax: java WebLogic.WLST  path of script

Ex: java WebLogic.WLST  C:\scripts\deploy.py

Example script:

print ‘***********************************************************’

connect(‘WebLogic’,’WebLogic’,’t3://localhost:9001′)

print ‘***********************************************************’

edit()

print ‘*************************************************************’

startEdit()

print ‘*************************************************************’

print ‘*************************************************************’

deploy(‘ShoppingCart’,’C:/course/labs/Lab25/exercise/applications/ShoppingCart.war’,targets=”ms1,ms2″)

print ‘*************************************************************’

save()

print ‘*************************************************************’

activate()

print ‘************************************************************’

disconnect()

  1. b)cmd  script path

Syntax: WLST.cmd  script path

Ex: WLST.cmd   C:\scripts\deploy.py

3) WLST.cmd

Syntax: WLST.cmd

Wls:/offline> execfile(‘C:\scripts\deploy.py’)

iii) Side by Side Deployment:  Using side by side deployment strategy, the user can experience how to use the WebLogic server to re-deploy a new version of production application with out interrupting the availability of the application to new client request. The way the new client gets connected to the new version of the application and the previous version of the application is still in use by the older clients and gets retrived after the client disconnects.

Steps :

Step1. Copybenefits.war in new folder and deploy

Step2. setDomainEnv.cmd

Step3: java WebLogic.Deployer –adminurl  t3://localhost:7001 –username WebLogic  –password  WebLogic –name benefits  –source <app_location>\benefits.war –nostage  –targets ms1,ms2 –deploy
-appversion version1

Step 4.Copy benefits.war into another folder(new_war) and extract

jar –xvf benefits.war

Step5: Edit welcome file color:navy replace navy with Color:green

Step:6 Save

Step7: jar  –cvf benefits.war  *(or) jar –cvf benefits.war “.”

Step8: Delete all files except  benefits.war

Step9: Now deploy benefits.war

: java WebLogic.Deployer –adminurl  t3://localhost:7001 –username WebLogic  –password  WebLogic –name benefits  –source <New_app_location>\benefits.war –nostage  –targets ms1,ms2 –deploy

-appversion version1

Step10: Test the application version1 before version2 deploy. Afetr version2 deploy test the application to see the difference. version1 application is in retried state.

  1. IV) Deployment using plan:

 Steps:

1. Start your administration server and managed servers, if not already started. If prompted, enter your domain’s administrative username and password.
2. Download the deploy_plan.zip file that contains the sample Web application and WLST script listed below:

HRApp.war
deploy_HRApp.py

Extract and place both files within the same directory on your local file system. This location will be referred to as <APP_HOME> in later steps.

3. Open a new command shell, Navigate to the directory <INSTALL_HOME>/wlserver_10.3/server/bin where <INSTALL_HOME> is the location of your Oracle WebLogic Server installation.
4.Execute the setWLSEnv script. For example, on Linux, type the following:

source setWLSEnv.sh

5. Change directories to your <APP_HOME> folder (the location of the downloaded WLST script and sample application).
6. Execute the deploy_HRApp.py script using WLST:

java WebLogic.WLST deploy_HRApp.py

Tip: If your domain’s administrative credentials are not admin/welcome1, you will need to first edit this script file and change these values.
Tip: Make sure you have not locked the administration console prior to running this script.

7. Confirm that the application has been deployed to the ms1 server. Direct a Web browser to the following URL:

http://localhost:7003/HRApp

Generating a Deployment Plan for an Application: 

Perform the following steps:

1. Return to the same command shell used to run the WLST script. Confirm that the current directory is still <APP_HOME>.
2. Execute the WebLogic.PlanGenerator tool on the HRApp.war application:

java WebLogic.PlanGenerator -all HRApp.war

3. You should receive a message similar to the following:

<Saved configuration for application, HRApp.war>

Editing a Deployment Plan: 

Perform the following steps:

1. Locate the <APP_HOME>/plan.xml file, and open it in a text editor.
2. Locate the following <variable> element:

<variable>
<name>WebLogicWebApp_ContextRoots_xxxxxxxxxxxxxx</name>
<value xsi:nil=”true”></value>

</variable>

3. Remove the following text from the <value> child element:

xsi:nil=”true”

4. Set the value of the <value> child element to /HR:

<value>/HR</value>

5. Futher down in the file, locate the following <variable-assignment> element:

<variable-assignment>
<name>WebLogicWebApp_ContextRoots_xxxxxxxxxxxxxx</name>
<xpath>/WebLogic-web-app/context-root</xpath>
</variable-assignment>

6. Add a new <operation> child element to this <variable-assignment>:

<variable-assignment>
<name>WebLogicWebApp_ContextRoots_xxxxxxxxxxxxxx</name>
<xpath>/WebLogic-web-app/context-root</xpath>
<operation>replace</operation>
</variable-assignment>

7. Save your changes.

Updating an Application with a Deployment Plan:

Perform the following steps:

1. Launch a Web browser and access your domain’s administration console. The default port is 7001:http://localhost:7001/console
2. Log into the console using your domain’s administrative username and password.
3. In the Change Center panel, click Lock & Edit:
4. In the Domain Structure panel, click Deployments:
5. Select the checkbox for the HRApp application, and click the Update button:
6. Click the Change Path button associated with the Deployment Plan Path field :
7. Select the radio button for your new plan.xml file, and click Next. If necessary, use the hyperlinks next to the Current Location field to browse to your <APP_HOME> directory:
8. Click the Finish button.
9. In the Change Center panel, click the Activate Changes button:
10.    Verify the new context path of the application. Direct your Web browser to the followingURL:http://localhost:7003/HR
  1. V)wl(WebLogic)deploy Ant task:

Step1: Create  .xml file

Step2: write  script in it.

Step3: execute command  ant  deploy {if we save the file name as build.xml}

Ant  –f  filename.xml {if the file name is created with filename.xml}

  1. VI) Two-Phase Deployment:The new two-phase deployment protocol helps to maintain domain consistency. In previous versions of WebLogic Server, when you deployed an application, the administration server sent a copy of the application file(s) to all the targeted servers, which then loaded the application. If deployment to any of those servers failed or partially failed, the entire deployment’s state across its target servers became inconsistent.

The two-phase model makes inconsistent deployment states in clusters less likely by confirming the success of the prepare phase before deploying the application on any targeted servers. A deployment that fails during the prepare phase will not enter the activation phase.

Prepare Phase: The prepare phase of deployment, the first phase, distributes or copies files and prepares the application and its components for activation, validating them and performing error checks on them. The purpose of the prepare phase is to ensure that the application and its components are in a state in which they can be reliably deployed.

Activate Phase: The second phase, the activate phase, is the actual deployment, or activation, of the application and its component with the relevant server subsystem. After the activate phase, the application is made available to clients.

JDBC( Java Data Base connectivity)

JDBC: Java database connectivity (JDBC) is the JavaSoft specification of a standard application programming interface (API) that allows Java programs to access database management systems. The JDBC API consists a set of interfaces and classes written in the Java programming language.  Using these standard interfaces and classes, programmers can write applications that connect to databases, send queries written in structured query language (SQL), and process the results.

The JDBC API is consistent with the style of the core Java interfaces and classes, such as java.lang and java.awt. The following table describes the interfaces, classes, and exceptions (classes thrown as exceptions) that make up the JDBC API. In the table, interfaces belonging to the javax.sql package are extensions to the standard JDBC interfaces and are contained in the Java 2 SDK, Enterprise Edition.

JDBC Architecture:

JDBC Drivers: There are four types of drivers in JDBC.

1) Type-1 Driver:(JDBC-ODBC  bridge driver)

  1.  This driver receives any JDBC calls and sends then to ODBC driver.
  2.  ODBC driver understand these calls and communicates with the database library provide by the vendor.
  3. ODBC driver and vendor database library must present on the client machine.

2) Type-2 Driver: (Native API-partly java driver)

  1. It converts JDBC calls into database specific calls with the help of vendor database library.
  2. It communicates directly with the database server; it requires that some binary code to be present on the client machine.

3) Type-3 Driver: (Net protocol-pure java driver)

  1. It follows three-tiered approach where by the JDBC database requests are passed through the network to a middle-tier server.
  2. The middle-tier server translates the request to the database specific library and then sends it to the database server.
  3. The database server then executes the request and gives back to the result.

4)Type-4 Driver:( Net protocol-pure java driver )

  1. It converts JDBC calls into the vendor-specific DBMS protocol. So that client applications can communicate directly database server.
  2.  This driver completely implemented in java to archive platform independent.

In JDBC contains two types of Architectures.

1) Two-Tier Arcitecture:  In two-tier java application communicates directly with the DBMS.

A JDBC driver is needed that can communicate directly with the DBMS. So This is Client/Server configuration(Architecture)

Multi-tier Architecture: In multi-tier commands are sent to a middle-tier of services which then send the commands. The DBMS process commands sends the results back to middle-tier, which then sends them to client.

 

Data Source: A Data Source object provides a way for a JDBC client to obtain a database connection from a connection pool. It is used to store the WLST JNDI tree, it can support transactions and it is also associated with the connection pool.

What is JNDI(Java Naming Directory Interface):

The Java Naming and Directory Interface (JNDI) is an application programming interface (API) for accessing different kinds of naming and directory services. JNDI is not specific to a particular naming or directory service, it can be used to access many different kinds of systems including file systems, distributed objects systems like CORBA, Java RMI, and EJB; and directory services like LDAP, Novell NetWare, and NIS+.

Why JNDI: In WebLogic Server, JNDI serves as a repository and lookup service for J2EE objects including:

  1.  EJB home stubs
  2.  JDBC DataSources
  3.  JMS connection factories, queues and topics
  4.  RMI stubs

JNDI Root(Tree):

Connection pool: A connection pool is a collection of database connections that is maintained by memory. That can be reused. Once an application has finished its physical connection the connection is recycled rather than beginning destroyed.

Connection pools:

  1.  Are created at WebLogic server.
  2. Can be administrated using the Administration console.
  3. Can be dynamically resized to accommodate increasing load.

Benefits of DataSource And Connection pool:

  1.  Time and overhead are saved by using an existing database connection
  2.  Connection information is managed in one location in the Administration Console
  3.  The number of connections to a database can be controlled
  4.  The DBMS can be changed without the application developer having to modify underlying code
  5.  A connection pool allows an application to “borrow” a DBMS connection.


JDBC DtataSource Architecture:

How to use DataSource:

A client retrieves a Data Source through JNDI look up and uses it to obtain a database connection.

Process :

  1. Client will look up for the JNDI , once jndi is identified it will return database.
  2. Data source will get connection from connection pool.
  3. It will access the database with that connection.

JDBC  – To run point base Database:

Step1:Copy database files from c:\student\course\work\database\ and paste in c:\bea\WebLogic91\common\eva1\pointbase\database\

and edit startpointbase c:\bea\WebLogic91\common\eva1\pointbase\tools\startpointbase.cmd

Step2:  Edit  Startpointbase

Remove “%SAPLES_HOME%\domain\wl_server\pointbase.ini” and paste “c:\bea\WebLogic91\common\eva1\pointbase\tools”

and then save it.

Step3: Run startpointbase script.

configuredatasoure in admin console and test connection:

Create a DataSource with the following specifications:

Name:                       dizzyworldDS

JNDI Name:             dizzyworldDS

Database Type:         PointBase

Database Driver:       *PointBase’sDriver(Type 4)versions:4.x,5.x

Database Name:        HRDATABASE

Host Name:               localhost

Port:                          9092

Database User Name: PBPUBLIC

Password:                   PBPUBLIC

Initial Capacity:            5

Maximum Capacity:     15

Capacity Increment:     5

Login Delay:                1

Target:                        dizzy1

deploy an application testds.war from lab14and test for database connectivity.

Steps for creating data source and connection pool in console:

Step1: click on services

2: click on JDBC

3: click on Data source

4: click on Lock And Edit

5: click on New

6: Enter JDBC datasource properties

Name   : Datasource Name

JNDI Name    : JNDI Name

Database Type : database name

Driver Type     : Select Type-4 driver Non-Xa

à Next

7: Select Transaction options

Select

Support global transaction

Select one-phase commit
à Next

8: Create a New DataSource

Database Name           : Database name

HostName                   : Hostname

PortNumber                : Portnumber

DB User Name           : username

DB password  : password

Conformpassword      : password

àNext

9: Display connection properties

10: Test configuration

11: Display connection properties

àConnection successes

àNext

12: Select Targets (Admin or cluster(ms1&ms2))

àFinish

àActivate changes
13. Test Data Source

Cluster JDBC (or) MultiDataSource: A multi data source is an abstraction around a group of data sources that provides load balancing or fail-over processing between the data sources associated with the multi data source. Multi data sources are bound to the JNDI tree or local application context just like data sources are bound to the JNDI tree.

Multi Data Source Algorithms: 

1)Failover: Connections requests are sent to the first data source in the list, if the request fails the request is sent to the next data source, in the list and so forth, the process is represented untial a valid connection is obtained or until the end of the list is reached in which case an exception is thrown.

2) Load balancing: The multi data source distributes connection requests evenly to its number data sources, which algorithm the multidata source also provides failover processing. That is if a request fails the multi data source sends to the requests to the next data source in the list until a valid connection is obtain, or until the end of the list is reached, in which case an exception is thrown.

Diff b/w Xa and Non-Xa  Datasource:

            Xa datasource

1)  It allows global transaction that my be
multiple resources.

2) It involves a co-ordinating transaction
manager  with one or more databases in
a single global transaction.

3) It comes  from the X/Open group
specification on distributed, global transactions.

          Non-Xa Datasource

1)  It allows single transaction that my
be single resources.

2) there is no transaction coordinator, and it is
a single resource is doing all its transaction
work itself.

3) It comes from  Servlet or EJB or plain old
JDBC in a Java application talking to
a single database.

JMS(JavaMessagingService)

JMS: The Java Message Service (JMSAPI is a Java Message Oriented Middleware (MOM) API for sending messages between two or more clients. JMS is a part of the Java Platform Enterprise Edition. It is a messaging standard that allows application components based on the Java 2 Platform Enterprise Edition (J2EE) to create, send, receive, and read messages. It allows the communication between different components of a distributed application to beloosely coupled, reliable, and asynchronous.

The following are JMS elements:

JMS provider: An implementation of the JMS interface for a Message Oriented Middleware (MOM). Providers are implemented as either a Java JMS implementation or an adapter to a non-Java MOM.

JMS client: An application or process that produces and/or receives messages.

JMS producer/publisher: A JMS client that creates and sends messages.

JMS consumer/subscriber: A JMS client that receives messages.

JMS message: An object that contains the data being transferred between JMS clients.

JMS queue: A staging area that contains messages that have been sent and are waiting to be read. Note that, contrary to what the name queue suggests, messages have to be delivered in the order sent A JMS queue only guarantees that each message is processed only once.

JMS topic: A distribution mechanism for publishing messages that are delivered to multiple subscribers

The JMS API supports two models:

  1.  Point-to-point
  2. Publish and subscribe

1) Point-to-Point: In the point-to-point model, a sender posts messages to a particular queue and a receiver reads messages from the queue. Here, the sender knows the destination of the message and posts the message directly to the receiver’s queue. This model is characterized by the following:

  1. Only one consumer gets the message.
  2. The producer does not have to be running at the time the consumer consumes the message, nor does the consumer need to be running at the time the message is sent.
  3. Every message successfully processed is acknowledged by the consumer.

2) The publish/subscribe model supports publishing messages to a particular message topic. Subscribers may register interest in receiving messages on a particular message topic. In this model, neither the publisher nor the subscriber knows about each other. A good analogy for this is an anonymous bulletin board. The following are characteristics of this model:

  1. Multiple consumers (or none) will receive the message.
  2. There is a timing dependency between publishers and subscribers. The publisher has to create a message topic for clients to subscribe. The subscriber has to remain continuously active to receive messages, unless it has established a durable subscription. In that case, messages published while the subscriber is not connected will be redistributed whenever it reconnects.Using Java, JMS provides a way of separating the application from the transport layer of providing data. The same Javaclasses can be used to communicate with different JMS providers by using the JNDI information for the desired provider. The classes first use a connection factory to connect to the queue or topic, and then use populate and send or publish the messages. On the receiving side, the clients then receive or subscribe to the messages.

Difference b/w Queue and Topic:

                         Queue                               Topic
1) In queues, one message can be consumed
by only one client.

2) Queue represent Point-To-Point model.

3) queue is used to send one to one system.

4) In queue the messages are send
to FIFO(First in first out) order.

1) In the topics, one message can be consumed
by many clients.

2) Topic represent Public and Subscribe  model.

3) topic is used to send more than one system
at a time.

4) In Topic  the messages are send to LIFO
(Last in first out) order.

Distributed Queue : Many producers can serialize messages to multiple receivers in a queue.

Distributed Topic : Publishing and subscribing to a topic decouples producers from consumers.


Difference b/w Distributed Queue and Distributed Topic:

                 Distributed Queue

1) A Distributed Queues are allow you to
retrieve a connection to any of the Queues
across a cluster by using the Global JNDI name.

2) It seems one of the main pieces of
functionality Distributed Queue gives you is
load balanced connections across
multiple managed servers.

3) The members of the unit are usually
distributed across multiple servers within
a cluster, with each queue member belonging
to a separate JMS server.

4)A distributed queue is a set of physical
JMS queue members.

                     Distributed Topic

1) A distributed topic can be used to
create a TopicPublisher and TopicSubscriber.

2) The topic members can be located anywhere but
must all be served either by a single WebLogic Server
or any number of servers in a cluster.

3) A distributed topic is a set of physical JMS
topic members.

JMS Architecture:

Connection Factory: A ConnectionFactory object encapsulates a set of connection configuration parameters that has been defined by an administrator. A client uses it to create a connection with a JMS provider.

  1. It encapsulates connection configuration information.
  2. It is used to create pre-configured connections.
  3. It stored in JNDI.
  4. Can be targeted server or cluster.
  5.  It supports concurrent use.

à The default connection factory that is bounded in JNDI to WebLogic is            WebLogic.jms.ConnectionFactory

Threshold and a Quota: A threshold and a quota can be set for Server and Destination objects.

A quota is a limit defined for JMS administered objects; it includes these values:

  1. The maximum number of bytes that can be stored
  2. The maximum number of messages that can be stored

A threshold is a limit that triggers message paging, flow control and logged warnings using:

  1. Upper and lower values for the number of bytes
  2. Upper and lower values for the number of messages

Durable Subscribers and Subscriptions:

  1. Durable subscribers register durable subscriptions to guarantee message delivery even if subscribers are inactive.
  2. A subscriber is considered active if the Java object that represents it exists.
  3.  By default, subscribers are non-durable.


Persistent store: The persistent store provides a built-in, high-performance storage solution for WebLogic Server subsystems and services that require persistence. For example, it can store persistent JMS messages or temporarily store messages sent using the Store-and-Forward feature. The persistent store supports persistence to a file-based store or to a JDBC-enabled database.

There are two types of  persistent mechanisms: 1) persistent         2)non-persistent

A persistent message is guaranteed to be delivered once-and-only-once. The message cannot be lost due to a JMS provider failure and it must not be delivered twice. It is not considered sent until it has been safely written to a file or database. WebLogic JMS writes persistent messages to a WebLogic persistent store (disk-base file or JDBC-accessible database) that is optionally targeted by each JMS server during configuration.

A Non-persistent messages are not stored. They are guaranteed to be delivered at-most-once, unless there is a JMS provider failure, in which case messages may be lost, and must not be delivered twice. If a connection is closed or recovered, all non-persistent messages that have not yet been acknowledged will be redelivered. Once a non-persistent message is acknowledged, it will not be redelivered.

When to Use Persistent Messaging:  Persistent messaging permits messages in memory to be written out to a persistent store.                                                                                                                               Configure persistent messaging if:                                                                                                                 – Development requires durable subscriptions (use durablesubscribers in the application)                      – You require that in-progress messages persist across server restarts

How a Durable Subscription Works:

When the client becomes active again, its ID is used to retrieve and redeliver messages.

Configure a Durable Subscription:

To configure durable subscriptions, an administrator must:

– Create and configure a JMS store

– Configure connection factories or destinations as persistent

– Associate the JMS store with the JMS Server

The JMS store can be configured to use either:

– A file store

– A JDBC store (a connection pool)

Configure JMS server through console:

The following steps are:

            Step1:  Click on JMS Server

Step2:  Click on Lock And Edit

Step 3:  Click on New

Step 4:  Enter JMS server Properties

Name:  JMS server Name

Persistent Store: none

à Next

Step 5: Select targets

Target :  server name(ms1)

à Finish

Configure JMS Module:

The following steps are:

            Step1:  Click on JMS Modules

Step2: Click on Lock And Edit

Step 3:  Click on New

Step 4:  Enter the following properties

Name :  JMS Module Name

Descriptor File Name:Filename

Location Domain:

—-à Next

Step5: Select Target :Cluster

—–àNext

Step 6: Select would you like to add Resources of this JMS System

——àFinish

Configure JMSQueue:

The following steps are:

Step1: Click on JMS Module

Step 2: Click on JMS Module Name

Step 3: Click on Lock And Edit

Step 4: Click on New

Step 5: Select Queue

Step 6: Description Properties

Name: QueueName

JNDI Name: JNDI Name

Template: None

–à Next

Step 7: Select Targets  JMS Server

—-à Finish

Configure JMSTopic:

The following steps are:

Step1: Click on JMS Module

Step 2: Click on JMS Module Name

Step 3: Click on Lock And Edit

Step 4: Click on New

Step 5: Select Topic

Step 6: Description Properties

Name:  TopicName

JNDI Name: JNDI Name

Template:  None

–à Next

Step 7: Select Targets  JMS Server

—-à Finish

Delete struck messages from the queue:

The following steps are:

Step1: Click on JMS Module

Step 2: Click on JMS Module Name

Step 3: Click on JMS Queue

Step 4: Click on Monitoring

Step 5: select the queue

Step 6: Click on show messages

Step 7: Select message ID

Step 8: Delete

Step 9: Finish

Check the pending messages in a queue:

The following steps are:

Step1: Click on JMS Server

Step 2: Click on JMS Server Name

Step 3: Click on monitoring

Step 4: Click on Active destrination

-à To check the pending messages in queue.

SSL(Security Socket Layer):

  1. I) Configure SSL in WebLogic:
    Generating the certificate:
    The following steps are:
    Step1: Open a command prompt and set the environment by running the setDomainEnv script.
    ( C:\bea9\user_projects\domains\ram_domain\bin\setDomainEnv.cmd)
    Step2: Generate the private – public key pair. For demonstration we would use keytool java utility to do so.            However we can use other utilities like openssl etc.
    keytool  -genkey  -alias mykey   -keyalg RSA   -keysize 2048   -keystore  identity.jks
    Step3: Generate a Certificate Signing Request (CSR) and send it to Certifying Authority.
    keytool  -selfcert   -alias mykey  -keystore   identity.jks
    Step 4: Create a identity  keystore, this can be done my exporting
    keytool   -export  -alias  mykey  -file  cert.cer  -keystore   identity.jks
    Step5: Create a trust keystore, this can be done my importing.
    keytool   -import   -alias   mykey  -file  cert.cer   -keystore   trust.jks    -noprompt
    To verify the contents of the keystore, you can use the below command,
    keytool  -list  -v  -keystore <keystore-name>  -storepass <keystore-password>

2)  Configuring the keystore on the WebLogic Server:
Step 1: Log into the Admin Console, Click on servers
Step 2: Click on Lock and Edit
Step 3: select the server on which you want to configure the SSL    certificate.(Ex:ms1)
Step 4: Click on keystores
Step 5: select Custom identity and Custom trust
Identiy:
CustomIdentitykeystore:C:\bea9\user_projects\domains\sai_domain\identity.jks
Custom Identity keystore type: jks
Custom identity passphrase : Pavan@123
Trust:
Custom trust keystore: C:\bea9\user_projects\domains\sai_domain\trust.jks
Custom trust keystore type: jks
Custom trust passphrase : Pavan@123
àsave     —àAcivate changes

Step 6: Click on SSL
Step 7: Enter identity
Private key alias: mykey
            Privatekey passphrase : Pavan@123
—àsave     —à Activate changes

àTo check SSL type browser  https://localhost:5003(ms1 ssl portnumber)/messaging(deploying application)

Apache Webserver

Install the apache web server in Linux:

Step 1: first unzip the file on zip file
Gunzip    httpd-2.0.55.gz
Step 2: tar file is open. Un tar that file
Tar –xvf  httpd-2.o.55.tar

The file will display   httpd-2.o.55

Step 3: cd  httpd-2.0.55

./configure—prefix= /home/apache2

./make

./make install

The install is completed.

Check Apache servers running processes:

ps  -ef | grephttpd | grep  -v grep

1) To start apache – httpd –k start

2) To stop apache – httpd –k stop

3) To Restart apache – httpd –k restart

Program files / Apache software foundation / Apache 2.2/bin folder in

  1. i) Main configuration file in Apache is“httpd.conf”
  2. ii) Additional config files –“Extra” folder

4) Apache default port no – 80

5) Apache ssl default port number – 443

6) To check the syntax – httpd  -t

7) All html documents – “htdocs” folder

The Apache Directory StructureThe Apache software is typically distributed into the following subdirectories:

cgi-bin This is where many, if not all, of the interactive programs that you write will reside. These will be programs written with Perl, Java, or other programming languages.
Conf This directory will contain your configuration files.
htdocs This directory will contain your actual hypertext documents. This directory will typically have many subdirectories. This directory is known as the DocumentRoot.
Icons This directory contains the icons (small images) that Apache will use when displaying information or error messages.
images This directory will contain the image files (GIF or JPG) that you will use on your web site.
Logs This directory will contain your log files – the access_log and error_log files.
Sbin Use nogroup

Main Configuration file in apache:

  1. The Apache software is configured by changing settings in several text files in the Apache conf (configuration) directory.
  2. There are four configuration files used by Apache. The main configuration file is usually called httpd.conf.
access.conf This is The security configuration file. It Contains instructions about which users should be able to access.  And  what information.
httpd.conf This is The server configuration file. It Typically contains directives that affect how the server runs, such as user and group ID’s it should use when running, the location of other files, etc.
srm.conf This is The resource configuration file. It Contains directives that define where documents are found, how to change addresses to filenames, etc.
mime.types A configuration file that relates filename extensions to file types.

Apache root: On an Apache HTTP Server, you can control where the server looks for live HTML documents; in other words, your web pages or content management system.

DocumentRoot: . The directory will typically have many subdirectories. This directory is known as the DocumentRoot. The documentRoot directory in apache is htdocs.

Server root: Server Root Directory                                                                                     Syntax: ServerRoot A<path>< tt=””>                                                                               Example: ServerRoot /sw/pkg/apache
Since: Apache 1.0  </path><>

This directive sets the root directory in which the server resides. Typically, it contains the subdirectories conf/ and logs/. Relative paths for other configuration files are taken as relative to this directory. This directive can be also overridden from the command line via the -d option.

  1. II) Integrate Apache with WebLogic Server:Install apache in our machine and open httpd.conf file (C:\Program Files (x86)\Apache Software Foundation\Apache2.2\conf\httpd.conf) and to do the following steps are:
    Step 1: Make sure the apache server run on port number 80 or 8080
    Listen localhost:80 or 8080                                                                                                                          Listen:80
    Step2:Copy the module Mod_WL_20 to C:\ProgramFiles(x86)\ApacheSoftware Foundation\Apache2.2\modules
    Step 3: copy the module on  LoadModule WebLogic_module modules/mod_wl_22.so  to httpd.conf file.
    Step 4: copy the below content in to  conf  on main server.
    <Location />   
    SetHandler WebLogic-handler                                                                                                 </Location>

<IfModule mod_WebLogic.c>  
WebLogicCluster localhost:5002,localhost:5004                                                                                   Debug ON                                                                                                                                         WLLogFile c:/temp/wlproxy.log                                                                                                     WLTempDir c:/temp   
 </IfModule>
Step 4: Re-start the server and access the application.

http://localhost:apacheportnumber/appname(http://localhost80:/messaging)

III) Integrate Apache-SSL with WebLogic server:  Install the “httpd/apache_x.x.x-win32-x86-openssl-x.x.x.msi” s/w in our machine. Open httpd.conf file Then do the following steps

Step 1: Configure apache configure file httpd.conf, uncomment the following 2 lines,
            LoadModule ssl_module modules/mod_ssl.so
Include conf/extra/httpd-ssl.conf

Step2: Execute the following step for windows

set OPENSSL_CONF=C:\Program Files\Apache Software Foundation\Apache2.2\conf\openssl.cnf

Step 3: Generate certification using openssl,

openssl req -new -out server.csr
openssl rsa -in privkey.pem -out server.key
openssl x509 -in server.csr -out server.cert -req -signkey server.key -days 365

Step 4:  Copy the generation files to the directory defined by httpd-ssl.conf

We have the Self-signed SSL certificates ready now. Now We need to MOVE the “server.cert” and        “server.key” file to the

“C:\Program Files\Apache Software Foundation\Apache2.2\conf” location.

Step 5:  check httpd-ssl.conf

Now we need to modify the “C:\Program Files\Apache Software Foundation\Apache2.2\conf\extra\httpd- ssl.conf”.

Let all the default options as it is but make sure to modify the following section according to your need:

<VirtualHost _default_:443>
ServerAdmin some@email.com
DocumentRoot “Your Root folder location”
ServerName www.domain.com:443
ServerAlias domain.com:443 
ErrorLog “logs/anyFile-error.log”
CustomLog “logs/anyFile-access.log” common
SSLEngine on

SSLCertificateFile “C:/Program Files/Apache Software Foundation/Apache2.2/conf/server.cert”

SSLCertificateKeyFile “C:/Program Files/Apache Software Foundation/Apache2.2/conf/server.key”
</VirtualHost>

Step 6: Open an exception in Windows Firewall for TCP port 443.(set ssl port number:443 in our mechine)

Step 7: Access the application using the below url

https://localhost:443/app-name or https://localhost/app-name

Set  SSLport number:443 in our mechine:

Step 1: Click on start button

Step2 : Click on Control panel

Step 3: Click on windows firewall

Step 4: Click on Advanced Settings

Step 5: Click on Inbounded rules

Step 6: Click on new rule

Step 7: Select port

—-à click on next

Step 8:  select TCP

Select specific location port: 443

——à next

Step 9: Select Allow the connections

—-à next     —ànext

Step 10:  SSL port is created

Diff  b/w one-way ssl and two-way ssl:

One Way SSL :- Only the client authenticates the server. This means that the public cert of the server needs to configured in the trust store of the client.
Two Way SSL: – The client authenticates the server & the server also authenticates the client.
This means that the public cert of the server needs to configured in the trust store of the client. And Also the public cert of the client needs to be configured on the server’s trust store.

Virtual Hosting:

Diff b/w Name-based and Ip-based virtual hosting:

IP-based virtual hosts use the IP address of the connection to determine the correct virtual host to serve.
Name-based virtual hosting, the server relies on the client to report the hostname as part of the HTTP headers & many different hosts can share the same IP address.

Configure virtual host in apache and WebLogic:

Go to servers  -> click on admin server -> click protocol -> select the chanel tab ->click new option N/w channel name : 80protocol:http  and click next ->  listen Address: localhost listen port : 80 and click next -> click finish
Go to environment -> virtual hosts ->click new option -> create a new virtual host -> click ok.

JVM(Java Virtual Machine)

JVM Architecture: JVM is the heart of any Java based Application Server. We face most of the issues due to incorrect JVM tuning. It is very important to understand the Overall architecture of the JVM in order to trouble shoot different JVM tuning related issues. Here we are going to discuss the Architecture and the Major parts of a Java Process And the Java Heap Division.

The Following Diagram is just a basic overview of a Java Process in a 2 GB process Size Machine. Usually in 32 bit Windows Operating Systems the default process size will be 2 GB (In Unix based 64 bit operating Systems it can be 4GB or more). So i draw the following Diagram of Java Process to explain the Java Process partitions in a 2Gb process size machine.

Java Process Architecture Diagram

In the above diagram we will find different partitions of a Java Process. Please compare the above diagram with below descriptions.

.

1) Just for Example we can see that Process Size is 2048 MB (2GB)

2) The Java Heap Size is 1024MB (means 1GB)   -Xmx1024m

3) Native Space = ( ProcessSize – MaxHeapSize – MaxPermSize) It means around 768 MB of Native Space.

4) MaxPermSpace is around -XX:MaxPermSize=256m

5) Young Generation Space is around    40% of Maximum Java Heap.

Different parts of JVM:

1) Eden space: Eden Space is a Part of Java Heap where the JVM initially creates any objects, where most objects die and quickly are cleaned up by the minor Garbage Collectors (Note: Full Garbage Collection is different from Minor Garbage Collection). Usually any new objects created inside a Java Method go into Eden space and the objects space is reclaimed once the method execution completes. Where as the Instance Variables of a Class usually lives longer until the Object based on that class gets destroyed. When Eden fills up it causes a minor collection, in which some surviving objects are moved to an older generation.

2) Survivor Spaces: Eden Space has two Survivor spaces. One survivor space is empty at any given time. These Survivor Spaces serves as the destination of the next copying collection of any living objects in Eden and the other survivor space.

The parameter SurvivorRatio can be used to tune the size of the survivor spaces.

-XX:SurvivorRatio=6 sets the ratio between each survivor space and Eden to be 1:6

If survivor spaces are too small copying collection overflows directly into the tenured generation.

3) Young Generation: (-XX:MaxNewSize): Till JDK1.3 and 1.4 we used to set the Young Generation Size using -XX:MaxNewSize. But from JDK1.4 onwards we set the YoungGeneration size using (-Xmn) JVM option.

Young Generation size is controlled by NewRatio.  It means setting -XX:NewRatio=3 means that the ratio between the Old Generation and the Young Generation is  1:3. Similarly -XX:NewRatio=8 means that 8:1 ratio of tenured and young generation.

NewRatio: NewRatio is actually the ratio between the (YoungGenaration/Old Generations) has default values of 2 on Sparc , 12 on client Intel, and 8 everywhere else.

NOTE: After JDK 1.4 The Young Generation Size can be set using  (-Xmn) as well.

1) Virtual space-1:(MaxNewSize – NewSize): The First Virtual Space is actually shows the difference between the -XX:NewSize and -XX:MaxNewSize.  Or we can say that it is basically a difference between the Initial Young Size and the Maximum Young Size.

JavaHeapArea:( -Xmx and –Xms): Java Heap is a Memory area inside the Java Process which holds the java objects.  Java Heap is a combination of Young Generation Heap and Old Generation Heap. We can set the Initial Java Heap Size using -Xms JVM parameter similarly if we want to set the Maximum Heap Size then we can use -Xmx JVM parameter to define it.

Example:

-Xmx1024m —> Means Setting the Maximum limit of Heap as 1 GB

-Xms512m —> Means setting Java Heap Initial Size as 512m

.

NOTE-1): It is always recommended to set the Initial and the Maximum Heap size values as same for better performance.

NOTE-2): The Theoretical limitation of Maximum Heap size for a 32 bit JVM is upto 4GB. Because of the Memory Fragmentation, Kernel Space Addressing, Swap memory usages and the Virtual Machine Overheads are some factors JVM does not allow us to allocate whole 4GB memory for Heap in a 32 bit JVM. So usually on 32-bit Windows Operating Systems the Maximum can be from 1.4 GB to 1.6 GB.

If we want a larger memory allocation according to our application requirement then we must choose the 64-bit operating systems with 64 bit JVM. 64-bit JVM provides us a larger address space. So we can have much larger Java Heap  with  the increased number of Threads allocation area. Based on the Nature of your Operating system in a 64 bit JVM you can even set the Maximum Heap size upto 32GB.

Example:        -Xms32g -Xmx32g -Xmn4g

2) Virtual Space-2: (MaxHeapSize – InitialHeapSize): The Second Virtual Space is actually the Difference between the Maximum Heap size (-Xmx)and the Initial Heap Size(-Xms). This is called as virtual space because initially the JVM will allocate the Initial Heap Size and then according to the requirement the Heap size can grow till the MaxHeapSize.

PermGen Space: (-XX:MaxPermSize): PermGen is a non-heap memory area where the Class Loading happens and the JVM allocates spaces for classes, class meta data,  java methods and the reference Objects here. The PermGen is independent from the Heap Area. It can be resized according to the requirement using -XX:MaxPermSize and -XX:PermSize  JVM Options. The Garbage collection happens in this area of JVM Memory as well. The Garbage collection in this area is called as “Class GC”. We can disable the Class Garbage Collection using the JVM Option -noclassgc. if  ”-noclassgc” Java Option is added while starting the Server. In that case the Classes instances which are not required will not be Garbage collected.

Native Area: Native Memory is an area which is usually used by the JVM for it’s internal operations and to execute the JNI codes. The JVM Uses Native Memory for Code Optimization and for loading the classes and libraries along with the intermediate code generation.

The Size of the Native Memory depends on the Architecture of the Operating System and the amount of memory which is already commited to the Java Heap. Native memory is an Process Area where the JNI codes gets loaded or JVM Libraries gets loaded or the native Performance packs and the Proxy Modules gets loaded.

There is no JVM Option available to size the Native Area. but we can calculate it approximately using the following formula:

NativeMemory = (ProcessSize – MaxHeapSize – MaxPermSize)

Garbage collection: It’s always best to enable the Garbage collection Logging in our production environment as well because it does not cause any resource overhead or any side effect on WebLogic server or another application server’s performance.  GC log helps us in investigating man issues. Apart from issues it helps us to find out if some tuning is required based on the statistics of the Garbage collection.                          Garbage collection logging can be enable and collected in a separate log file by using the following JAVA_OPTIONS:

-Xloggc:D:/gcLogs/GCLogs.log         -XX:+PrintGCDetails        -XX:+PrintGCTimeStamps

As soon as you add these JAVA_OPTIONS which are JVM specific (above will work for Sun and Open JDKs fine) the JVM will start generating the garbage collection logging in the GCLog.log file. Now if you will open this file then you can

see something like following:

01 4.636: [GC [PSYoungGen: 230400K->19135K(268800K)] 230400K->19135K(2058752K), 0.0635710 secs] [Times: user=0.08 sys=0.01, real=0.06 secs]
02 7.302: [GC [PSYoungGen: 249535K->38396K(268800K)] 249535K->51158K(2058752K), 0.0777300 secs] [Times: user=0.21 sys=0.04, real=0.07 secs]
03 7.521: [GC [PSYoungGen: 49735K->38388K(268800K)] 62496K->51933K(2058752K), 0.0741680 secs] [Times: user=0.15 sys=0.04, real=0.07 secs]
04 7.595: [Full GC (System) [PSYoungGen: 38388K->0K(268800K)] [PSOldGen: 13545K->51794K(1789952K)] 51933K->51794K(2058752K) [PSPermGen: 19868K->19868K(39936K)], 0.3066610 secs] [Times: user=0.28 sys=0.02, real=0.31 secs]
05 9.752: [GC [PSYoungGen: 230400K->26206K(268800K)] 282194K->78000K(2058752K), 0.0728380 secs] [Times: user=0.15 sys=0.00, real=0.08 secs]
06 11.906: [GC [PSYoungGen: 256606K->38393K(268800K)] 308400K->94759K(2058752K), 0.1058920 secs] [Times: user=0.19 sys=0.00, real=0.10 secs]
07 13.480: [GC [PSYoungGen: 268793K->38394K(268800K)] 325159K->109054K(2058752K), 0.0762360 secs] [Times: user=0.20 sys=0.03, real=0.08 secs]
08 18.115: [GC [PSYoungGen: 268794K->38384K(268800K)] 339454K->179238K(2058752K), 0.1351350 secs] [Times: user=0.42 sys=0.10, real=0.14 secs]
09 20.860: [GC [PSYoungGen: 268784K->38394K(268800K)] 409638K->200343K(2058752K), 0.1063430 secs] [Times: user=0.29 sys=0.03, real=0.11 secs]
10 22.148: [GC [PSYoungGen: 268794K->38399K(268800K)] 430743K->221395K(2058752K), 0.1173980 secs] [Times: user=0.24 sys=0.02, real=0.12 secs]
11 23.357: [GC [PSYoungGen: 268799K->26775K(268800K)] 451795K->231618K(2058752K), 0.0714130 secs] [Times: user=0.15 sys=0.03, real=0.08 secs]
12 24.449: [GC [PSYoungGen: 257175K->29170K(268800K)] 462018K->239909K(2058752K), 0.0312400 secs] [Times: user=0.06 sys=0.01, real=0.04 secs]

You can notice something in the above output:

Point1: [Full GC (System) [PSYoungGen: 38388K->0K(268800K)]    It means a Full GC is happening on the complete Heap Area including all the Areas of the Java Heap Space.

Point2: [GC [PSYoungGen: 230400K->19135K(268800K)]   Indicates some small GCs which keep on happening in the young generation very frequently, This garbage collection cleans the Young Generation short living Objects.

Point3:  Meaning of the [GC [PSYoungGen: 230400K->19135K(268800K)]   line is around 256MB (268800K) is the Young Generation Size, Before Garbage Collection in young generation the heap utilization in Young Generation area was around  255MB (230400K)  and after garbage collection it reduced up to 18MB (19135K)

Point4:  Same thing we can see for Full Garbage collection as well….How effective the Garbage collection was…[Full GC (System) [PSYoungGen: 38388K->0K(268800K)] [PSOldGen: 13545K->51794K(1789952K)]  Here it says that around

[(old)1789952K +  young (268800K) ]  memory space means  OldGeneration is consuming 1.75GB space and Young Generation is consuming around 255 MB space  So it means total Heap size is around 2GB.

But analyzing the Garbage collection log like above technique Line by Line is very bad…so here we have an alternative was to analyze the Garbage Collection log in few Seconds to see how much time the Full Garbage collection is taking as an average and other reports…etc.

Step1): Download the “garbagecat-1.0.0.jar   (881 KB) ”  tool from the follwing link:http://garbagecat.eclipselabs.org.codespot.com/files/garbagecat-1.0.0.jar

Step2): Open a command prompt and then make sure that JAVA is set in the Path so that we can use “jar” utility of JDK to run the “garbagecat-1.0.0.jar”  tool.

Step3): Put the “garbagecat-1.0.0.jar”  file and the “GCLog.log” file in the same directory. then run the following command:

java      -jar      garbagecat-1.0.0.jar      GCLog.log

Step4): As soon as our run the above command you will see that in your current directory following files are created:

garbagecat-1.0.0.jar

GCLog.log

gcdb.lck

gcdb.log

gcdb.properties

report.txt

Step5): Now open the “report.txt” file to see the Overall report of the Garbage Collection something like following:

========================================

SUMMARY:

========================================

# GC Events: 12

GC Event Types: PARALLEL_SCAVENGE, PARALLEL_SERIAL_OLD

Max Heap Space: 2058752K

Max Heap Occupancy: 462018K

Max Perm Space: 39936K

Max Perm Occupancy: 19868K

Throughput: 95%

Max Pause: 306 ms

Total Pause: 1233 ms

First Timestamp: 4636 ms

Last Timestamp: 24449 ms

========================================

.

If you see that the Garbage Collection Max Pause time is very high like more than 5-7 Seconds for a 2 GB heap then you need to worry about it.

NOTE: Garbage collection  is a best utility to generate the Garbage Collection Report for Sun JDK and Open JDK for other JDKs you should use other tools for accurate results.

Garbage collection algorithms:

1) Mark-and-sweep collector:  This type of collector first traverses the object graph and marks reachable objects. It then scans the heap for unmarked objects and adds their memory to a list of available memory segments. This collector typically uses a single thread to do its work and is a stop-the-world collector.

2) Mark-and-compact collector:  A mark-and-compact collector, sometimes known as a mark-sweep-compact collector, uses the same marking phase as a mark-and-sweep collector. During the second phase, it compacts the heap by copying marked objects to a new area of the heap. These collectors are also stop-the-world collectors.

3) Copying collector:  This type of collector divides the heap into two areas, commonly known as semi-spaces. It uses only one semi-space at a time; the JVM creates all new objects in one semi-space. When the garbage collector runs, it copies any reachable objects it finds to the other semi-space as it finds them, thus compacting the heap as it copies live objects. All dead objects are left behind. This algorithm works well for short-lived objects, but the expense of continually copying long-lived objects makes it less efficient. Again, this is a stop-the-world collector.

4) Incremental collector:  Incremental collectors basically divide the heap into multiple areas and collect garbage from only one area at a time. This can create much smaller, though more frequent, pauses in your application. There are numerous approaches defining how the actual collection is handled from traditional mark-and-sweep to algorithms designed explicitly for use with multiple smaller areas like the train algorithm. See “Incremental Mature Garbage Collection Using the Train Algorithm” by Jacob Seligmann and Steffen Grarup (http://www.daimi.aau.dk/~beta/Papers/Train/train.html) for more information.

5) Generational collector:  This type of collector divides the heap into two or more areas that it uses to store objects with different lifetimes. The JVM generally creates all new objects in one of these areas. Over time, the objects that continue to exist get tenure and move into another area for longer-lived objects. Generational collectors often use different algorithms for the different areas to optimize performance.

6) Concurrent collectors:  Concurrent collectors run concurrently with the application, typically as one or more background threads. These collectors typically have to stop-the-world at some point to complete certain tasks, but the amount of time they halt all processing is significantly reduced because of their other background work.

7) Parallel collectors:  Parallel collectors typically use one of the traditional algorithms but use multiple threads to parallelize their work on multiprocessor machines. Using multiple threads on multi-CPU machines can dramatically improve the scalability of a Java application on multiprocessor machines.

Creating And Analyze log for Garbage Collection:

Creating GC log: Set memory argument in startWebLogic.cmd.

-Xms256m –Xmx512m –XX:CompailThreshold=8000 –XX:permSize=48m –XX:MaxPermSize=128m

analyze GC logs:  

Srep1:Go to admin console

Step2: Click the Adminserver

Step3: Select the monitors tab

Step4: Click the performance

Step5: Select the garbage collector

Security Realms: A security realm is a container for the mechanisms including users, groups, security roals, security palaces and providers. That are used to protect WebLogic resources, we can have multiple security reasons in a WebLogic servers domain. But only one can be set as the default realm.

This security realms page, lists is security realms that has been configured in this WebLogic server domain. Click the name of the realms to explore and configure that realm.

Creating users and groups in WLS:

Step1:  Goto security realm

Step2: Click on Lock And Edit

Step3: Select Myrealm

Step4: Select user and group tab

Step5: Click on New

Name               :  Ram

Designation     :  WebLogic_Admin

Provider          :  Select provider

Password         :  Ram123

ConformPwd  :  Ram123

——->    Ok

Step6: Click on Ram

Step7: Click on group Tab

Step8: Select Role

Step9: Click on Ok

Step10: Click on Save

Roals:

1) Admin Channel Users: Admin channel users can access the admin channel.

2) Administrator: Administrator can view and modify all the resource attributes and start, stop servers.

3) App Testing: App testing group.

4) Cross Domain Connecters: Cross Domain Connecters can make inter-domain  calls from foreign domains.

5) Deployers: Deployer can view all the resource attributes and deploy applications.

6) Monitors: Monitors can view and modify all resource attributes and perform operations not restricted by roles.

7) Operators: Operators can view and modify all response attributes and perform server life cycle operations.

 

Difference between unicast and multicast:

                      Unicast

1)  It is just one-to-one communication that
takes place between the client and the server.

2)  In unicast, one packet is transmitted to only
one destination at a time. So it recive only one           reciver.

3) In unicast, the Internet protocol methods,
such as, TCP(Transmission Control
Protocol) and UDP(User Datagram Protocol)
are used.

4) When a user uses the Windows Media
Player, he or she has direct contact with
the server. Each of the users using
the unicast system utilises additional bandwidth.

                         Multicast

1) It is a multi-communication level and mainly
multicasts enabled routers used for broadcasting.

2) In multicast sends packets to multiple
destinations which is represented by a group address.
So it receives multiple receivers.
3) When the former is more practical as only
a small section of the Internet is multicast enabled.

4)  In multicast, there is no direct link between
the user and the server. When using Windows
Media Player, the user does not have any direct
link with the server. Instead, once the user starts to
use Windows Media Player, an .nsc or Next
how channel is generated which is then delivered
to the user from the server.

Trouble shooting issues:

Deployment:   We will send error log to the application team for modification.

Caused By: WebLogic.utils.ErrorCollectionException:

There are 1 nested errors:

WebLogic.j2ee.dd.xml.AnnotationProcessException: Duplicate ejb name ‘BDAccountEjbBean’ found: annotation ‘Stateless’ on bean failed due to connection pool issue: we will fix connection pool issues and then redeploy the application

Out of memory issue during the deployment:

error: java.lang.outofmemory.permgenspace

this error occured due to space in perm area.

setDomainEnv.sh

xx:permsize 128m

xx:maxpermsize 128m

we have set intialpermsize=maxpermsize then restarted the servers, redeployed the application

If one or two application failed when we are triggering through scipt.we will fix that issue and do a deployment using console

JDBC:

1) DB down (raise a ticket to db team)

2) In correct hostname or port number ( raise a ticket to network team)

3) Data base connection lost ( telnetipaddress port )

4) Data base user_acc lock ( raise a ticket to db team for unlocking user_acc)

5) Invalid pakage error (raise a ticket to db team)

6) TNS listener error (raise a ticket to db team)

7) Schema does not exist (raise a ticket to db team)

8) Cannot allocate resource error

Intialcapacity : 5

max      : 15

increase max to 25

9) Connection leaks ( send error to application team)

10) Connection time out ( raise a tickect to db team for long running quries)

JMS:

stuck message issues

Check whether dest queue is available, check message format, check queue name.

rolling message issues (messages will run continuously in the loop)

delete those messages in the queue.

Disk Space:

If the disk space usage is 95%-100% then we will delete old log files

[root@localhost ~]# df -kh

FilesystemSize  Used Avail Use% Mounted on

/dev/sda2             3.8G  1.9G  1.8G  52% /

/dev/sda1              46M  9.2M   35M  22% /boot

tmpfs                 506M     0  506M   0% /dev/shm

/dev/sda3              14G  1.8G   12G  100% /home

du -kh (disk usage)

s

[root@localhost ~]# du -sh /home

1.8G    /home

[root@localhost bea10.3]# du -sh *

181M    jdk160_05

28K     logs

211M    jrockit_160_05

100M    modules

24K     registry.dat

8.0K    registry.xml

19M     user_projects

556K    utils

429M    wlserver_10.3

delete old log files

/home/bea10.3/user_projects/domains/sherkhan/servers/AdminServer/logs

rm -rf Adminserver.log00001  Adminserver.log00002 Adminserver.log00003

rm -rf Adminserver.out00001 Adminserver.out00002 Adminserver.out00003

rm -rf access.log00001 access.log00002 access.log00003

/home/bea10.3/user_projects/domains/sherkhan/servers/ms1/logs

rm -rf ms1.log00001

rm -rf ms1.out00001

or zip the log files

/home/bea10.3/user_projects/domains/sherkhan/servers/AdminServer/logs

gzip -r *

/home/bea10.3/user_projects/domains/sherkhan/servers/AdminServer

gzip -r logs

High CPU utilization:

top (linux)

prstat (solaris)

top – 07:45:22 up  3:03,  3 users,  load average: 0.16, 0.33, 0.17

Tasks: 113 total,   2 running, 109 sleeping,   0 stopped,   2 zombie

Cpu(s):  0.0%us,  0.7%sy,  0.0%ni, 99.3%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st

Mem:   1035400k total,  1020348k used,    15052k free,    77688k buffers

Swap:  2040212k total,        0k used,  2040212k free,   483724k cached

%cpu %Mem

9523 root      22   0  637m 239m 3660 S 98.7 23.7   0:12.79 java

If you find any zombie process count >50 raise a ticket to solaris admins

If any java processes are occupying 95-100% cpu usage then check the log files for any continuous looping messages or jdbc transaction time outs.

fix the problem and kill manged  server using kill -9 pid and restart the service instance.

404 error:

page can’t be displayed.

10.4.5 404 Not Found

The server has not found anything matching the Request-URI. No indication is given of whether the condition is temporary or permanent.

1) check whether they are using correct url

2) check whether apache server is running ( ps -ef | grephttpd) ( ps -ef | grep -i apache)

3) check the diskspace of Apache server if it is full then delete the log files (df -kh)

goto Apache2.2/logs

delete old logs

4) Check whether the deployed application is in active state

5) If the deployed application is failed then fix the issue and redeploy the application

Users are getting 404 error some times and they are able to access the application sometimes.

1) check whether all managed servers are in running state.

if one of the managed server is in shutdown state then bring up the server.

check the http requests in access.log file for all managed server

if you are getting 404 error in one of the managed server log. then check server log for any errors

i got the in log file:

port already in use

netstat -anp | grep 8002

if the port is listened on any other instance. restat managed server.

if the issue still persists then raise a reqest to network team..

500 error:

Service unavailable

this error is due to server down

check apache or WebLogic service instance is the server is down then start the server.

Slow response:

check All WebLogic server status. bring the servers up if they are down

check network handshake requests in application logs. If you found any issues related to n/w then raise request to n/w team.

check for stuck thread issues in WebLogic. If you found any stuck thread issues then take thread dump and analyze.

checkcpu usage for java processes.

check heap size of WebLogic server gc log or in console.

If the heap size is more than 80% then take heap dump send it to l3 support.

check no of users logged in to the application.

check for long running quiries from data base side.

check for latency in data base side.

check memory leaks in gc logs.

check connection leaks in the WebLogic server side.

check space in WebLogicunix machine.

check apache server space.

OOM(OutOfMemory):

–     Login to the Corresponding Server through Putty

–     Then Check the Status of the Server instances

–     Check the Server logs and Out logs for OutOfMemory Error

–     Take the Access logs at the time of OOM and it will be good if we take thread dump

If Server(s) is/are in Running State.

–     Analysis the Thread dump for the Cause of OutOfMemory Error (Due to App/Server)

–     Then Depending on the Server Status (if not in Running State) Restart the Server.

  1. i) OutOfMemory during deployment:
  2. If the application is huge(contains more than 100 JSPs), we might encounter this problem with default JVM settings.
  3. The reason for this is, the MaxPermSpace getting filled up.
  4. This space is used by JVM to store its internal datastructures as well
  5. as class definitions. JSP generated class definitions are also stored in here.
  6. MaxPermSpace is outside java heap and cannot expand dynamically.
  7. So fix is to increase it by passing the argument in startup script of the server: –XX:MaxPermSize=128m (default is 64m)
  1. ii) Memory related issues can be caused by many problems including:

? Java Heap is undersized for the environment

? There is not enough native memory available for the java process

? Web server is overloaded

Below are some general guidelines on how to address memory-related issues. In addition, you should search the “My Oracle Support” knowledge base for the specific “OutOfMemory” error message that you see in your PIA_WebLogic.log.

Also, you can collect further details on WebLogic memory usage by using monitoring tools referenced in section “Monitoring WebLogic Memory Usage”

General Guidelines on Fixing OutOfMemory Issues:

  1. First, you need to determine if WebLogic is running out of “native heap” memory or “java heap” memory. Typically you are able to tell this by checking the “OutOfMemory” error message in the PIA_WebLogic.log:
  2. If the error message refers to “native” or to a “thread” related error, it is an issue with “nativememory”. Examples of errors due to running out of native memory are:

? “Unable to create new native thread”

? “Error starting thread: Not enough storage is available”

Native memory errors are more likely to occur on PeopleTools 8.50 and lower versions where you are running a 32-bit java process (which has address space limitations)

  1. Any other error messages, are usually due to running out of java heap memory
  2. If you are running out of java heap, you may want to start by increasing the java heap settings (if you are unable to increase java heap setting, then the other option is to add more WebLogic PIA’s to the environment).

Increase the java heap setting as follows:

  1. First check the current heap setting by searching string “-Xmx” in your WebLogic log (for Unix, search PIA_stdout.log. For Windows, search NTservice-<DOMAIN_NAME>-PIA.log).

The “-Xmx” value shows you the current heap setting. For example, these settings show that the minimum heap (-Xms) and maximum heap (-Xmx) are set to 512mg:

Java command line=java -server –Xms512m –Xmx512m

  1. For PeopleTools 8.50, try increasing the heap (at 256mg increments) up to 1.5gb. For PeopleTools 8.51 or 8.52, you can increase the heap even higher, provided the server has enough memory available.

For Unix, you can change the heap setting in file setEnv.sh. Example:

JAVA_OPTIONS_LINUX=”-jrockit -XnoOpt -XXnoJITInline –Xms768m –Xmx768m

? For Windows, you will either need to change the setting in the Windows registry, or else change setting in setEnv.cmd and then rebuild the Windows Service

Refer to the following document for more details on changing the java heap setting:

Doc#638298.1: How To Increase/Decrease JVM Heap Size for WebLogic

  1. If you are running out of native memory heap, then you may want to consider doing the following:
  2. Lower the java heap setting (ieXmx/Xms settings) in order to allow more of the java process’ memory to be used for “Native Memory”. (see step 2b above, for instructions on changing java heap setting)

If the java heap is already being fully utilized, and you are unable to lower it, then you may want to consider adding additional PIA’s to your environment

  1. Lower the thread stack size. Note that the threads use native memory, so if you lower the thread stack size, then the threads will not consume as much memory. The thread stack size is specified using parameter “-Xss”. Refer to the following document for details

651285.1: WebLogic Error: “java.lang.OutOfMemoryError: unable to create new native thread”

Log files not rotating:

check the diskspace if it is full then delete old logs

check whether log4j properties file set in classpath

  1. Check the Status of the Server
  2. ./startWebLogic.sh
  3. ./startManagedWebLogic.sh <manageservername>
  4. [0R]
  5. Check through console.
  6. Check the disk Space(if full, Delete the logs and then need to restart the Server)
  7.  du –kh (folder)
  8.    df –kh (filesystem)
  9. Avail space is90%

If full , mv <source path><destination path>

Delete, rm –rf<filename: adminserver.log>

Stuck thread:

“[STUCK]”

When a transaction is running more than 5 minutes, a message (example below) is logged to the PIA_WebLogic.log.

<Apr 18, 2011 12:47:04 PM PDT><Error><WebLogicServer><BEA-000337><[STUCK] ExecuteThread: ‘4’ for queue: ‘WebLogic.kernel.Default (self-tuning)’ has been busy for “675” seconds working on the request …..

Note that the message shows that the thread is ‘STUCK’. But in fact, the thread may not be stuck, but is just taking a long time to complete. These threads often successfully complete, if given enough time.

If you see a lot of long-running threads, at the time users are experiencing problem, then this indicates that the web server is having issues processing threads, which may cause the web server to hang.

Long running threads can be caused by different issues. The problem often occurs due to issues on the app server or database subsequently causing the threads to queue up and wait on the web server. So if you see a lot of stuck threads, you may want to troubleshoot further by doing the following:

  1. Get a thread dump as described in section “Creating/Analyzing Thread Dumps”. The thread dump may help you determine whether the threads are getting hung up on the app server or database.
  2. Have your DBA check for long running SQL’s and/or DB locks
  3. You can also look at the ‘Stuck’ thread messages in the PIA_WebLogic.log to see what user(s) are running the transactions and the specific component they are running. This may help you determine if there is a specific user and/or transaction that is causing the problems.

Port Conflict Issue:

While configuring a new WebLogic instance and starting it, that might be get an issue like : “Port already in use”. There could be many reasons for this one.

  1. on the same machine multiple standalone instances might be running one of the instance already used that port which you have given for new configuration.
  2. apache might be running with the same port.
  3. middleware might be running on the same machine with same port

On Solaris Operating environment we have 2 options:

  1. usingpfiles command

netstat –na|grep –> identify port in use

pfiles |grep -isockname |grep port –> look for every java process is initialized by startWebLogic.sh or startManagedWebLogic.sh

  1. Another way costly one (Third party package) to find the process that is using particular port is :

lsof -itcp:

  1. Best way is perl script using a method it will check only standard ports which are used by the system.

getservbyport(intport_number, const char *protocol_name)

#!/usr/bin/perl

($name, $aliases, $port_number, $protocol_name) = getservbyport(7001, “tcp”);

print “Name = $name\n”;

print “Aliases = $aliases\n”;

print “Port Number = $port_number\n”;

print “Protocol Name = $protocol_name\n”;

JVM memory arguments:

-XX:-PrintGCDetails outputs detailed  information at each collection

-XX:-PrintGCTimeStamps outputs a time stamp at the start of each collection

-xloggc=<filename>           outputs gc information to the specified file

-XX:-DisableExplicitGC disable calls to system .gc( )

– -XX:NewSize=2m default size of new generation

-XX:MaxNewSize=size maximum size of the new generation

-XX:PermSize=64m default size of permanent generation

-XX:MaxPermSize=64m maximum size of the permanent generation

– -Xms256m Initial heap size

–Xmx512m  maximum heap size

-xx:survivor Ratio=<value>   Ratio of survivors spaces to young generation

-XX:-UseParallelGC   Use parallel garbage collection for scavenges.

THREAD DUMP

Tread dump:- Thread dump provides a snapshot of the current active live threads. It provides the stack trace of all the java threads in the JVM. It is used when the server is hung and we want to see the threads executing and take their dump.

There are different ways to take thread dump.

In unix: kill -3 <pid>

In windows:  ctrl+break

WebLogic.Admin utility:  javaWebLogic.Admin -url t3://localhost:7001 -username WebLogic -password WebLogic THRED_DUMP

WLST Scripting:

connect(‘WebLogic’,’WebLogic’,’t3://localhost:7001′)

cd(‘server’)

cd(‘AdminServer’)

TreadDump()

disconnect()

exit()

Admin console: 

Step1: login to the admin console

Step2: Click on server

Step3: Navigate to servers

Step4: Click monitor tab

Step5: Click on tread

Step6: Click on the dumpthread stack.

Locating the Thread Dump:  The thread dump is placed in the WebLogic log file. The log file location varies depending on the OS platform:

For UNIX: the output is sent to:

<PS_HOME>/webserv/<DOMAIN_NAME>/servers/logs/PIA_stdout.log

For Linux: the output is sent to:

<PS_HOME>/webserv/<DOMAIN_NAME>/servers/logs/PIA_stderr.log

For Windows: the output is sent to:

<PS_HOME>\webserv\<DOMAIN_NAME>\servers\PIA\logs\NTservice-<DOMAIN_NAME>-PIA.log

Analyzing a Thread Dump: The thread dump can be a bit challenging to analyze, and you may need assistance from an Oracle Support Engineer. Below are some tips on how to analyze the thread dump. This information is broken out into the following sections:

  1. General Information about the thread dump
  2. Overview of types of threads commonly seen in thread dump
  3. Examples of different issues you may observe in the thread dump

1) General Information about the Thread Dump:  Note that the thread dump always begins with this line:

===== FULL THREAD DUMP ===============

And ends with this line:

===== END OF THREAD DUMP ===============

The first line of the thread dump shows when the thread dump was created, followed by the exact java version you are using.

Example:

Mon Apr 18 12:46:56 2011

Oracle JRockit(R) R28.0.0-679-130297-1.6.0_17-20100312-2123-windows-ia32 

2) Overview of Types of Threads commonly seen in Thread Dump:

  1. i) Threads waiting for Requests:You will always see some threads that are just waiting for work, as WebLogic always allocates some threads to be available and ready to process any incoming requests. These threads can easily be identified because you’ll see “ExecuteThread.waitForRequest” in the call stack. These threads will be in ‘ACTIVE’ or ‘STANDBY’ mode. These threads do not have much significance when troubleshooting. However, if you see a lot of these threads waiting for requests (20 or more), it most likely indicates that the environment is just recovering from a very heavy load, when the thread dump was taken (and as the load diminishes, WebLogic will remove many of these extra threads that are waiting for requests)

Ex: at WebLogic/work/ExecuteThread.waitForRequest(ExecuteThread.java:157)

  1. ii) Socket Muxer Threads:You will also see approximately two to five socket muxer threads. These threads’ main responsibility is to read the request off the socket and pass the work to the appropriate thread. WebLogic allocates a percentage of execute threads from the self-tuning thread pool to be Muxer threads. Usually you will see three or four of these threads:

“ExecuteThread: ‘0’ for queue: ‘WebLogic.socket.Muxer'” id=25 idx=0x60 tid=2068 prio=5 alive, in native

iii) ListenThreads: You will also see approximately six “listen threads”, usually three for SSL and three for non-SSL. The purpose of these threads is to wait for connections to arrive. All browser requests enter the WebLogic server through these threads.

“DynamicListenThread[Default]” id=39 idx=0x90 tid=2812 prio=9 alive, in native

“DynamicSSLListenThread[DefaultSecure]” id=40 idx=0x94 tid=3148 prio=9 alive, in native

  1. iv) Jolt Connection Threads:WebLogic Server and the Tuxedo Application Server use Jolt to communicate with each other. PIA creates two threads inside the WebLogic’s JVM per Jolt connection. For each Jolt connection made between WebLogic and the Tuxedo Application Servers, you will see a LLENwReader and a LLENwWriter thread in the thread dump:

“LLENwReader” id=52 idx=0xc4 tid=4408 prio=5 alive, in native, daemon

“LLENwWriter” id=53 idx=0xc8 tid=7828 prio=5 alive, waiting, native_blocked, daemon

  1. v) Threads waiting on Application Server:If the web server is waiting on the app server to process a request, you will see the following thread (below)

at bea/jolt/IOBuf.waitOnBuf(IOBuf.java:119)

3) Examples of Different Issues you may Observe in Thread Dump: Below are examples of different issues and the thread stacks you may observe.

Many threads waiting on App Server: If you see a lot of threads such as the one below, then this means that many of the WebLogic threads are waiting on the application server to finish processing the request:

at bea/jolt/IOBuf.waitOnBuf(IOBuf.java:119)

  1. i) Many threads processing the same call stack:If you see many threads all processing the same call stack, then you may need to review contents of the call stack in order to troubleshoot the issue. For example, in one case, the web server hung and the thread dump showed hundreds of threads like the one below. This was caused by an issue with a proxy server configuration, causing all threads to get hung up at logout:

com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:798)

psft.pt8.psp.logoutAccessedPIAs(Unknown Source)

  1. ii) All threads busy and waiting on one thread:By design, the PIA does not allow more than one request per HTTP session, to be submitted to the application server. If the PIA receives multiple requests from the same HTTP session, it will queue up all subsequent requests and process just one at a time. Typically, there should not be situations where the PIA receives multiples requests from the same HTTP session. However, this can occur in the following situations:
  2. You are using a proxy server that is re-submitting requests to the web server if a response is not received within a certain time.

-OR-

  1. A user submits a long-running request, and while waiting for the request to finish, the user continuously attempts to submit more requests.

When one of the above scenarios occurs, in the thread-dump you see one request waiting on Jolt to get response from the App-Server and many other threads waiting for the lock on the session to be released. Below are excerpts from a thread dump, showing this situation:

  1. a)There are many threads like this that are “blocked”, and all the threads are waiting on the same lock #.

— Blocked trying to get lock: java/lang/String@0x27D36AC0[thin lock]

  1. b)The thread that is holding the lock on “0x27D36AC0” (that all blocked threads are waiting on), is usually processing a jolt request (ie it is waiting on the application server):

at bea/jolt/IOBuf.waitOnBuf(IOBuf.java:119)

^– Holding lock: java/lang/String@0x27D36AC0[thin lock]

  1. c)At the end of the thread dump, you may see a list of “blocked locked chains”. In this list, you’ll notice that all threads are waiting on one thread: “Thread #0” in this example. Which happens to be a jolt request (ie it is waiting on application server)

Blocked lock chains

===================

Chain 2: “[ACTIVE] ExecuteThread: ‘2’ for queue: ‘WebLogic.kernel.Default (self-tuning)'” id=35 idx=0x80 tid=3964 waiting for java/lang/String@0x27D36AC0  held by:

“[ACTIVE] ExecuteThread: ‘0’ for queue: ‘WebLogic.kernel.Default (self-tuning)'” id=16 idx=0x48 tid=180 in chain 1

Chain 3: “[ACTIVE] ExecuteThread: ‘3’ for queue: ‘WebLogic.kernel.Default (self-tuning)'” id=44 idx=0xa4 tid=4620 waiting for java/lang/String@0x27D36AC0  held by:

“[ACTIVE] ExecuteThread: ‘0’ for queue: ‘WebLogic.kernel.Default (self-tuning)'” id=16 idx=0x48 tid=180 in chain 1

Chain 4: “[ACTIVE] ExecuteThread: ‘4’ for queue: ‘WebLogic.kernel.Default (self-tuning)'” id=49 idx=0xb8 tid=1120 waiting for java/lang/String@0x27D36AC0

held by:

“[ACTIVE] ExecuteThread: ‘0’ for queue: ‘WebLogic.kernel.Default (self-tuning)'” id=16 idx=0x48 tid=180 in chain 1

Analysing ThreadDump by using Summari tool:

Download: The binary is available for download at                                                   http://yusuke.homeip.net/samurai/en/samurai.jar

How to launch samurai: You can simply double-click to launch Samurai on your desktop or type as following in your command prompt.

$java  -jar  samurai.jar

Automatic update is not available with this way. Please check and download latest version manually.

Step1: Drag and drop the ThreadDump into summary tool

Step2: When Samurai detects a thread dump in your log, a tab named “Thread Dump” will appear.

Step3: You can just click “Thread dumps” tab to see the analysis result. Samurai colors idle threads in gray, blocked threads in red and running threads ingreen.

There are two resultant views and Samurai shows “Table view” by default.
In many cases, you are just interested in the table view and the sequence view. Use the table view to decide which thread needs be inspected, the sequence view to understand the thread’s behavior.

Result1:

Result2:

HeapDump: A Heapdump is a snapshot of JVM memory – it shows the live objects on the heap along with references between objects. It is used to determine memory usage patterns and memory leak suspects. It is useful to analyse OOM(OutOfMemory) situations.

To take Heap dump:

Eclipse Memory Ananlyser is a very useful tool to analyze heap dumps. It has a lot of features such as Memory Leak detection where it runs an automated test to determine the suspected leaks.

Step 1) Start the WebLogic Server, with the application in active state which causes memory leak.

Step 2) Get the process id of the server using jps

Step 3) Access the application that causes memory leak

Step 4) Take heap dump at regular interval using jmap.

jmap -dump:format=b,file=dump1.bin [processId]

Analyzer HeapDump by using Eclipse MAT:   Analyzer  Open the Heap Dump in Eclipse Memory Analyzer (U can download it fromhttp://www.eclipse.org/mat/downloads.php) Approximate size is 42 MB. Just u need to extract this Zip then u can directly start (no Installation needed)

Step1:

Step2: Observe the heap usage of Objects in the heap dumps. If the object instance keeps on increasing in the subequent heap dumps, force a garbage collection from the WebLogic Server console.

Step3: Take heap dumps again and open in the Eclipse Memory Analyzer. If the number of instances still don’t go down for those objects, you can expect to see this
<Jul 16, 2010 10:49:15 AM IST> <Critical> <Health> <BEA-310003> <Free memory in
the server is 47,856 bytes. There is danger of OutOfMemoryError>
Exception in thread “Thread-12? java.lang.OutOfMemoryError: Java heap space
at demo.MemoryLeakTest.runTest(MemoryLeakTest.java:14)
at jsp_servlet.__memoryleak$1.run(__memoryleak.java:86)
at java.lang.Thread.run(Thread.java:619)

If the leak is happening due to a WebLogic Class, it can be a known issue or an undiscovered BUG. You need to get in touch with Oracle Support. If it’s an Application Class, you need to contact the developers. Out of Memory can also happen dude to third party codes such as database drivers.

How to install Eclips MAT? How to Analyze Heapdump using Eclips MAT and Jhat tools:

Step1: download the Eclips MAT

Step2: Extract Memory Analyser zip file and open MemoryAnalyzer.ini

Step3:  Double-click on MemoryAnalyzer.exe to start Memory Analyser Tool

Step4: Select Search for new features to install and click Next

Step5:  Accept the license agreements and click Next

Step6: Click Finish to install the extensions

Step7: Click Install All to ignore the warning

Step8: Restart Memory Analyser to reflect changes.

JPROFILE

Introduction: JProfiler eases developers in creating more efficient applications by improving their performance. It is oriented towards testing and exploring different aspects of the performance of a Java program, concerning the operation of the JVM making use of available platform resources. JProfile is mainly using to find out the memory leaks of JVM.

JProfiler provides the following functionality:

  1. Memory consumption measurement
  2. Memory stack frames tracing
  3. CPU loads profiling
  4. Momentary heap allocation information
  5. Thread state progress statistics
  6. Visual representation of JVM work loads by different parameters
  7. Source code reference
  8. Garbage collection during profiling
  9. Remote profiling
  10. Profiling only of a particular stage or a combination of several stages of the program life cycle
  11. Using different target environments
  12. Saving profiler information for further examination
  13. Exporting profiler information in text format

JProfiler is a commercially licensed Java profiling tool developed by ej-technologies GmbH, targeted at Java EE and Java SEapplications.

  1. JProfiler works both as a stand-alone application and as a plug-in for the Eclipse software development environment.
  2. JProfiler supports local profiling (analysis of applications running on the same machine as the JProfiler software) and remote profiling (analysis of Java applications running on remote machines)
  3. Enables both memory profile to assess memory usage and dynamic allocation leaks and CPU profiling to assess thread conflicts.
  4. Provides visual representation for the virtual machine load in terms of active and total bytes, instances, threads, classes, Garbage Collector activity.

Download Jprofiler(http://www.ej-technologies.com/download/jprofiler/files.html)

You will be asked to provide your name and e-mail id.An Evaluation Key will be mailed to you.

At the time of installation, you will be prompted for the installation key, copy it from your mail and paste it as shown in the screenshots.

NOTE: It is not recommended to use JProfiler in Production Environments .as it consumes more resources.which may not be desired in Production Envs.

Patch: patch is a piece of software designed to fix problems[1] with, or update a computer program or its supporting data. This includes fixing security vulnerabilities[1] and other bugs, and improving the usability or performance. Though meant to fix problems, poorly designed patches can sometimes introduce new problems (see software regressions). In some special cases updates may knowingly break the functionality, for instance, by removing components for which the update provider is no longer licensed or disabling a device.

Patch management is the process of using a strategy and plan of what patches should be applied to which systems at a specified time.

Patch installation steps:

            Step1: Take the back up of bea home directory and config.xml file

Step2: Copy all patches along with the patch-catalog.xml file to the Linux box.at                                      */oracle/utils/bsu/cache_dir

Step3: Stop all the servers including admin.

Step4: On the Linux machine go to the bsu folder. ( */oracle/utils/bsu/) and run the                                    following command

               Ex: ./bsu.sh -prod_dir=<WebLogic home> -patchlist=<patch name> -verbose -install

Step5: Use the below command to check the output

*\oracle\utils\bsu> ./bsu.sh -view -prod_dir=/usr/local/oracle/wls1033/wlserver_10.3                                                        -status=applied

Step6: Start the all servers.

            Step7: Check the application health.

Commands:

      Patch installation: ./bsu.sh -prod_dir=/usr/local/oracle/wls1033/wlserver_10.3 –                                                               patchlist=4EWM -verbose   -install

      Patch Uninstallation: ./bsu.sh -remove -patchlist=1FKM –                                                                                                   prod_dir=/usr/local/oracle/wls1033/wlserver_10.3 –verbose

      Check for what are all patches installed: ./bsu.sh -view –                                                                                            prod_dir=/usr/local/oracle/wls1033/wlserver_10.3 -status=applied

Creating patch logs:  ./bsu.sh -report -log=test.log -log_priority=trace

Screen shots

Applying patches on WebLogic Server using Oracle Smart Update(BSU):  Oracle provides the Smart Update utility to apply patches and upgrade the WebLogic Server installations. Oracle’s WebLogic Server is now a critical component  of Fusion Middleware and every other component of Fusion Middleware requires WebLogic Server to be installed as  a pre-requisite. Applying patches and upgrading WebLogic Server is quite straight forward using the Oracle’s Smart Update utility,the documentation for Oracle Smart Update Utility can be found here.

Step1: Shutdown and take a complete backup of the WLS environment.

The Startup/Shutdown scripts are placed in   $WLS_HOME/user_projects/domains/<domain_name>/bin

Step2: The Oracle Smart Update Tool is located at  “$WLS_HOME/utils/bsu

Step3: Launch the the Oracle Smart Update Tool :

Step4: Once logged in, you will be presented with Oracle Smart Update Dialog.

Step5: You can choose to “Register for security updates”, this is usually helpful to keep yourself updated with the latest security updates and product expiration.

Step7: On the left pane you would see   WebLogic Servers installed  and on the right pane you will see two tabs. “Get Patches” and “Manage Patches” and a section to show the downloaded patches.

Step8: Now select the patches and hit the “Download Selected” button, you will be prompted if you wish to to validate and resolve conflicts.

Step9: The Validation completes with the following message:

Step10: Click “OK” to proceed downloading the patches.

Step11: Once the patches are downloaded and click the “Manage Patches” tab to proceed with the patch application. In the “Downloaded Patches” section you will notice the patches downloaded, click the “up” arrow to apply the patch

Step12: You will be prompted with couple of prompts for you to take action:

Click “OK” to proceed

Step13: Once more the validation is done, click “OK” to proceed                                       Step14:  One more “Are you sure?” prompt, annoying I know. Click “Proceed” to apply the patch

Step15:  Once the patch is applied you’d see the patch in the Applied Patches “Default” tab

That  the patch is now applied. If you face any issues its worth investigating the server logs.

Log File Location: The log file location is:

C:/bea/user_projects/domains/ram_domain/servers/admin server/log

1) Access log:

2) Serveer log: The server log records information about events such as the startup and shutdown of servers, the deployment of new applications, or the failure of one or more subsystems. The messages include information about the time and date of the event as well as the ID of the user who initiated the event.

3) Domain log: This will have about domain information. (domainname.log)

4) AdminServer log: This will have about the AdminServer information. (AdminServer.log)

5) Out logs: This will have about the JVM output. (Adminserver.out)

6) Application logs: This will have information about each and every application which we deployed in server.

7) Node Manager logs: This will have information about Node Manager. (node manager.log)

(C:/bea/WebLogic91/common/nodemanager/nodemanager.log)

Diff b/w WebLogic 8,9,10 & 11 versions:

Features WLS8.1 WLS9x WLS10.3 and 11G
JDBC Connection Pool-Max Capacity PM-25(AdminServer)

DM-15(AdminServer)

PM-15(managed Server)

PM and DM-15

(AdminServer and Managed Server)

PM and DM-15

(AdminServer and Managed Server)

Execute ThreadDefaultThreadCount PM-25(AdminServer)

DM-15(AdminServer)

PM-15(managed Server)

PM and DM-15

(AdminServer and Managed Server)

PM and DM-15

(AdminServer and

Managed Server)

JMS Services Queue and Topics can beCreated under JMS Server Queue and Topic Services Can be Created only by JMS Module Queue and Topic Services

Can be Created only by JMS Module

JMS Server Starting and Stopping Not Available Not Available Particular JMS Instances Can be Stopped
JMS Advanced features Quota,SAF(Store and Forward Agents) is not Available Quota,SAF(Store and Forward Agents)is Available Quota,SAF

(Store and Forward Agents)

is Available

JMS Configuration repository NO Config file for JMS Separate Configuration File for JMS inside the  WebLogic Domain Separate Configuration File for JMS inside the  WebLogic Domain
JMS transaction No JMS transaction Logs No JMS transaction Logs JMS transaction Logs
Cluster—Unicast  Address No Unicast Address No Unicast address Unicast Address is available
JMS Destination KeyCustom Key TypeFacility No Custom Key Type No Custom Key Type No Custom Key Type
Garbage Collector Process Scheduled GC No GC NO GC Scheduled Garbage Collection
XML—Xpath and XLang—WebService Not Supported Supported Supported
EJB 3.0 Not Supported Supported Supported
Advanced WEbservice Support by SOA Not Supported NOT Supported Supported
Oracle Fusion and Ebusiness Suite Integration Not Supported Not Supported Supported
Log File(Default Transaction Log) Available Not Available Not Available
JDBC log Available Not Available Not Available
Jolt Connection Pools Not Available Available Not Available
Config folder Not Available Available Available
Prepare, Active states No Prepare state for application. Only active state Prepare state for application, This optimises memory utilization. Prepare state for application, This optimises memory utilization.
Deployment fails Server dosent come up if deployment fails Server boots in ADMIN mode if deployment failes Server boots in ADMIN mode if deployment failes
configuration information All configuration information is in one config.xml Seperate xml files for domain config and jms modules are added Seperate xml files for domain config and jms modules are added
Side by side deployment Side by side deployment is not possible Side by side deployment is possible Side by side deployment is possible
Lock and Edit Not Available Available Available
Connection pools We have connection pools and datasources We have datasources and connection pools are inside datasources. We have datasources and connection pools are inside datasources.
app inf lib and classes Not Available Available Available
Deployment updates We need to delete and redeploy from admin console We can update the application using admin console We can update the application using admin console
Queues We have exclude queues. We have work managers We have work managers
WebLogic Scripting Tool(WLST) Not Available Available Available
license.bea genericlicense.bea file for each version that you candownload from Oracle. genericlicense.bea file for each version that you candownload from Oracle. In WLS 10 MP2 and above, the downloadedsoftware comes with a fully blown license so no need to evendownload a new one from Oracle.

Ticketing Tools

1) BMC Remedy ticketing tool:

IITL(Information Technology Infrastructure Library)Process:

  1. Change Management.
  2. Incident Management.
  3. Problem Management.
  4. Release Management.

Different Types of Tickets:

1) Incident ticket which identity by INC: Something happen accidently the ticket which raises manually or automatically.

Ex: WebLogic server failed to startup  ticket will be raised automatically.

2) Change ticket by CRQ: If somebody wants to do change or creating a new during that time the change management ticket uses.

3) Problem ticket which identified by PBC: It is used to managed problem investigations known errors and solutions DB(Data Base)entries. Problem management can practically prevent the occurency of incidents errors and addition management.

States of Tickets:

1) New: Displays when creating a new record or ticket.

2) Assigned: Auto set to assigned when you create a new incident assigned to some one.

3) In progress: Actively working on that incident also must select at assigning a record to yourself.

4) Pending: can’t work on that incident must fill in the reason failed or pending. It means keeping the ticket on hold for some time.

5) Resolved: A solution or work around has been found, must fill in the status reason failed.

6) Closed: The system will auto-close in five business days or if user wants close the ticket we can close immediately or manually.

7) Canceled: If record was an accident or the issue doesn’t need resolution customer or support staff may task incident as cancelled.

Urgency or priority:

1) Critical: It will impact business.

2) High: It will import only for that server or only for that particular batch systems.

3) Medium: It is not that much critical but still we need take task on that job.

4) Low: It does not require to consider this point.

Based on how many systems, process and business units are afforded as well as if the work around is possible or not.

2)  Amdocs clarify CRM Support:

Handling Change Request: If any config  changes have been done. The change request will be raised.

Status of Tickets:

1) Requested: The ticket is in requested state. These are different levels of approvals needed for implementing any change request.

Level1:  Line manager ready.

Level2:  Production co-ordinater ready.

Level3:  Change co-ordinater ready.

Level4:  Skill group implementation(Request implementer) ready.

2) Ready: While getting the approvals the ticket will be in ready state.

3) Scheduled: After getting the approvals the ticket will come in to scheduled state.

4) Accepted: For implementing any change request ticket should be in scheduled state. The request has to be accepted.

5) Resoled:

6) Failed

7) Rejected

IBM Websphere MQ TIPS

IBM Websphere MQ TIPS

It is still in progress. Please wait for update

websphere family.

MQ,MB,WAS,Portal

Features of MQ:

1) message delivery
2) Asynchronus messaging
3) Time dependent
4) Integrity
5) Support

Plat form independent

we can send messages from one os to other os.

A ——– B
solaris   windows
TCP/IP    SPNX

we can write our own code in any language.

JMS Supports Java language.

MQ is a s/w which is developed on java. but it supports all other languages.

it runs on eclipse palat form.

MQ version

dspmqver

ver 7.0  eclipse 3.3
ver 6.0
ver 5.2
ver 5.1
.
.
.

server
client
client with XA enabled. used for commit and roll back transactions.

Default 4MB info including header.

max 100MB info
300MB segmentation is required.

QM is like our weblogic domain

it contains all queues.

runs on a listener. default 1414 unless you define a port.

Queue types:

Remote Queue
Local Queue
Transmission Queue
Dead letter Queue
Alias Queue
Cluster Queue

Local Queue — where you store all the messages.
Remote Queue — Contains All the parameters of definations
It will not store any messages but it will send the messages to local Queue.

Sender recvr  — names should be same

surconn — We use surconn to send the message from the application to MQ.

client A ——-> server B
surconn

Below parameters are required to connect to the client
Qname
servername
port
protocol
 

#dspmqver ( it will display MQ version)

command not found ( MQ is not installed)

Before installation you Make sure that the below dir are exist

/opt/mqm ( all the binaries generated from installation)

/var/mqm ( all the configurations and log file )

Before installing MQ Execute licence file

cd /opt/mqm

./mqlicence.sh

check whether mqm user exist or not

more /etc/passwd | grep mqm

++++++++

#group mqm

mqm unixadms wheel

#pkgadd -d /home/melletit (used to install any s/w in solaris)

execute steps 1,2,3

select below options for MQ installation

1) MQ server

2) Man

3) sample programs

4) mq client

5) IBM jre

6) extended Architecture

enter : 1,3,5,6

cd /opt/mqm

ls -lrt

cd /var/mqm

ls -lrt

#crtmqm QM.DEMO  ( create Queue Manager)

#dspmq  ( It displays QM status )

#dltmq testqmgr ( delete QM)

#strmqm QM.DEMO ( Start Queue manager )

#dspmq ( displays QM status)

#cd /var/mqm

#more mqm.ini ( Contain all the configuration details of QM )

#cd /var/mqm/errors ( Contains installation error logs)

.FDC ( Contains network issues )

$ffstsummary

The tool ffstsummary is also useful – it produces a summary of FFST reports in the current directory, sorted into time order. This can be a good place to start to see the errors reported in your errors directory.

For example:

[dalelane@dlane ~]$ cd /var/mqm/errors
[dalelane@dlane errors]$ ffstsummary
AMQ21433.0.FDC 2007/04/10 10:05:45 amqzdmaa 21433 2 XC338001 xehAsySignalHandler xecE_W_UNEXPECTED_ASYNC_SIGNAL OK
AMQ21429.0.FDC 2007/04/10 10:05:45 amqzmur0 21429 2 XC338001 xehAsySignalHandler xecE_W_UNEXPECTED_ASYNC_SIGNAL OK
AMQ21469.0.FDC 2007/04/10 10:05:45 runmqlsr 21469 2 XC338001 xehAsySignalHandler xecE_W_UNEXPECTED_ASYNC_SIGNAL OK
AMQ21422.0.FDC 2007/04/10 10:05:45 amqzfuma 21422 2 XC338001 xehAsySignalHandler xecE_W_UNEXPECTED_ASYNC_SIGNAL OK
AMQ21424.0.FDC 2007/04/10 10:05:45 amqzmuc0 21424 2 XC338001 xehAsySignalHandler xecE_W_UNEXPECTED_ASYNC_SIGNAL OK
AMQ21431.0.FDC 2007/04/10 10:05:45 amqrrmfa 21431 2 XC338001 xehAsySignalHandler xecE_W_UNEXPECTED_ASYNC_SIGNAL OK
AMQ21449.0.FDC 2007/04/10 10:05:45 amqzlaa0 21449 2 XC338001 xehAsySignalHandler xecE_W_UNEXPECTED_ASYNC_SIGNAL OK
AMQ21434.0.FDC 2007/04/10 10:05:45 amqzmgr0 21434 2 XC338001 xehAsySignalHandler xecE_W_UNEXPECTED_ASYNC_SIGNAL OK
AMQ21452.0.FDC 2007/04/10 10:05:45 runmqchi 21452 2 XC338001 xehAsySignalHandler xecE_W_UNEXPECTED_ASYNC_SIGNAL OK
AMQ21417.0.FDC 2007/04/10 10:05:45 amqzxma0 21417 4 XC338001 xehAsySignalHandler xecE_W_UNEXPECTED_ASYNC_SIGNAL OK
[dalelane@dlane errors]$

#cd /var/mqm/qmgrs/QM!DEMO

more qm.ini ( Contains all the details of particular QM – log, Services, service components)

logfile types

1) circular logs — Info cant be retrived. It will overwrite previous logs.

2) linear logs  — Will keep on appending the log file. (  use for production )

based on criticality of message we will decide the log types.

logpath = /var/mqm/log/QM!DEMO

cd  /var/mqm/log/QM!DEMO/errors — give the errors to the particular QM.

cd /var/mqm/log/QM!DEMO/active — we can check QM is active or not. Some times due to pending message QM goes into inactive state.

#runmqsc  ( used to run mq commands )

There are two ways to configure the objects in MQ

1) command line
2) console

#runmqsc QM.DEMO

AMQ8426: Valid MQSC commands are:

ALTER
CLEAR
DEFINE
DELETE
DISPLAY
END
PING
REFRESH
RESET
RESOLVE
RESUME
START
STOP
SUSPEND

Application     QM.DEMO QM.DEMO1  Application
RQ ( DEMO.REMOTE) LQ (LQ.DEMO1)
TX — local Queue but usage — transmission Recv chl
Sender channel

Create Remote Q:

define QREMOTE(DEMO.REMOTE)

alter qremote(DEMO.REMOTE) RNAME(LQ.DEMO1) RQNAME(QM.DEMO1) XMITQ(XQ.DEMO)

Create Local Q:

define qlocal(XQ.DEMO)

alter qlocal(XQ.DEMO) usage(XMITQ)

define channel(DEMO.DEMO1) chltype(SDR) trptype(TCP) connname(‘localhost(1415)’) xmitq(XQ.DEMO)

end

creating 2nd QM

crtmqm QM.DEMO1

start QM.DEMO1

dspmq  ( check mq stauts)

ps -ef | grep QM.DEMO1

**it will not show any listener.

dis listener(*)

System.default.listener.TCP

alter listener (System.default.listener.TCP)  trptype(TCP) port(1415)

start listener(System.default.listener.TCP)

ps -ef | grep QM.DEMO1

*** 1415 listener

create local Queue:

define qlocal(LQ.DEMO1)

define channel(DEMO.DEMO1) chtype(RCVR) trptype(TCP)

dis channel(*) chltype(SDR)

start channel(DEMO.DEMO1)

dis chstatus(DEMO.DEMO1)

end

find . -name “amqsput”

$cd /opt/mqm/samp/bin

$./amqsput DEMO.REMOTE QM.DEMO

hi welcome to PavanBlog

$./amsget LQ.DEMO1 QM.DEMO1

hi welcome to PavanBlog

Trouble shooting & Interview questions:
***************************************

1) What is Remote Queue? and Remote Queue parameters

2) Reasons for message is going to retain state.

1) Not able to get the connection
2) Input parameter for remote queue might be wrong ( parameter)
3) Destination QM is not running
4) Sender and REcv channel names should be same ( might be wrong some time)
5) Message will be in local queue
6) Problem with message format

xmit Queue properties-> put : allowed
        get : allowed

Local Queue -> usage : Transmission becomes Transmission Queue.

Dead letter Queue (DLQ)
***********************

1.IF destination is not defined or unavailable then message without loss it will store in DLQ .
each queue manager (QM ) will have one DLQ .it is mandatory or suggested to have DLQ .

QM.DEMO   QM.DEMO1
|->DLQ1   
|->DLQ 

RQ LQ
TX  Receiver channel.
SC (sender channel)
                 

Before sender channel started message seats with or stores in TX .
once connection established it will reached the receiver channel and look for destination queue .
if that moment it will not able to find the destination queue it will store the message in DLQ1(which is with  Qmgr )

mqm@ /home/mqm
dspmq

dis qmgr (dispaly all the queue manager properties)
define qlocal(DLQ)

alter qmgr DEADQ(DLQ)

dis qmgr

dspmq

runmqsc QM.DEMO1

define qlocal(DLQ)

alter qmgr DEADQ(DLQ)

dspmq

runmqsc QM.DEMO

dis qremote(*)
dis qlocal(DLQ)
display

dis queue(DEMO.REMOTE)

alter qremote(DEMO.REMOTE) RNAME(LQ.DEMO)

channel –> start manually .
amqsput DEMO.REMOTE QM.DEMO

cd /opt/mqm
cd sampl/bin/

./amqsput DEMO.REMOTE QM.DEMO

Hai Test msg

runmqsc QM.DEMO

dis queue(XQ.DEMO)

CURDEPTH: properties of the queue *  tell the pending message count .

./amqsbcg DEMO.REMOTE XQ.DEMO   (browse the message )

runmqsc QM.DEMO

dis channel(*)   chltype(sdr)

CHANNEL (DEMO.DEMO1)
Start CHANNEL (DEMO.DEMO1)

dis chstatus(DEMO.DEMO1)

rummqsc

./amqsbcg DLQ QM.DEMO1

cd /var/mqm/qmrs/QM\!DEMO1/errors/

deadletter handler  :program will helps in retriveing the message from dlq to destination queue.

if destination queue is  fulled then receiver channel drop the msg into DLQ .

input count : no .of threads connection to local queue to put the msg . (put )
output count : get

always check mq logs .

if message flow is not happening then check following points;

1. MQ logs.
2. destination properties
3. channel is active …
4. application security issue ……(proxy)

end …..

Dead letter Queue (DLQ)
***********************

1.IF destination is not defined or unavailable then message without loss it will store in DLQ .
each queue manager (QM ) will have one DLQ .it is mandatory or suggested to have DLQ .

QM.DEMO   QM.DEMO1
|->DLQ1   
|->DLQ 

RQ LQ
TX  Receiver channel.
SC (sender channel)
                 

Before sender channel started message seats with or stores in TX .
once connection established it will reached the receiver channel and look for destination queue .
if that moment it will not able to find the destination queue it will store the message in DLQ1(which is with  Qmgr )

mqm@ /home/mqm
dspmq

dis qmgr (dispaly all the queue manager properties)
define qlocal(DLQ)

alter qmgr DEADQ(DLQ)

dis qmgr

dspmq

runmqsc QM.DEMO1

define qlocal(DLQ)

alter qmgr DEADQ(DLQ)

dspmq

runmqsc QM.DEMO

dis qremote(*)
dis qlocal(DLQ)
display

dis queue(DEMO.REMOTE)

alter qremote(DEMO.REMOTE) RNAME(LQ.DEMO)

channel –> start manually .
amqsput DEMO.REMOTE QM.DEMO

cd /opt/mqm
cd sampl/bin/

./amqsput DEMO.REMOTE QM.DEMO

Hai Test msg

runmqsc QM.DEMO

dis queue(XQ.DEMO)

CURDEPTH: properties of the queue *  tell the pending message count .

./amqsbcg DEMO.REMOTE XQ.DEMO   (browse the message )

runmqsc QM.DEMO

dis channel(*)   chltype(sdr)

CHANNEL (DEMO.DEMO1)
Start CHANNEL (DEMO.DEMO1)

dis chstatus(DEMO.DEMO1)

rummqsc

./amqsbcg DLQ QM.DEMO1

cd /var/mqm/qmrs/QM\!DEMO1/errors/

deadletter handler  :program will helps in retriveing the message from dlq to destination queue.

if destination queue is  fulled then receiver channel drop the msg into DLQ .

input count : no .of threads connection to local queue to put the msg . (put )
output count : get

always check mq logs .

if message flow is not happening then check following points;

1. MQ logs.
2. destination properties
3. channel is active …
4. application security issue ……(proxy)

end …..

what is OSB?

OSB is a shared domain and used for transformation and routing like Message Broker in Websphere.

OSB requires Weblogic.
MB  requires    MQ.

$runmqsc QM.DEMO

dis channel(*) chtype(snd)  ( it will display All channels)

Xmit Q->Trigger control : on
Trigger type    : first
full
  depth

depth   : 1

data    : ALSB.TO.EC -> channel
Init Q  : SYSTEM.CHANNEL.INIT Q

dis qlocal(XQ.DEMO)

alter qlocal(XQ.DEMO) TRIGDATA(DEMO.DEMO1) INITQ(SYSTEM.CHANNEL.INITQ)

SYSTEM.CHANNEL.INITQ : Is default for QM.

Putting some msg into remote Q:
_______________________________

cd /opt/mqm/samp/bin

./amqsput DEMO.REMOTE QM.DEMO

type some text here

runmqsc QM.DEMO  (run queue manager)

dis chstatus(DEMO.DEMO1)

./amqsget DLQ QM.DEMO1

** Triggering can start any process ( Ex: star channel)

Queue ->
-> Advanced
-> channel
-> new – sender channel
 server channel

Cluster–Full repository — All running object info
Partial repository — Only info of objects to which it communicating

server   ———>  client
conn channel
(application)——> (MQ server)

Ex: OSB or TUX application —–> (MQ server)
Conn channel

server–conn channel
–> General
–> Extended —-> Max msg length = (should be more than 4MB)
   hearbeat       = 300
   max instances  = 999999999
   max instance per client = 999999999
   message compression     =
   Keep alive.Auto         =

MCA : Message Channel Agent —> UserID : MQALSB
–>Exist-> Security exit name: BlockIP(Block Exit)
   user data : FN = /var/mqm/exist641/ALSB.txt

ALSB.txt file : Contains user details . Those users can only alter the QM using server channel.

–>SSL — Used for security purpose and some certificates have been installed.
Cipher Text : /#A&sjfsjslf08j)+/jllljjj

./amgsbcg DLQ12 QM.DEMO1

Error: reason 2085

mqrc 2085 ( It will display error details )

endmqm QM.DEMO1 (stop QM)

IMP Error numbers:
—————–

mqrc 2085

2085  0x00000825  MQRC_UNKNOWN_OBJECT_NAME
mqrc 2058

2058  0x0000080a  MQRC_Q_MGR_NAME_ERROR
mqrc 2059

2059  0x0000080b  MQRC_Q_MGR_NOT_AVAILABLE
mqrc 2035

2035  0x000007f3  MQRC_NOT_AUTHORIZED
mqrc 2033

2033  0x000007f1  MQRC_NO_MSG_AVAILABLE
mqrc 2038

2038  0x000007f6  MQRC_NOT_OPEN_FOR_INQUIRE
mqrc 2039

2039  0x000007f7  MQRC_NOT_OPEN_FOR_OUTPUT
mqrc 2016

2016  0x000007e0  MQRC_GET_INHIBITED

binding concept:

/bea/osb103/scripts/jmsadm.scp

binding files : ex: .bindings

binding file contails Queue info in osb

like connection factory, Jndi info , etc.

SHELL SCRIPTING Reference

SHELL SCRIPTING:

-shell is a command line interpreter

-it is interface b/w user & kernel

– it takes commands form the user and excute them

Shell  are different types:

Shell           developed   shellprompt                   executetioncommand

Bourne        SteveBorn   $                           sh

Corn           devidCorn   $                           ksh

Cshell                   billjoy                   %                          csh

Bash           born            $                           sh(or)bsh

Zsh             panel           $                           zsh

Shell variables:

There are two types of shell variables.

Unix Defined or system defined

User Defined

Unix Defined:-these are standed variable which are always accessable.the shell provide the values for these variables. These variables are usually used by the system we can change the variables as per over preference an custamize the system environment.

$ set

HOME=/user/pavan

HZ=100

IFS=space or tab or new line

LOGNAME=pavan

MAIL=usr/sped/mail/pavan

MAILCHEECK=600sec

OPTEND=1

PATH=/bin:/usr/bin:/usr/pavan:/bin:.

PS1=$primary shell prompt

Ps2= > -system prompt(default values)

SHELL=/bin/sh

TERM=vt100

TZ=ist-5:30

PATH:- Define the which shell  must search in order to command .

HOME:-store default working directory of the user.

LOGNAME:-store the log name of the user.

MAIL:-Define the file where the mail of user stored.

MAILCHECK:-define the duration after which shell checks whether the user received mail by default the values 600 sec

IFS:-define the internal felids separator which is space or tab or newline

SHELL:-define the name of you are working shell.

TERM:-define the name of the term and which you r working.

TZ:-define the name of the time zone in which you are working

User defined variable:-

These are defined by the user and used most exclusively  in shell programming

Rules for creating user shell variables

The first character should be alphabet or –

Eg:- -a= ,a=,b=,c=,d=

-no commas or blanks are allowed

Eg:-a,b=10 is worng

Variable names should be casesensitive

Eg:-name=,Name=,nAme=

Variable names should be a shell keywords.

SHELL keywords:

Key words are words which meaning as already been explained to the shell.

Keywords are also called as reverse words

The list of key words are in bourn shell

Echo  for     if       untill read   else    case   set     wait   fi       esas   uset   eval   while readonly          break do      shift   exec   continue      done  ulimit export         exit    umask                   return          frap

Echo statements: Echo command is used to display the message on the screen and it is used to display the values stored in a shell variable.

$echo “welcome”

Display output to the screen.

Double cotes are optional.

UNIX command should be in back cotes (`) in echo statement, otherwise it treats as a text.

$echo “todays date is : date”

O/p – todays date is: date

$echo “todays date is :`date`“

o/p-todays date is : fri apr 5 9:15 Gt 2013

$echo “no of files `wc –l file1` ”

o/p – no of files  10

$echo “my log in name`logname`

o/p – my login name is shahid

$echo “my present working directory is :`pwd`”

o/p – my present working directory is :/home/shahid

Shell variables:

$a = 10

$b = 20

$name = “shahid”

$echo $a – 10

$echo $b – 20

$echo $name – shahid

$mypath=/home/shahid/dir1

$cd $mypath

$pwd

/home/shahid/dir1

Null variables:

A variable which has defined but has not been given any value is known as a null variable.

$n=” “

$n=’ ‘

Constant: It is a fixed value it doesn’t change during execution of the program.

$readonly a

When the variable is made readonly the shell doesn’t allow you to change their values.

$unset a  -> the variable a and its value assigned to it are erased from shell memory.

Escape sequences:

echo “shahid\n”

echo “pavan”

\n – displays in new line

\n                newline                 $echo”shahid\nshaik”

\t                 tab                        $echo”shahid\tshaik”—-shahid         shaik

\b                backspace             $echo”pavan\bkumar”—-pavakumar

\”                 double quote                  $echo”\”pavankumar\””

\’                 single quote

\\                 backslash

Sample program:

Write a program to display list of files and directories and present working directories and no of users logged into the system.

Vi sample.sh

#! /bin/bsh

ls –l

pwd

who

:wq

How to execute shell script?

$sh sample.sh

$./sample.sh

We have to check the permissions and then we have to execute.

Chmod 775 sample.sh

Write a program to display the address?

#!/bin/sh

echo “100/14,20 th main\n”

echo “9th cross maruthi nagar\n”

echo”Bangalore\n”

:wq

$./address.sh

Write a program to count no of users are currently logged into the system?

Echo “ The no of users :`who|wc –l`”

:wq users.sh

./users.sh

Read input from program?

Echo “enter your name:”

Read name

Echo “hello $name how are you”

Execution:

Enter your name: shahid

Hello shahid how are you

Read is a command to read variable value from the input user or keyboard.

Read command reads value from the keyboard up to space or enter key.

echo “enter a, b, c values”

read a b c

echo $a,$b,$c

enter a b c values :3  4 5

3,4,5

write a program to read two numbers and display?

Echo”enter a ,b values”

Read a b

Echo $a  $b

Operators:

  1. Arthematic operators
  2. Relational operators

Numeric comparison

String comparison

  1. Logical operators

1.Arthematic operators : Addition(+) ,subtraction(-) multiplication(*),division(/),modulus division(%)

  1. Relational operators: -gt (>),- lt(<) ,- ge (>=),-le (<=),-eq(=),-ne(!=)
  2. Logical operators:

-And  -a

-Or    -o

-Nor   -!

Write a program to read two numbers and display sum diff pro and div?

Echo “enter 2 numbers”

Read a b

C = `expr $a + $b`

Echo  “ addition is $c”

D = `expr $a – $b`

Echo “subtraction is $D”

E = `expr $a \ * $b`

Echo “product is $E”

F = `expr $a / $b `

Echo “division is $F”

*_ ? [] —wild chard characters we will use “\”

Expr is a command to evaluating arthematic expressions.

But expr is capable of carrying out only integer arthematic.

Write a program to read 2 float numbers and display sum diff prod and divi?

Echo “enter 2 numbers”

Read a b

C = `echo $a + $b\bc`

Echo  “ addition is $c”

D = `echo $a – $b\bc`

Echo “subtraction is $D”

E = `echo $a \ * $b\bc`

Echo “product is $E”

F = `echo $a / $b\bc `

Echo “division is $F”àbc – basic calculator

IF statements:

If condition

then

————

————-

————-

Fi

  1. if condition

Then

————-

———–

Else

Fi

3.ifcondition

Then

—-

Elif condition

—-

Elif condition

—-

Fi

If 0-true

If 1-false

Cd $path

0-success

1-failure

Write a program to change directory?

Echo ”enter directory name”

Read dir

If [cd  $dir]

Then

Echo “changed to $dir”

Pwd

Fi

Write a program to copy a file?

Echo “enter source and target file names”

Read source target

If cp $source $target

Then

Echo “files have been copied successfully”

Else

Echo “failed to copy the file”

Fi

Write a program to search a string in a file?

Write a program to find greatest number of two numbers?

Echo “ enter two numbers”

Read a b

If [$a –gt $b]

Then

Echo “ $a is greatest number”

Else

Echo “$b is greatest number”

fi

write a program to check given number is even or odd?

Echo “ enter a number”

Read a

If [`expr $a%2` -eq 0]

Then

Echo “ even number”

Else

Echo “ odd number”

Fi

Text:-(we use conjection if)

If constantsthe  are generally  used in conjection text command.

Eg:-if text [condi]

If condi

If[condi]

The text command help us to find the contents of  a variable the no of variables and the type of file or kind of file permission.

The text command returns an exist status after evaluating the condition

Sy:-if text condition

Then

Commands

Else

Commands

Fi

Write a program to check how many users or working on the system

#!/usr/bin/bsh

Total=’ who|wc –l ‘

If text $total –eq 1

Then

Echo” u r only the user logged in “

Else

Echo “total no of users:$total”

Fi

Write a program to check the given number is +ve or –ve?

#!/usr/bin/bsh

Echo “enter a number in”

Read a

If text $a –gt 0

Then

Echo “ the entered no is +ve”

elseIf text $a –eq 0

echo “the entered no is 0”

elseif text $a –lt 0

echo “the entered no is –ve”

fi

write a program to find out student results

#!/usr/bin/bsh

Echo “enter subject marks”

Read m1 m2 m3

If text $m1 –ge 35

Then

If text $m2 –ge 35

then

If text $m1 –ge 35

Echo “pass”

Else

Echo “fail”

Elseif

Echo “fail”

Elseif

Echo “fail”

Fi

Write a program to print greatings.

Hour=’date | cut –c 12, 13’

If[hour –ge 0 –a $hour –lt 12]

Then

Echo “Good moring”

Elseif[$hour –gt 12 –a $hour –lt 17)

Echo “good afternoon”

Else

Echo “good evening”

Fi

Fi

File text command:

-s –true if the file exist and has a size>0

-f-true if the file exists and is not a directory.

-d-true if the exists is in directory

-c- true if the file exist

-r-true if the file exist it have read permission

-w-true if the file write permission

-x-true if the file execute permission

Write a program to check for ordinary file and display it contents

Echo “enter a file name to be opened”

Read filename

If text –f $filename

Then

Cat<$fname

Else

Echo “ file is not present “

Fi

Write a program to check given file an ordinary file or directory

Echo “enter a filename”

Read fname

If[-f $fname]

Then

Echo”it is an ordinary file”

Elseif[-d $fname]

Echo “it is a directory file”

Else

Echo “it is not an ordinary file”

Fi

Write a program to open a file if the doesn’t have read permission then assign the permission & open a file .

Echo “enter a file”

Read filename

If [-r $ fname]

Then

Cat <$fname

Else

Chmod u+r $fname

Cat<$fname

Fi

Write a program to append data to the file

Echo “enter a file”

Read fname

If[-f $fname]

Then

If[-w$fname]

Then

Echo “enter the content & press ctr+d at the end”

Cat>>fname

Else

Chmod u+w $fname

Cat>>fname

Fi

Else

Echo “enter the data press ctr+d”

Cat>fname

Fi

String text command:

Str1=str2-true if the strings are equal

Str!=str2-true if the strings not equal

-n str-true if the length of string is >0

-z str-true if the length of equal zero(=0)

Write a program to compare two strings

Echo”enter str1”

Read str1

Echo “enter str2”

Read str2

If text $str1=$str2

Then

Echo “both are equal”

Else

Echo “both are not equal”

Fi

Write a program to check given string is empty or not

Echo “enter a string “

Read string

If text –z $string

Then

Echo “string is empty”

Else

Echo “string is not empty”

Fi

CASE CONTROL STATEMENTS

Case value in

Choice 1)

___________

___________

;;

Choice 2)

—————-

—————-

—————-

;;

Choice *

———————–

——————–

;;

esac

The expression the following the case keyword is evaluate first the value that it yields is then mathch one by one against potential choices like choice 1 choice 2 ……………. choice n.when match is found then shell will execute all commands in that case upto ;; .this pair of semicolons placed at the end of each choice.

Eg:-

Echo “enter a number b/w 1 to 4”

Read num

Case $num in

Echo “ u entered one”

;;

Echo “u entered two”

;;

Echo “u entered three”

;;

Echo “u entered four”

;;

Esac

Write a program to check given character is uppercase alphabet or lower case alphabet or digit or special character.

Echo “enter a character”

Read ch

Case $ ch in

[a-z] echo “u entered lowercase charecters”

;;

[A-Z] echo “ u entere lower case charecters”

;;

[0-9] echo “u entered digits”

;;

?) echo “u entered special character”

;;

Esac

Write a program to display file contents or write on to the file or execute based on user choice

Echo “enter a filename”

Read fname

Echo “main menu”

Echo “***********”

Echo”r-readmode”

Echo “w-writemode”

Echo “x-excute mode”

Echo “enter mode”

Read mode

Case $ mode in

Choice r) If[-f $fname –a –r $fname]

Then

Cat<$fname

Fi

;;

Choice w) if[-f $fname –a –w$fname]

Then

Echo “enter data & press ctr+d”

Cat>>$fname

Fi

;;

Choice x) if[-f $fname –a –x $fname]

Then

$fname

Fi

;;

Choice *) echo “u r execute invalid input”

Esac

Exit statement:

It is used to terminate execution of shell programming

Eg:-$exit

Looping control statements:

While

Until

forloop

while:-

while condition

do

———–

————–

Done

Until:

Until condition

Do

——————

—————–

Done

Forloop:

For varable in value1,value2……………….valuen

Do

——————-

———————

Done

Write a program to display number from 1 to 10

Echo “enter no from 1 to 10”

I=1

While [$i –gt 10]

Do

Echo “$i”

I=”expr $i+1”

Done

Break Or continue statements:

Break:

When the keyword break is encounted inside any loop etc automatically passes to the first statement after the loop

While condition

Do

————–

————–

Break

——————-

————-

Done

Continue:

When the keyword continue is encounted inside loop control automatically passes to the beginning of the loop & continue from beginning of the loop .

Write a program to display file contents of the file existing

X=0

While test $x=0

Do

Echo “enter a filename”

Read fname

If text ! –f $name

Then

Echo “$fname is not found enter current file “

Continue

Else

Break

Fi

Done

Cat $ fname | more

Until: execute from false.then true it will not execute

Write a program to print no 1 to 10?

I=1

Untile [$i –gt 10]

Do

Echo $i

I=”expr $i+1”

Done

Sleep:

Sleep commmad stop the execution of the program that specified no of seconds.

Write a program to print no  from 1 to 10.

For i in 1 2 3 4 5 6 7 8 9 10

Do

Echo $i

Done

Command line arguments:
$0-first argument

$1-second argument

$./script.sh arg1 arg2…………………argn

$*-contains active string of an arguments

$#-contains no of arguments specified in the command

$?-it will store the last execution commands states.

 

Apache URL rewriting

Most dynamic sites include variables in their URLs that tell the site what information to show the user. Typically, this gives URLs like the following, telling the relevant script on a site to load product number 7.
http://www.pets.com/show_a_product.php?product_id=7

The problems with this kind of URL structure are that the URL is not at all memorable. It’s difficult to read out over the phone (you’d be surprised how many people pass URLs this way). Search engines and users alike get no useful information about the content of a page from that URL. You can’t tell from that URL that that page allows you to buy a Norwegian Blue Parrot (lovely plumage). It’s a fairly standard URL – the sort you’d get by default from most CMSes. Compare that to this URL:
http://www.pets.com/products/7/

Clearly a much cleaner and shorter URL. It’s much easier to remember, and vastly easier to read out. That said, it doesn’t exactly tell anyone what it refers to. But we can do more:
http://www.pets.com/parrots/norwegian-blue/

Now we’re getting somewhere. You can tell from the URL, even when it’s taken out of context, what you’re likely to find on that page. Search engines can split that URL into words (hyphens in URLs are treated as spaces by search engines, whereas underscores are not), and they can use that information to better determine the content of the page. It’s an easy URL to remember and to pass to another person.

Unfortunately, the last URL cannot be easily understood by a server without some work on our part. When a request is made for that URL, the server needs to work out how to process that URL so that it knows what to send back to the user. URL rewriting is the technique used to “translate” a URL like the last one into something the server can understand.
Platforms and Tools

Depending on the software your server is running, you may already have access to URL rewriting modules. If not, most hosts will enable or install the relevant modules for you if you ask them very nicely.

Apache is the easiest system to get URL rewriting running on. It usually comes with its own built-in URL rewriting module, mod_rewrite, enabled, and working with mod_rewrite is as simple as uploading correctly formatted and named text files.

IIS, Microsoft’s server software, doesn’t include URL rewriting capability as standard, but there are add-ons out there that can provide this functionality. ISAPI_Rewrite is the one I recommend working with, as I’ve so far found it to be the closest to mod_rewrite’s functionality. Instructions for installing and configuring ISAPI_Rewrite can be found at the end of this article.

The code that follows is based on URL rewriting using mod_rewrite.
Basic URL Rewriting

To begin with, let’s consider a simple example. We have a website, and we have a single PHP script that serves a single page. Its URL is:
http://www.pets.com/pet_care_info_07_07_2008.php

We want to clean up the URL, and our ideal URL would be:
http://www.pets.com/pet-care/

In order for this to work, we need to tell the server to internally redirect all requests for the URL “pet-care” to “pet_care_info_07_07_2008.php”. We want this to happen internally, because we don’t want the URL in the browser’s address bar to change.

To accomplish this, we need to first create a text document called “.htaccess” to contain our rules. It must be named exactly that (not “.htaccess.txt” or “rules.htaccess”). This would be placed in the root directory of the server (the same folder as “pet_care_info_07_07_2008.php” in our example). There may already be an .htaccess file there, in which case we should edit that rather than overwrite it.

The .htaccess file is a configuration file for the server. If there are errors in the file, the server will display an error message (usually with an error code of “500”). If you are transferring the file to the server using FTP, you must make sure it is transferred using the ASCII mode, rather than BINARY. We use this file to perform 2 simple tasks in this instance – first, to tell Apache to turn on the rewrite engine, and second, to tell apache what rewriting rule we want it to use. We need to add the following to the file:
RewriteEngine On # Turn on the rewriting engine 
RewriteRule ^pet-care/?$ pet_care_info_01_02_2008.php [NC,L] # Handle requests for “pet-care”

A couple of quick items to note – everything following a hash symbol in an .htaccess file is ignored as a comment, and I’d recommend you use comments liberally; and the “RewriteEngine” line should only be used once per .htaccess file (please note that I’ve not included this line from here onwards in code example).

The “RewriteRule” line is where the magic happens. The line can be broken down into 5 parts:

RewriteRule – Tells Apache that this like refers to a single RewriteRule.
^/pet-care/?$ – The “pattern”. The server will check the URL of every request to the site to see if this pattern matches. If it does, then Apache will swap the URL of the request for the “substitution” section that follows.
pet_care_info_01_02_2003.php – The “substitution”. If the pattern above matches the request, Apache uses this URL instead of the requested URL.
[NC,L] – “Flags”, that tell Apache how to apply the rule. In this case, we’re using two flags. “NC”, tells Apache that this rule should be case-insensitive, and “L” tells Apache not to process any more rules if this one is used.
# Handle requests for “pet-care” – Comment explaining what the rule does (optional but recommended)

The rule above is a simple method for rewriting a single URL, and is the basis for almost all URL rewriting rules.
Patterns and Replacements

The rule above allows you to redirect requests for a single URL, but the real power of mod_rewrite comes when you start to identify and rewrite groups of URLs based on patterns they contain.

Let’s say you want to change all of your site URLs as described in the first pair of examples above. Your existing URLs look like this:
http://www.pets.com/show_a_product.php?product_id=7

And you want to change them to look like this:
http://www.pets.com/products/7/

Rather than write a rule for every single product ID, you of course would rather write one rule to manage all product IDs. Effectively you want to change URLs of this format:
http://www.pets.com/show_a_product.php?product_id={a number}

And you want to change them to look like this:
http://www.pets.com/products/{a number}/

In order to do so, you will need to use “regular expressions”. These are patterns, defined in a specific format that the server can understand and handle appropriately. A typical pattern to identify a number would look like this:
[0-9]+

The square brackets contain a range of characters, and “0-9” indicates all the digits. The plus symbol indicates that the pattern will idenfiy one or more of whatever precedes the plus – so this pattern effectively means “one or more digits” – exactly what we’re looking to find in our URL.

The entire “pattern” part of the rule is treated as a regular expression by default – you don’t need to turn this on or activate it at all.
RewriteRule ^products/([0-9]+)/?$ show_a_product.php?product_id=$1 [NC,L] 
# Handle product requests 

The first thing I hope you’ll notice is that we’ve wrapped our pattern in brackets. This allows us to “back-reference” (refer back to) that section of the URL in the following “substitution” section. The “$1” in the substitution tells Apache to put whatever matched the earlier bracketed pattern into the URL at this point. You can have lots of backreferences, and they are numbered in the order they appear.

And so, this RewriteRule will now mean that Apache redirects all requests for domain.com/products/{number}/ to show_a_product.php?product_id={same number}.
Regular Expressions

A complete guide to regular expressions is rather beyond the scope of this article. However, important points to remember are that the entire pattern is treated as a regular expression, so always be careful of characters that are “special” characters in regular expressions.

The most instance of this is when people use a period in their pattern. In a pattern, this actually means “any character” rather than a literal period, and so if you want to match a period (and only a period) you will need to “escape” the character – precede it with another special character, a backslash, that tells Apache to take the next character to be literal.

For example, this RewriteRule will not just match the URL “rss.xml” as intended – it will also match “rss1xml”, “rss-xml” and so on.
RewriteRule ^rss.xml$ rss.php [NC,L] # Change feed URL

This does not usually present a serious problem, but escaping characters properly is a very good habit to get into early. Here’s how it should look:
RewriteRule ^rss\.xml$ rss.php [NC,L] # Change feed URL

This only applies to the pattern, not to the substitution. Other characters that require escaping (referred to as “metacharacters”) follow, with their meaning in brackets afterwards:

. (any character)
* (zero of more of the preceding)
+ (one or more of the preceding)
{} (minimum to maximum quantifier)
? (ungreedy modifier)
! (at start of string means “negative pattern”)
^ (start of string, or “negative” if at the start of a range)
$ (end of string)
[] (match any of contents)
– (range if used between square brackets)
() (group, backreferenced group)
| (alternative, or)
\ (the escape character itself)

Using regular expressions, it is possible to search for all sorts of patterns in URLs and rewrite them when they match. Time for another example – we wanted earlier to be able to indentify this URL and rewrite it:

http://www.pets.com/parrots/norwegian-blue/

And we want to be able to tell the server to interpret this as the following, but for all products:
http://www.pets.com/get_product_by_name.php?product_name=norwegian-blue

And we can do that relatively simply, with the following rule:
RewriteRule ^parrots/([A-Za-z0-9-]+)/?$ get_product_by_name.php?product_name=$1 [NC,L] 
# Process parrots 
With this rule, any URL that starts with “parrots” followed by a slash (parrots/), then one or more (+) of any combination of letters, numbers and hyphens ([A-Za-z0-9-]) (note the hyphen at the end of the selection of characters within square brackets – it must be added there to be treated literally rather than as a range separator). We reference the product name in brackets with $1 in the substitution.

We can make it even more generic, if we want, so that it doesn’t matter what directory a product appears to be in, it is still sent to the same script, like so:
RewriteRule ^[A-Za-z-]+/([A-Za-z0-9-]+)/?$ get_product_by_name.php?product_name=$1 [NC,L] # Process all products
As you can see, we’ve replaced “parrots” with a pattern that matches letter and hyphens. That rule will now match anything in the parrots directory or any other directory whose name is comprised of at least one or more letters and hyphens.
Flags

Flags are added to the end of a rewrite rule to tell Apache how to interpret and handle the rule. They can be used to tell apache to treat the rule as case-insensitive, to stop processing rules if the current one matches, or a variety of other options. They are comma-separated, and contained in square brackets. Here’s a list of the flags, with their meanings (this information is included on the cheat sheet, so no need to try to learn them all).

C (chained with next rule)
CO=cookie (set specified cookie)
E=var:value (set environment variable var to value)
F (forbidden – sends a 403 header to the user)
G (gone – no longer exists)
H=handler (set handler)
L (last – stop processing rules)
N (next – continue processing rules)
NC (case insensitive)
NE (do not escape special URL characters in output)
NS (ignore this rule if the request is a subrequest)
P (proxy – i.e., apache should grab the remote content specified in the substitution section and return it)
PT (pass through – use when processing URLs with additional handlers, e.g., mod_alias)
R (temporary redirect to new URL)
R=301 (permanent redirect to new URL)
QSA (append query string from request to substituted URL)
S=x (skip next x rules)
T=mime-type (force specified mime type)

Moving Content
RewriteRule ^article/?$ http://www.new-domain.com/article/ [R,NC,L] # Temporary Move

Adding an “R” flag to the flags section changes how a RewriteRule works. Instead of rewriting the URL internally, Apache will send a message back to the browser (an HTTP header) to tell it that the document has moved temporarily to the URL given in the “substitution” section. Either an absolute or a relative URL can be given in the substitution section. The header sent back includea a code – 302 – that indicates the move is temporary.
RewriteRule ^article/?$ http://www.new-domain.com/article/ [R=301,NC,L] # Permanent Move

If the move is permanent, append “=301” to the “R” flag to have Apache tell the browser the move is considered permanent. Unlike the default “R”, “R=301” will also tell the browser to display the new address in the address bar.

This is one of the most common methods of rewriting URLs of items that have moved to a new URL (for example, it is in use extensively on this site to forward users to new post URLs whenever they are changed).
Conditions

Rewrite rules can be preceded by one or more rewrite conditions, and these can be strung together. This can allow you to only apply certain rules to a subset of requests. Personally, I use this most often when applying rules to a subdomain or alternative domain as rewrite conditions can be run against a variety of criteria, not just the URL. Here’s an example:
RewriteCond %{HTTP_HOST} ^addedbytes\.com [NC] RewriteRule ^(.*)$ http://www.addedbytes.com/$1 [L,R=301]
The rewrite rule above redirects all requests, no matter what for, to the same URL at “www.addedbytes.com”. Without the condition, this rule would create a loop, with every request matching that rule and being sent back to itself. The rule is intended to only redirect requests missing the “www” URL portion, though, and the condition preceding the rule ensures that this happens.

The condition operates in a similar way to the rule. It starts with “RewriteCond” to tell mod_rewrite this line refers to a condition. Following that is what should actually be tested, and then the pattern to test. Finally, the flags in square brackets, the same as with a RewriteRule.

The string to test (the second part of the condition) can be a variety of different things. You can test the domain being requested, as with the above example, or you could test the browser being used, the referring URL (commonly used to prevent hotlinking), the user’s IP address, or a variety of other things (see the “server variables” section for an outline of how these work).

The pattern is almost exactly the same as that used in a RewriteRule, with a couple of small exceptions. The pattern may not be interpreted as a pattern if it starts with specific characters as described in the following “exceptions” section. This means that if you wish to use a regular expression pattern starting with <, >, or a hyphen, you should escape them with the backslash.

Rewrite conditions can, like rewrite rules, be followed by flags, and there are only two. “NC”, as with rules, tells Apache to treat the condition as case-insensitive. The other available flag is “OR”. If you only want to apply a rule if one of two conditions match, rather than repeat the rule, add the “OR” flag to the first condition, and if either match then the following rule will be applied. The default behaviour, if a rule is preceded by multiple conditions, is that it is only applied if all rules match.
Exceptions and Special Cases

Rewrite conditions can be tested in a few different ways – they do not need to be treated as regular expression patterns, although this is the most common way they are used. Here are the various ways rewrite conditons can be processed:

<Pattern (is test string lower than pattern)
>Pattern (is test string greater than pattern)
=Pattern (is test string equal to pattern)
-d (is test string a valid directory)
-f (is test string a valid file)
-s (is test string a valid file with size greater than zero)
-l (is test string a symbolic link)
-F (is test string a valid file, and accessible (via subrequest))
-U (is test string a valid URL, and accessible (via subrequest))

Server Variables

Server variables are a selection of items you can test when writing rewrite conditions. This allows you to apply rules based on all sorts of request parameters, including browser identifiers, referring URL or a multitude of other strings. Variables are of the following format:
%{VARIABLE_NAME}

And “VARIABLE_NAME” can be replaced with any one of the following items:

HTTP Headers
HTTP_USER_AGENT
HTTP_REFERER
HTTP_COOKIE
HTTP_FORWARDED
HTTP_HOST
HTTP_PROXY_CONNECTION
HTTP_ACCEPT
Connection Variables
REMOTE_ADDR
REMOTE_HOST
REMOTE_USER
REMOTE_IDENT
REQUEST_METHOD
SCRIPT_FILENAME
PATH_INFO
QUERY_STRING
AUTH_TYPE
Server Variables
DOCUMENT_ROOT
SERVER_ADMIN
SERVER_NAME
SERVER_ADDR
SERVER_PORT
SERVER_PROTOCOL
SERVER_SOFTWARE
Dates and Times
TIME_YEAR
TIME_MON
TIME_DAY
TIME_HOUR
TIME_MIN
TIME_SEC
TIME_WDAY
TIME
Special Items
API_VERSION
THE_REQUEST
REQUEST_URI
REQUEST_FILENAME
IS_SUBREQ

Working With Multiple Rules

The more complicated a site, the more complicated the set of rules governing it can be. This can be problematic when it comes to resolving conflicts between rules. You will find this issue rears its ugly head most often when you add a new rule to a file, and it doesn’t work. What you may find, if the rule itself is not at fault, is that an earlier rule in the file is matching the URL and so the URL is not being tested against the new rule you’ve just added.
RewriteRule ^([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/?$ get_product_by_name.php?category_name=$1&product_name=$2 [NC,L] # Process product requests                  
RewriteRule ^([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/?$ get_blog_post_by_title.php?category_name=$1&post_title=$2 [NC,L] # Process blog posts
In the example above, the product pages of a site and the blog post pages have identical patterns. The second rule will never match a URL, because anything that would match that pattern will have already been matched by the first rule.

There are a few ways to work around this. Several CMSes (including wordpress) handle this by adding an extra portion to the URL to denote the type of request, like so:
RewriteRule ^products/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/?$ get_product_by_name.php?category_name=$1&product_name=$2 [NC,L] # Process product requests
RewriteRule ^blog/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/?$ get_blog_post_by_title.php?category_name=$1&post_title=$2 [NC,L]# Process blog posts 
You could also write a single PHP script to process all requests, which checked to see if the second part of the URL matched a blog post or a product. I usually go for this option, as while it may increase the load on the server slightly, it gives much cleaner URLs.
RewriteRule ^([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/?$ get_product_or_blog_post.php?category_name=$1&item_name=$2 [NC,L] # Process product and blog requests

There are certain situations where you can work around this issue by writing more precise rules and ordering your rules intelligently. Imagine a blog where there were two archives – one by topic and one by year.
RewriteRule ^([A-Za-z0-9-]+)/?$ get_archives_by_topic.php?topic_name=$1 [NC,L] # Get archive by topic 
RewriteRule ^([A-Za-z0-9-]+)/?$ get_archives_by_year.php?year=$1 [NC,L] # Get archive by 

The above rules will conflict. Of course, years are numeric and only 4 digits, so you can make that rule more precise, and by running it first the only type of conflict you cound encounter would be if you had a topic with a 4-digit number for a name.
RewriteRule ^([0-9]{4})/?$ get_archives_by_year.php?year=$1 [NC,L] # Get archive by year RewriteRule ^([A-Za-z0-9-]+)/?$ get_archives_by_topic.php?topic_name=$1 [NC,L] # Get archive by topic
mod_rewrite

Apache’s mod_rewrite comes as standard with most Apache hosting accounts, so if you’re on shared hosting, you are unlikely to have to do anything. If you’re managing your own box, then you most likely just have to turn on mod_rewrite. If you are using Apache1, you will need to edit your httpd.conf file and remove the leading ‘#’ from the following lines:
#LoadModule rewrite_module modules/mod_rewrite.so #AddModule mod_rewrite.c

If you are using Apache2 on a Debian-based distribution, you need to run the following command and then restart Apache:
sudo a2enmod rewrite

Other distubutions and platforms differ. If the above instructions are not suitable for your system, then Google is your friend. You may need to edit your apache2 configuration file and add “rewrite” to the “APACHE_MODULES” list, or edit httpd.conf, or even download and compile mod_rewrite yourself. For the majority, however, installation should be simple.
ISAPI_Rewrite

ISAPI_Rewrite is a URL rewriting plugin for IIS based on mod_rewrite and is not free. It performs most of the same functionality as mod_rewrite, and there is a good quality ISAPI_Rewrite forum where most common questions are answered. As ISAPI_Rewrite works with IIS, installation is relatively simple – there are installation instructions available.

ISAPI_Rewrite rules go into a file named httpd.ini. Errors will go into a file named httpd.parse.errors by default.
Leading Slashes

I have found myself tripped up numerous times by leading slashes in URL rewriting systems. Whether they should be used in the pattern or in the substitution section of a RewriteRule or used in a RewriteCond statement is a constant source of frustration to me. This may be in part because I work with different URL rewriting engines, but I would advise being careful of leading slashes – if a rule is not working, that’s often a good place to start looking. I never include leading slashes in mod_rewrite rules and always include them in ISAPI_Rewrite.
Sample Rules

To redirect an old domain to a new domain:
RewriteCond %{HTTP_HOST} old_domain\.com [NC] RewriteRule ^(.*)$ http://www.new_domain.com/$1 [L,R=301]
To redirect all requests missing “www” (yes www):
RewriteCond %{HTTP_HOST} ^domain\.com [NC] RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301]

To redirect all requests with “www” (no www):
RewriteCond %{HTTP_HOST} ^www\.domain\.com [NC] RewriteRule ^(.*)$ http://domain.com/$1 [L,R=301]

Redirect old page to new page:
RewriteRule ^old-url\.htm$ http://www.domain.com/new-url.htm [NC,R=301,L]

CentOS Remove Old Kernels

Tonight when upgrading a CentOS Linux server it was noted by YUM that 15MB more disk space was needed to upgrade grub and the kernel itself. Below are four quick steps to verify what kernels are installed, install yum-utils if it is not installed already, delete previous kernels and set YUM to remove old kernels when new kernels are installed. Depending on the size of your /boot directory you should make a decision on how many previous kernels you want to keep installed though I would recommend always keeping at least one previous kernel at a minimum. In the steps below we go off that recommendation and set YUM to always keep two kernels which would include the current kernel and one previous kernel.

YUM Warning Regarding /boot Disk Space:

As you can see below during the transaction test YUM runs during package installation, upgrades, etc. there is a warning that stops the update process because there is not enough room on the /boot partition.

Total                                                                                                                                                                          8.5 MB/s | 167 MB     00:19
Running rpm_check_debug
Running Transaction Test
Transaction Check Error:
  installing package kernel-2.6.32-431.17.1.el6.centos.plus.x86_64 needs 15MB on the /boot filesystem
  installing package grub-1:0.97-83.el6.x86_64 needs 15MB on the /boot filesystem
Error Summary
-------------
Disk Requirements:
  At least 15MB more space needed on the /boot filesystem.

Once you receive that warning it is always good to manually check the disk space left on the server to verify YUM is reporting accurately. You can see in the below output from a CentOS Linux server that there is only 14MB of disk space available and YUM is reporting that it needs at least 29MB of disk space to complete the grub and kernel upgrades.

Show Disk Usage Per Partition on CentOS Linux:

[root@dev ~# df -kh
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 228G 22G 194G 11% /
tmpfs 1.9G 0 1.9G 0% /dev/shm
/dev/sda1 99M 81M 14M 87% /boot
[root@dev ~]#

Follow the steps below to list currently installed kernels on your CentOS server, install yum-utils for the package-cleanup command, remove the oldest kernels on the CentOS Linux server and configure YUM to automatically remove older kernels when new kernels are installed in the future.

Remove Previous CentOS Linux Kernels:

  1. List Installed CentOS Linux Kernels: Use the RPM command listed in the example below to list the set of kernels currently installed on your CentOS Linux server.
    [root@dev ~]# rpm -q kernel
    kernel-2.6.32-358.el6.x86_64
    kernel-2.6.32-358.6.2.el6.x86_64
    kernel-2.6.32-358.18.1.el6.x86_64
    [root@dev ~]#
  2. Install YUM Utilities Package On CentOS Linux: Now install the yum-utils package on Linux as shown in the example command below.
    [root@dev ~]# yum install yum-utils
    Loaded plugins: fastestmirror, security
    Loading mirror speeds from cached hostfile
     * atomic: www8.atomicorp.com
     * epel: mirror.compevo.com
     * rpmforge: mirror.team-cymru.org
    Setting up Install Process
    Resolving Dependencies
    --> Running transaction check
    ---> Package yum-utils.noarch 0:1.1.30-14.el6 will be updated
    ---> Package yum-utils.noarch 0:1.1.30-17.el6_5 will be an update
    --> Finished Dependency Resolution
    Dependencies Resolved
    ===============================================================================================================================
     Package                    Arch                     Version               Repository                             Size
    ===============================================================================================================================
    Updating:
     yum-utils                  noarch                   1.1.30-17.el6_5       updates                                102 k
    Transaction Summary
    ===============================================================================================================================
    Upgrade       1 Package(s)
    Total size: 102 k
    Is this ok [y/N]: y
    Downloading Packages:
    Running rpm_check_debug
    Running Transaction Test
    Transaction Test Succeeded
    Running Transaction
      Updating   : yum-utils-1.1.30-17.el6_5.noarch                             1/2
      Cleanup    : yum-utils-1.1.30-14.el6.noarch                               2/2
      Verifying  : yum-utils-1.1.30-17.el6_5.noarch                             1/2
      Verifying  : yum-utils-1.1.30-14.el6.noarch                               2/2
    Updated:
      yum-utils.noarch 0:1.1.30-17.el6_5                                                                                             Complete!
    [root@dev ~]#
  3. Remove Older CentOS Linux Kernels: Once the CentOS yum-utils package has been installed you will now have access to the package-cleanup command which will allow us to easily remove previous CentOS Linux kernels as shown in the below example command output.
    [root@dev ~]# package-cleanup --oldkernels --count=2
    Loaded plugins: fastestmirror
    Loading mirror speeds from cached hostfile
     * atomic: www8.atomicorp.com
     * epel: mirror.steadfast.net
     * rpmforge: mirror.team-cymru.org
    --> Running transaction check
    ---> Package kernel.x86_64 0:2.6.32-358.el6 will be erased
    --> Finished Dependency Resolution
    Dependencies Resolved
    ===============================================================================================================================
     Package        Arch       Version           Repository                                                       Size
    ===============================================================================================================================
    Removing:
     kernel         x86_64    2.6.32-358.el6     @anaconda-CentOS-201303050102.x86_64/6.4                         116 M
    Transaction Summary
    ===============================================================================================================================
    Remove        1 Package(s)
    Installed size: 116 M
    Is this ok [y/N]: y
    Downloading Packages:
    Running rpm_check_debug
    Running Transaction Test
    Transaction Test Succeeded
    Running Transaction
      Erasing    : kernel-2.6.32-358.el6.x86_64            1/1
      Verifying  : kernel-2.6.32-358.el6.x86_64            1/1
    Removed:
      kernel.x86_64 0:2.6.32-358.el6                                                                                               Complete!
    [root@dev ~]#
  4. Update YUM Configuration to Automatically Remove Old Kernels: Once we have the old CentOS Linux kernels removed we should now update the yum.conf file located in the /etc directory on CentOS Linux to automatically remove the oldest kernel every time a new kernel is installed. Again the minimum you should set the install_only limit is two so you can always roll back to the older kernel is need be. Use your favorite editor such as “vi” to edit the /etc/yum.conf file and modify the install_only configuration line from the default 5 to 2 as shown in the below examples.Default yum.conf install_only Configuration:
    installonly_limit=5

    Default yum.conf install_only Configuration:

    installonly_limit=2
  5. Verify CentOS Linux /boot Directory Free Disk Space: As you can see in the output below there is 42MB of disk space available even after using “yum update” to update packages that included a new kernel.
    [root@dev ~]# df -kh
    Filesystem      Size  Used Avail Use% Mounted on
    /dev/sda3       228G   22G  194G  11% /
    tmpfs           1.9G     0  1.9G   0% /dev/shm
    /dev/sda1        99M   53M   42M  57% /boot
    [root@dev ~]#

The end result will be that disk space for the /boot directory should always be under control. In my personal opinion the /boot directory should always be installed with more than 100MB of space so you can keep numerous older kernels or kernels for different tasks but many times you might take over administration of a server that is already configured and running.

Python file and DIRECTORY

import os
import os.path

PATH='./file.txt'

if os.path.isfile(PATH) and os.access(PATH, os.R_OK):
    print "File exists and is readable"
else:
    print "Either file is missing or is not readable"


import os
fname = "foo.txt"
if os.path.isfile(fname):
    print "file does exist at this time"
else:
    print "no such file"
  1. Try opening the file:Opening the file will always verify the existence of the file. You can make a function just like so:
    def File_Existence(filepath):
        f = open(filepath)
        return True 

    If it’s False, it will stop execution with an unhanded IOError or OSError in later versions of python. To catch the exception, you have to use a try except clause. Of course, you can always use a try except statement like so (Thanks to hsandt for making me think):

    def File_Existence(filepath):
        try:
            f = open(filepath)
        except IOError, OSError: # Note OSError is for later versions of python
            return False
    
        return True
  2. Use os.path.exists(path):This will check the existence of what you specify. However, it checks for files and directories so beware about how you use it.
    import os.path
    >>> os.path.exists("this/is/a/directory")
    True
    >>> os.path.exists("this/is/a/file.txt")
    True
    >>> os.path.exists("not/a/directory")
    False
  3. Use os.access(path, mode):This will check whether you have access to the file. It will check for permissions. Based on the os.py documentation, typing in os.F_OK, will check the existence of the path. However, using this will create a security hole, as someone can attack your file using the time between checking the permissions and opening the file. You should instead go directly to opening the file instead of checking its permissions. (EAFP vs LBYP). If you’re not going to open the file afterwards, and only checking its existence, then you can use this.Anyways, here:
    >>> import os
    >>> os.access("/is/a/file.txt", os.F_OK)
    True
 


Directory 



import os
print(os.path.isdir("/home/el"))
print(os.path.exists("/home/el/myfile.txt"))

os provides you with a lot of these capabilities:

import os
os.path.isdir(dir_in) #True/False: check if this is a directory
os.listdir(dir_in)    #gets you a list of all files and directories under dir_in
 
 

Make directory on python 

import os

dirname = 'create/me'

try:
    os.makedirs(dirname)
except OSError:
    if os.path.exists(dirname):
        # We are nearly safe
        pass
    else:
        # There was an error on creation, so make sure we know about it
        raise
 

How To Check If A File Exists

If you find yourself doing any kind of disk-based I/O with Python, you’ll undoubtedly come across the need to verify that a file exists before continuing to read/write against it. There are multiple ways to do this but also some things you should watch for.

You may initially discover the os.path.exists() method, but keep in mind that this will yield True for both files and directories. This lack of specificity could easily introduce bugs and data loss if not expected.

#Returns true for directories, not just files
>>> print os.path.exists('/this/is/a/dir')
True

If you want to zero-in on just files, stick to os.path.isfile() method. Remember that something could happen to a file in the time between checking that it exists and actually preforming read/write operations against it. This approach will not lock the file in any way and therefore your code can become vulnerable to “time of check to time of use” (TOCTTOU) bugs.

#Returns true for directories, not just files
if os.path.isfile('my_settings.dat'):
    #...
    with open('my_settings.dat') as file:
       pass  #Potential for unhandled exception
True

Yes, that’s a real thing. Wikipedia has an article on TOCTTOU bugs, along with an example of how symlinks can be used by an attacker. I encourage you to read it.

Raising exceptions is considered to be an acceptable, and Pythonic, approach for flow control in your program. Consider handling missing files with IOErrors, rather than if statements. In this situation, an IOError exception will be raised if the file exists but the user does not have read permissions.

try:
    with open('my_settings.dat') as file:
        pass
except IOError as e:
    print "Unable to open file" #Does not exist OR no read permissions

Check If a File Exists and Then Delete It in Python

 
#!/usr/bin/python
import os
 
## get input ##
filename=raw_input("Type file name to remove: ")
 
## delete only if file exists ##
if os.path.exists(filename):
    os.remove(filename)
else:
    print("Sorry, I can not remove %s file." % filename)

 

A Better Option To Delete A File In Python

The following code gives an error information when it can not delete the given file name:

 
#!/usr/bin/python
import os
 
## get input ##
filename=raw_input("Type file name to remove: ")
 
## check if a file exists on disk ##
## if exists, delete it else show message on screen ##
if os.path.exists(filename):
	try:
		os.remove(filename)
	except OSError, e:
		print ("Error: %s - %s." % (e.filename,e.strerror))
else:
	print("Sorry, I can not find %s file." % filename)

Sample outputs:

SFTP server on chroot

SFTP server
SFTP ( Secure File Transfer Protocol ) is used to encrypt connections between clients and the FTP server. It is highly recommended to use SFTP because data is transferred over encrypted connection using SSH-tunnel on port 22 .
Basically we need openssh-server package to enable SFTP .
Install openssh-server package, if its not already installed.

yum -y install openssh-server

Create a separate group for FTP access.

groupadd ftpaccess

Now open /etc/ssh/sshd_config file and make changes as below.
Find and comment the below line ( Line no : 147 ).

#Subsystem sftp /usr/libexec/openssh/sftp-server
and add these lines below.
Subsystem sftp internal-sftp
Match group ftpaccess
ChrootDirectory %h
X11Forwarding no
AllowTcpForwarding no
ForceCommand internal-sftp

Step 9 » Now restart sshd service.
[root@krizna ~]# systemctl restart sshd
Now your SFTP server is configured and ready .

User creation
Create user jack with /sbin/nologin shell and ftpaccess group

useradd -m mohan -s /sbin/nologin -g ftpaccess
passwd mohan

Now assign root ownership for the home directory for chroot access and modify permission.
chown root /home/mohan
chmod 750 /home/mohan
Create a directory www inside home directory for writing and modify ownership .

mkdir /home/mohan/uploaded
chown mohan:ftpaccess /home/jack/uploaded

Now mohan can use both ftp and sftp services . He can upload files in www directory .

Setup ftp server centos 7
If you are going to use FTP and SFTP together in the same server, you should follow above steps while creating users . For existing users add them to ftpaccess and make below changes.

usermod test -g ftpaccess
chown root /home/test
chmod 750 /home/test
mkdir /home/test/www
chown test:ftpaccess /home/test/www

Have a nice day.

Setup FTP server on centos 7

yum -y install vsftpd

After installation you can find /etc/vsftpd/vsftpd.conf file which is the main configuration file for VSFTP.
Take a backup copy before making changes .

cp /etc/vsftpd/vsftpd.conf /etc/vsftpd/vsftpd.conf.org

vi /etc/vsftpd/vsftpd.conf

Find this line anonymous_enable=YES ( Line no : 12 ) and change value to NO to disable anonymous FTP access.

anonymous_enable=NO

Uncomment the below line ( Line no : 100 ) to restrict users to their home directory.
chroot_local_user=YES

and add the below lines at the end of the file to enable passive mode and allow chroot writable.
allow_writeable_chroot=YES
pasv_enable=Yes
pasv_min_port=40000
pasv_max_port=40100

Now restart vsftpd service and make it start automatically after reboot.

systemctl restart vsftpd.service

systemctl enable vsftpd.service

Add FTP service in firewall to allow ftp ports .

firewall-cmd –permanent –add-service=ftp
firewall-cmd –reload

Setup SEinux to allow ftp access to the users home directories
setsebool -P ftp_home_dir on

Now create an User for ftp access. Here /sbin/nologin shell is used to prevent shell access to the server .

useradd -m mohan -s /sbin/nologin
passwd mohan