Search This Blog

Saturday 19 December 2015

Tuning the Memory Arguments for WebLogic Managed server

Tuning the JVM Memory Arguments for WebLogic server instance. Here tuning means either increase or decrease the memory size of a JVM Heap or Perm Size. Remember that Heap, Perm spaces are combined to forms a Admin/managed server's MEM space.

Pr-requisites for this experiment:

  • WebLogic installed 
  • Domain Configuration
  • Admin, Managed servers Running State
There are 2 options to modify existing JVM Arguments
  1. SetDomainEnv.sh (or) .cmd
  2. Admin Console
1. Changing JVM Arguments through setDomainEnv.sh

Before changing JVM arguments from the terminal you can use jps or ps command  -Xms256m -Xmx512m

JVM arguments for AdminServer
Before changing the JVM arguments


JVM Memory size of AdminServer can be increased by changing Xmx and Xms values in setDomainEnv.sh or in the startWebLogic.sh as per the need. which are located in $MW_HOME/user_projects/domains/domain_name/bin$vi setDomainEnv.sh
JVM size of AdminServer using setDomainEnv.sh
Changing the JVM Arguments for the AdminServer from setDomainEnv.sh

Above script changed the value of Xms and Xmx of 32bit where my requirement relates to 32bit architecture OS to 512m and 1024m

These values can be determined within the performance domain where trial and error options will concludes at certain values.

After increasing JVM memory arguments restarts the AdminServer and then check the JVM arguments of the AdminServer by using the below command

ps -ef  |grep AdminServer.

Output:
Tuning theJVM memory arguments
After Increasing JVM memory arguments
2. Admin Console level MEM_ARGS sizing

Logon to WebLogic Admin Console and select the WebLgoic server instance for which you wish to modify. Except AdminServer. Lets modify for managed server managed_01
From the domain structure -> Environment -> Servers
In the work area Configuration tab select the server start tab & enter the new JVM arguments as per your project needs here for sample using :
-Xms1024m -Xmx1024m 
WebLogic 12c server instance default MEM Arguments (Before Tuning)



Change the Argument


MEM Arguments for Weblogic managed server


Now after change of the argument restart the server from the Admin console that using Nodemanger restart the server to get the changes

After Tuning the WebLogic server Memory Allocation





You can explore more on sizing Memory argument at Oracle documentation.



Sunday 29 November 2015

Threads, ThreadDump in WebLogic - TroubleShooting

Every WebLogic server is one process on the Operating System. Each Java process is going to have multiple Java Threads or Native Threads. The Native threads usage will be optimizing input and output operations between CPU and the system resources.

In many WebLogic/FMW admin interviews people asks the following

Difference between Server Hang, server Crash


In case of Server Hang the incoming requests keep on coming. Where as Server cannot accept the requests from the clients.

What is the meaning of WebLogic server hang?

Potential Causes of Server Hang
  • RMI, RJVM responses – all threads tied up waiting for RJVM, RMI responses
    Application Deadlock 
  • Threads  are all used up, none available for new work.Garbage Collection taking too much time
  • Long Running JDBC calls or JDBC deadlocks lead to a hang
  • JVM hang  during code optimization, may look like server hang
  • JSP compilation causes server hang under heavy load
  • JVM bugs 

Why does the WebLogic Server crash occurs?

When a WebLogic Server crash (or JVM crash, machine crash) an application gets a binary core file produced. The server crashes due to some invalid native code (machine specific code)
Troubleshooting Steps:
  • The WebLogic Server performance pack 
  • Any native libraries accessed with JNI calls 
  • The JVM itself JVM will produce a small log file hs_err_pid.log 
  • If there is a core file produced, run dbx or gdb debuggers on the core file, which will let us know what was the last thread processing


How to take the ThreadDump in WebLogic environment?


Using command line thread dump with kill command with -3 option will take the snapshot of what threads doing in a WebLogic server.

Install and Configure a mail service on Ubuntu

Install ssmtp

Step 1: We must use super previllages then Install ssmtp:

sudo apt-get install ssmtp

Step 2: Edit the ssmtp config file : vi /etc/ssmtp/ssmtp.conf Enter this inside the file:
root=username@gmail.com
mailhub=smtp.gmail.com:465
rewriteDomain=gmail.com
AuthUser=username
AuthPass=password
FromLineOverride=YES
UseTLS=YES

Step 3: Enter the email address of the person who will receive your email: Now enter this:
ssmtp recepient_name@gmail.com

To: recipient_name@gmail.com
From: username@gmail.com
Subject: Sent from a terminal!

Your content goes here. Lorem ipsum dolor sit amet, consectetur adipisicing.
(Notice the blank space between the subject and the body.)

To send the email: Ctrl + D

Send mail from ssmtp in Ubuntu box
SSMTP Error:
 Here I got the Authorization failed error

To resolve it I've used the following fix:
Log into your google email account and then go to this link: https://www.google.com/settings/security/lesssecureapps and set "Access for less secure apps" to ON. Test to see if your issue is resolved. Got It!! it works for me...

Sunday 22 November 2015

Apache HTTP Server proxy configuration with WebLogic

There are many HTTP servers which serves web requests. Apache HTTP server is one of the most widely used webserver in the IT. Different vendors providing HTTP servers but all of them originated from Apache web server only. Due to open source many contributors expanded it with more capabilities.

Apache HTTP server Proxy with WebLogic 12c

Architecture overview

Apache Proxy to WebLogic cluster

Download Apache HTTP Server


Select stable version of Web server which will give minimum guaranty to work as expected.

Install Apache HTTP Server


tar -xvf httpd-2.2.27.tar.gz
cd httpd-2.2.27/
./configure --prefix=/home/oracle/apache2.27
Apache HTTP Server Configuration Successful

Compile and Install the Apache binaries

Actually Apache HTTP server uses native C, C++ libraries to compile and the compilation utility is 'make' command. You need to run the 'make' command in the same same path where configure was ran.

make

Linking the LD_LIBRARY to HTTP Server ready to run this we can do with 'make install ' command.

make install

Apache Configuration

The HTTP server configuration is in the conf folder. It contains various sum directories. Once the installation completed you can define environment variable in the profile as :
export APACHE_HOME=/home/oracle/apache2.27
vi $APACHE_HOME/conf/httpd.conf

Apache Control

Start the Apache Web server
cd $APACHE_HOME/bin
 ./apachectl start 
 
Stop the Apache Web server
cd $APACHE_HOME/bin
 ./apachectl start 
 

Check the Apache HTTP Server working

Check Apache HTTP Server configuration Listen Port issue


Apache HTTP Server start failed when the port 80 used from non root user. 80 is reserved port in Linux OS for the web server that run as administrator.
make_sock error Fix: To over come you can use different port e.g: 8080. Modify this Listen port value in the httpd.conf file and start the web server. 
It Works!

Listen 8080

Confirmation of HTTP server accessability Open a web browser and test the following URL:

http://192.168.33.100:8080


Validation of Web Server access
Integrate Weblogic with Apache

Configure Apache HTTP Server Proxy plugin for WebLogic Server


Post 10g weblogic stopped providing the plugins along with the installation, you have to download them externally. You can download the web server plugins from the below location


http://www.oracle.com/technetwork/middleware/webtier/downloads/index-jsp-156711.html

or

Oracle - downloads - middleware - webtier - Accept the license agreement - plugin you want - Download

Once you download the plugins you will find the following files after extraction as shown below.


I am selecting Linux 64 as I am configuring it on Linux 64 bit machine, extract the Linux ZIP and go to the lib folder, you will find a plugin called mod_wl.so under lib as shown below.

copy the mod_wl.so plugin from the above location to $APACHE_HOME/modules

NOTE – The mod_wl.so file differs for different apache versions. Make sure that the name of the file you copied to modules is same in httpd.conf.(sometimes you might prefix it with
Now edit the httpd.conf file present under /home/vagrant/apache2.2/conf/httpd.conf

Add the below lines to the httpd.conf file and save it integrate your weblogic cluster with apache.


LoadModule weblogic_module /home/vagrant/apache2.2/modules/mod_wl.so


SetHandler weblogic-handler



WebLogicCluster localhost:7002,localhost:7003
Debug ON
WLLogFile /tmp/wlproxy.log
WLTempDir /tmp


You can replace the cluster with individual host, by replacing weblogicCluster with weblogic Host as shown below.

  WebLogicHost 192.168.33.100
  WebLogicPort 7001
  Debug ALL
  DebugConfigInfo ON
  WLLogFile /tmp/wl-proxy.log


Restart the apache to get the changed reflected.

go to /home/vagrant/apache2.2/bin and run the below command.

./apachectl restart


Deploy any web application that is .war/ear file to the weblogic cluster


Application deployment on WebLogic  Server

Test it by accessing thru Individual manged servers as shown below.

Application accessing with WebLogic server port

Now try accessing it thru Apache using 8080 port as shown below.

Application accessing with Apache Server port

  WebLogicHost 192.168.33.100
  WebLogicPort 7001
  Debug ALL
  DebugConfigInfo ON
  WLLogFile /tmp/wl-proxy.log


Restart the apache to get the changed reflected.

go to /home/vagrant/apache2.2/bin and run the below command.

./
./apachectl restart


Deploy any web application that is .war/ear file to the weblogic cluster


Application deployment on WebLogic  Server

Test it by accessing thru Individual manged servers as shown below.

Application accessing with WebLogic server port

Now try accessing it thru Apache using 8080 port as shown below.

Application accessing with Apache Server port

Thursday 19 November 2015

JMX Monitoring for WebLogic domain

Server State using JMX Program

Java Management Extension (JMX) programs are going to use three levels.
  1. Probe level
  2. Agent level
  3. Remote Connection level
 In the probe level we have Configuration MBean, Runtime MBean.

Every Managed server, Admin Server have the Agent level - MBean Server which connects with probe level

JMX Architectuer WebLogic Domain MBeans

Remote Connection level is the top level where RMI, HTTP, SOAP, SNMP protocols will help to provide monitoring capabilities.

Sample PrintServerState.java

The following program will illustrates about how to use the JMX for huge WebLogic Environments where number or managed servers in 100s or 1000s.


import java.io.IOException;
import java.net.MalformedURLException;
import java.util.Hashtable;
import javax.management.MBeanServerConnection;
import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;
import javax.management.remote.JMXConnector;
import javax.management.remote.JMXConnectorFactory;
import javax.management.remote.JMXServiceURL;
import javax.naming.Context;

public class PrintServerState {

   private static MBeanServerConnection connection;
   private static JMXConnector connector;
   private static final ObjectName service;

   // Initializing the object name for DomainRuntimeServiceMBean
   // so it can be used throughout the class.
   static {
      try {
         service = new ObjectName(
            "com.bea:Name=DomainRuntimeService,Type=weblogic.management.mbeanservers.domainruntime.DomainRuntimeServiceMBean");
      }catch (MalformedObjectNameException e) {
         throw new AssertionError(e.getMessage());
      }
   }

   /*
   * Initialize connection to the Domain Runtime MBean Server
   */
   public static void initConnection(String hostname, String portString, 
      String username, String password) throws IOException,
      MalformedURLException { 
      String protocol = "t3";
      Integer portInteger = Integer.valueOf(portString);
      int port = portInteger.intValue();
      String jndiroot = "/jndi/";
      String mserver = "weblogic.management.mbeanservers.domainruntime";
      JMXServiceURL serviceURL = new JMXServiceURL(protocol, hostname,
         port, jndiroot + mserver);
      Hashtable h = new Hashtable();
      h.put(Context.SECURITY_PRINCIPAL, username);
      h.put(Context.SECURITY_CREDENTIALS, password);
      h.put(JMXConnectorFactory.PROTOCOL_PROVIDER_PACKAGES,
         "weblogic.management.remote");
      connector = JMXConnectorFactory.connect(serviceURL, h);
      connection = connector.getMBeanServerConnection();
   }

   /* 
   * Print an array of ServerRuntimeMBeans.
   * This MBean is the root of the runtime MBean hierarchy, and
   * each server in the domain hosts its own instance.
   */
   public static ObjectName[] getServerRuntimes() throws Exception {
      return (ObjectName[]) connection.getAttribute(service,
         "ServerRuntimes");
   }

   /* 
   * Iterate through ServerRuntimeMBeans and get the name and state
   */
   public void printNameAndState() throws Exception {
      ObjectName[] serverRT = getServerRuntimes();
      System.out.println("got server runtimes");
      int length = (int) serverRT.length;
      for (int i = 0; i < length; i++) {
         String name = (String) connection.getAttribute(serverRT[i],
            "Name");
         String state = (String) connection.getAttribute(serverRT[i],
            "State");
         System.out.println("Server name: " + name + ".   Server state: "
            + state);
      }
   }

   public static void main(String[] args) throws Exception {
      String hostname = args[0];
      String portString = args[1];
      String username = args[2];
      String password = args[3];

      PrintServerState s = new PrintServerState();
      initConnection(hostname, portString, username, password);
      s.printNameAndState();
      connector.close();
   }
}

Compile the JMX program:

javac PrintServerState.java

Execution of the JMX program is as follows:
java PrintServerState 192.168.33.100 7001 weblogic welcome1

JMX WebLogic Program execution output

Monday 16 November 2015

Message Driven Bean (EJB 3.0) deployment

JMS Server, Module creation you can refer the previous posts.
This program requires the JMS Module configurations

Configuration of JMS Module for MDB
Sample JMS Module configuration for different types of JMS destinations

We can use any kind of JMS destinations in the MDB program. Here in the sample program we are going to use the Queue, where we will refer to its JNDI name is jms.test.TestQ1.

Create a Message Driven Bean (MDB) 3.0


This sample is for Admins and WebLogic based developers. Now open a editor and write the following Java code:

package ejb30;
import javax.ejb.MessageDriven;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.TextMessage;
import javax.ejb.ActivationConfigProperty;

@MessageDriven(
activationConfig = {
@ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue") ,
@ActivationConfigProperty(propertyName="connectionFactoryJndiName",propertyValue="jms.test.QCF"),
@ActivationConfigProperty(propertyName="destinationJndiName", propertyValue="jms.test.TestQ")
}
,mappedName="jms.test.TestQ"
)

public class MyMDB implements MessageListener
{
public void onMessage(Message message)
{
TextMessage textMessage = (TextMessage) message;
try {
System.out.println("nnt(mdb) MyMDB Received n"+ textMessage.getText());
}
catch (JMSException e)
{
e.printStackTrace();
}
}
}

Note: The ConnectionFactory, Queue JNDI names must match to your configured on the WebLogic admin console.

Compile the MDB Code

This is regular process of Java program compilation, -d option used to create the package directory, dot indicate current location path and a Java file.

javac -d . MyMDB.java

Generate MDB Jar

Now lets generate the artifact which we can deploy on WebLogic platform

jar   -cvf     mdb30.jar   ejb30     MyMDB.java

Deploying  MDB application on WebLogic

Goto your WebLogic admin console select deployments select install and select the path where the mdb30.jar file created. then do the deploy the artifact.

WebLogic Deployment for MDB
MDB Deployment on WebLogic Cluster


Running QueueSend

All set to go!! Execute the QueueSend program to send messages to the MDB, which is listening on the WebLogic cluster/server.

java jms.test.QueueSend t3://192.168.33.100:7011
 
QueueSend to MDB

MDB Listening

 tail -100f ms1.out
 

Finally you can see the received messages in the Managed server output log. That confirms JMS capabilities.

Friday 30 October 2015

3 ways to Create Weblogic 12c Domain



WebLogic Domain Creation procedures

Hey all, here we are going to know about the three ways to create a WebLogic Domain. Provided you must have WebLogic installed on your machine. In this article I'm using two different operating systems: Windows, Precise Ubuntu Linux. Most interesting thing here is multiple alternative ways. If one possibility is not working out you can try out with other option. Usually GUI mode domain creation is pretty simple but it need XWindows support in Llinux so it is applicable in the Windows environment. The precise Ubuntu which is plain vanilla Linux server for fare enough configuration on Linux platform. In such cases WLST would be perfect choice.


3 Ways to create to create Domain are:

  1. Configuration Wizard 
  2. Using Pack & UNPack 
  3. WLST 
Let’s get into brief about these 3 Domain Creation

  1. Using Configuration Wizard for WebLogic Domain
  2. The Configuration Wizard simplifies the process of creating or extending a domain. To create or extend a domain using the Configuration Wizard, you simply select the product components you want to include in your domain (or choose a template that best meets your requirements), and provide some basic configuration information. The Configuration Wizard then creates or extends the domain using the settings from the templates that contain the component functionality you specified Installation steps

    Step 1: Invoking Configuration Wizard from command prompt.

    cd $WL_HOME/common/bin
    config.sh
    

    Now, in Windows environment
    cd %WL_HOME%\common\bin
    config.cmd
    


    Step 2: Configuration Welcome screen !!

    Steop 3: Configuration Type existing or fresh domain creation?
    Step 4: Creating Domain using Product Template selects all templates by default, Actually this selection would be useful when we create a domain from custom domain template or specific business purpose we can use SOA, AIA, OSB etc type of extra templates.


    Step 5: Enter the Admin configuration details

    Step 6: In this windows of Domain Mode we have two options Development Mode & Production Mode based on your need select one among them I took Production mode here & select JDK


    Step 7: Advanced Configuration you have three options here Administration Server, Node Manager & Manager Servers, Clusters & Coherence, But my domain I selected only Administration Server.



    Step 8: Admin Server IP Address, Port number if you need you can select SSL Port. For me, not selecting.


    Step 9: Configuration Summary this is where you can review and if there is anything you wish to modify you can choose back and update them.


    Step 10: Configuration Progress


    Step 11: Configuration Success this confirms us everything went well!


  3. Using pack and unpack command
  4. The WebLogic provides this pack and unpack commands for two phase usage one is compressing the WebLogic Domain and on the other side (remote machine) uncompressed the domain. This feature can be used for various purposes
    • Backup of domains
    • Remote managed server configuration
    • Reusing Domain template for creating new environments

    Select your choice!

    Using Pack command

    Let me share my experiment here, I already created domain called Citydomain , our mission is running this domain in windows Machine first we need compress this Exiting Ctitydomain using pack command then we need to move or copy this jar file into shared folder then in windows machine we will run Unpack command in windows :
    pack.sh -domain=/home/vagrant/wlsdomains/Citydomain  \
    -template="/home/vagrant/wlsdomains/Citydomain.jar" -template_name="Citydomain.jar"
    
    
    Here I am using Citydomain as example I already created this domain using WLST Scripting this domain had save under home/vagrant/wlsdomains/Citydomain in following path here if you are using multiple lines we need to use \ (backward slash) at end if you want we can run this command in single line too at that time we need to remove this backward slash. Next line 2 -template="/home/vagrant/wlsdomains/Citydomain.jar" -template_name="Citydomain.jar" Here we are creating template Jar file of a WebLogic domain name - Citydomain and naming this Jar file as Citydomain.jar which is our outcome.

    Unpack Command

    cp /home/vagrant/wlsdomains/Citydomain.jar /vagrant_data
    
    We will run this Unpack command in windows for this first we need to copy this Citydomain.jar into shared folder(OFMW) this folder then we can un compress this Citydomain.jar using Unpack.cmd then that would create domain in windows machine
    unpack.cmd -template= E:/OFMW/Citydomain.jar -domain=E:/wlsdomains/Citydomain
    
    
    First
    Lets see the syntax ...
    Now lets run the unpack command ...

  5. Using WLST Script

WLST scripting is one of other way we can create new WebLogic domain in Windows or Linux platform. Here we are using simple python code in this script.
 

###########################################################
# This script will dynamically create the domain as per your inputs

###########################################################
import os
WLHOME=os.environ['WL_HOME']
#==========================================
# Create a domain from the weblogic domain template.
#==========================================
readTemplate(WLHOME+'/common/templates/wls/wls.jar')
cd('Servers/AdminServer')
AdminName=raw_input('Please Enter Admin ServerName: ')
set('Name',AdminName)
#==========================================
# Configure the Administration Server
#==========================================
AdminListenAdr=raw_input('Please Enter Admin Listen Address: ')
AdminListenPort=input('Please enter Admin listen Port: ')
set('ListenAddress',AdminListenAdr)
set('ListenPort', AdminListenPort)
#====================================================
# Define the password for user weblogic. You must define the password before you
# can write the domain.
#====================================================
cd('/')
cd('Security/base_domain/User/weblogic')
usr=raw_input('Please Enter AdminUser Name: ')
set('Name',usr)
AdminPassword=raw_input('Please enter Admin password:')
cmo.setPassword(AdminPassword)
# - OverwriteDomain: Overwrites domain, when saving, if one exists.
setOption('OverwriteDomain', 'true')
#==============================================
# Write the domain, close template and finally exit from the WLST
#==============================================
domainPath=raw_input('Enter the domain path: ')
domainName=raw_input('Enter domain name: ')
print 'Given domain path, name : ', domainPath, domainName
writeDomain(domainPath+"/"+domainName)
closeTemplate()
exit()


Above script is example for creating Domain using WLST Scripting we can copy this script use VI Editor to make new file & name the script

Here we are naming our script as py is the extension we are using because it’s Python code


We had used Interactive scripting here we need to enter details like Admin Server name, Listen Address Port number, Admin user Name, Admin Password & specify he path we were we need to create domain & finally domain name it take 10 to 15 minutes to create domain

You might be interested to see...

Tuesday 1 September 2015

Configuring JMS Distributed Queue

Create JMS module  - Click "New" button

Step 2: Name the module  and give descriptor -> Next

Step 3: Configure the Connection Factory for distributed destinations

Create a subdeployment for distributed destinations


ConnectionFactory configuration Confirmation

Create a Distributed Queue
 You can also select Distributed Topics as well as show above sample for Queue

Configuring Distributed Queue : Name, JNDIA, Uniform modified

Target the Distributed Queue on JMS servers

Confirmation screen of Distributed Queue
To do list:
Use the QueueSend.java, QueueReceive.java programs to validate the above configured distributed Queue is working with JNDI lookup and accessible.

Keep sharing this on FB or G+

WebLogic Books

  • Oracle WebLogic Server 12c: Administration Handbook
  • WebLogic Diagnostic Framework
  • Advanced WebLogic Server Automation
  • Oracle SOA Suite 11g Administrator's Handbook

Popular Posts