Search This Blog

Showing posts with label Vagrant. Show all posts
Showing posts with label Vagrant. Show all posts

Saturday, 16 April 2016

Learn How to setup personal lab for WebLogic 12c Administration

In this page you will be learning the following

  • Download software list for WebLogic Administration course
  • How to prepare my system as Learning Lab?
    • Virtualization with Vagrant setup for WebLogic
    • Learn How to use Vagrant Ubuntu precise 64 box configuration
    • Troubleshooting with Vagrant 5.1.2  for Ubuntu Precise 64
  • How to create groups and users for WebLogic or FMW environments?
Learn How to setup personal lab for WebLogic 12c Administration

Download software list for WebLogic 12c Administration course

  1. Oracle VirtualBox http://download.virtualbox.org/virtualbox
  2. PuTTY http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html
  3. MobaXterm http://mobaxterm.mobatek.net/download-home-edition.html
  4. WinScp (FTP Tool) http://winscp.net/eng/download.php
  5. Oracle JDK http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
  6. Oracle WebLogic http://www.oracle.com/technetwork/middleware/fusion-middleware/downloads/index.html
  7. Notepad++ http://notepad-plus-plus.org/download/v6.7.7.html
  8. Oracle XE Database http://www.oracle.com/technetwork/database/enterprise-edition/downloads/index.html
  9. Oracle SQL Developer http://www.oracle.com/technetwork/developer-tools/sql-developer/overview/index.html
  10. Open LDAP http://www.openldap.org/software/download/
  11. LDAP Browser http://www.ldapadministrator.com/download.htm
  12. Apache HTTP Server http://httpd.apache.org/download.cgi
  13. Open SSL https://www.openssl.org/source/
  14. Thread Logic https://java.net/projects/threadlogic/downloads
  15. Thread dump analyser http://samuraism.jp/samurai/en/index.html.
  16. Ubuntu 14 [optional]  http://www.ubuntu.com/download/desktop
  17. GC Viewer https://github.com/chewiebug/GCViewer/wiki

Vagrant setup for WebLogic

Install Virtual Box - For download and installation instructions visit https://www.virtualbox.org Install Vagrant Install Vagrant - For download and installation instruction visit http://www.vagrantup.com/ Create a directory name it as workspace_wls for the Vagrantfile. In a terminal/command window, navigate to that directory. Before we can kick start your VM, we need to make the follow changes.

All the boxes which are downloaded from the http://www.vagrantbox.es consist of default ssh user as vagrant and root both have password as vagrant. Now let’s tell the Vagrant that we want to use the OS username called "oracle". Add the following to the Vagrantfile before the "config.vm.box" line
vagrant box add {title} {url}
vagrant init {title}
Here you can select any Linux flavor box which are pre-built boxes. Less in size and low consumption of CPU, MEM resources.
  config.ssh.username = "oracle"  
  config.ssh.password = "Welcome1"

Tell Vagrant that we want the VM to boot in GUI mode and that we want it to be allocated 4Gb RAM. Add the following to the Vagrantfile after the "config.vm.box" line

 config.vm.provider :virtualbox do |vb|
    vb.gui = true
    vb.customize ["modifyvm", :id, "--memory", "4096"]
    vb.customize ["modifyvm", :id, "--cpus", "2"]
  end

The Vagrantfile should now look like the following

# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure(2) do |config|
  config.ssh.username = "oracle"  
  config.ssh.password = "Welcome1"
  config.vm.box = "oel6u4-64bits.box"
  config.vm.synced_folder "C:/OFMW", "/u01/software",owner: "oracle", group: "oracle",  create: "true"
  config.vm.synced_folder "C:/OFMW/app","/u01/app/oracle", owner: "oracle", group: "oracle", create:true 
  config.vm.network :private_network, ip: "192.168.33.105"
  
  config.vm.provider :virtualbox do |vb|
    vb.gui = true
    vb.customize ["modifyvm", :id, "--memory", "4096"]
    vb.customize ["modifyvm", :id, "--cpus", "2"]
  end
end

in command window you could run the’ vagrant up’ if already running need to update few configurations that changed in the Vagrantfile then use ‘vagrant reload’, this will forceful shutdown the vm and then start the virtualbox.


Ubuntu Precise 32 contains the Vagrantfile as you have many box options select as per you Laptop or desktop capabilities:

# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure(2) do |config|
  config.vm.box = "precise32"
  config.vm.box_url="http://files.vagrantup.com/precise32.box"
  config.vm.synced_folder "C:/OFMW","/vagrant_data/", create:true
  config.vm.network :private_network, ip: "192.168.33.104"
  config.vm.provider "virtualbox" do |vb|
    vb.gui = true
    vb.customize ["modifyvm", :id, "--memory", "4092"]
    vb.customize ["modifyvm", :id, "--cpus", "2"]
  end  
  #config.vm.provision :shell, :path => "setup.sh"
 end


Vagrant Ubuntu precise 64 box configuration


Now latest laptops all working with 64 bit only, So for you...
Vagrant.configure(2) do |config|
  config.vm.box = "hashicorp/precise64"
  #config.vm.box_url="http://files.vagrantup.com/precise64.box"
  config.vm.boot_timeout=600
  config.vm.host_name = "mydev.vybhava.com"
  config.vm.network "private_network", ip: "192.168.33.100"

  config.vm.synced_folder "F:/Softwares", "/u01/app/software"
  config.vm.provider "virtualbox" do |vb|
   #vb.gui = true
   vb.memory = "4096"
  end
end

Vagrant boxes are small in sizes and easy to use, flexible, disposable any time you can destroy them. Here some of the vagrant commands that are initially used when you began using it.

vagrant up


On Windows platform vagrant up runs precise64 box

Login to the vagrant box To work with static IP we need private_network must be working. On Mac OSX.
vagrant ssh
On Windows use PuTTY using 127.0.0.1 and port 2222.
Vagrant ssh connecting precise64 box

Troubleshooting with Vagrant 5.1.2  for Ubuntu Precise64

Switch to root user
sudo -i

Now edit the following in the  /etc/os-release with the below given lines:
vi /etc/os-release
 

NAME="Ubuntu"
VERSION="14.04 LTS, Precise Pangolin"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu precise (14.04 LTS)"
VERSION_ID="14.04"

This would resolve your network adapter creation errors on both Mac OSX and also on Windows hosts having guest as precise64 boxes.

Connect Vagrant Ubutnu box with PuTTY


The private network that is configured in the vagrantfile will give the static IP configuration.

Save the IP for Vagrant Ubuntu box

If you wish to use the same box for the Oracle SOA then you need to increase RAM size and reload the box.

Preferable Load the saved session  PuTTY settings are:
  1. Window -> Line of Scrollback 2000 change to 200000
  2. Appearance -> Font Lucida Sans Typewriter 14/12 point
  3. Colour ->Check Use System colours
  4. Session -> Save
Hope you enjoyed this settings.

How to create groups and users for WebLogic or FMW environments?

Lets create Oracle recommended groups oinstall, dba
groupadd -g 501 oinstall
groupadd -g 502 dba

Now we can go for creating the user name as : oracle. Change the passwd for the user using passwd:
https://github.com/mitchellh/vagrant/issues/6426
useradd -u 502 -g oinstall -G dba oracle
passwd oracle
Create a home directory and give full access and ownership to the standard directory /u01/app/oracle.
mkdir -p /u01/app/oracle

chown -R oracle:oinstall /u01
chmod -R 775 /u01

Finally assign that directory as home director for oracle user.
 usermod -d /u01/app/oracle oracle
Lets make simple script "vi createUser.sh" that you can run as super user that is root user.
#!/bin/bash
# Run this script with root user

echo "Create the new groups and users."

groupadd -g 501 oinstall
groupadd -g 502 dba

useradd -u 502 -g oinstall -G dba -s /bin/bash oracle
passwd oracle

mkdir -p /u01/app/oracle

chown -R oracle:oinstall /u01
chmod -R 775 /u01

usermod -d /u01/app/oracle oracle

echo "User oracle created successfully..."
Now change mode and execute the script:
chmod +x createUser.sh

./createUser.sh 

Friday, 21 August 2015

JDBC Datasource creation on Precise Ubuntu box using Vagrant Oracle XE

Preparation 
  • Download Ubuntu-Vagrant-Oracle-xe
  • Modify the Vagrantfile
The major changes in the vagrangfile are Oracle XE on Vagrant Ubuntu box
  • Memory size 1024MB 
  • Select the hostonly network adapter with a private IP. 
 The vagrant file:

# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure("2") do |config|
  config.vm.box = "precise64"
  config.vm.box_url = "http://files.vagrantup.com/precise64.box"
  config.vm.hostname = "oracle.vybhava.com"
  config.vm.synced_folder ".", "/home/vagrant/vagrant-ubuntu-oracle-xe", :mount_options => ["dmode=777","fmode=666"]
  config.vm.network "private_network", ip: "192.168.33.105"
  config.vm.network :forwarded_port, guest: 1521, host: 1521

  config.vm.provider :virtualbox do |vb|
    vb.customize ["modifyvm", :id,
                  "--name", "oracle",
                  # Oracle claims to need 512MB of memory available minimum
                  "--memory", "1024",
                  # Enable DNS behind NAT
                  "--natdnshostresolver1", "on"]
  end

  config.vm.provision :shell, :inline => "echo \"America/New_York\" | sudo tee /etc/timezone && dpkg-reconfigure --frontend noninteractive tzdata"
  config.vbguest.auto_update = false
  ....
... # remain code as it is no changes
end

Configure DataSource on WebLogic administration console

Step-by-Step JDBC Datasource creation process is as follows
  1. login to your WebLogic domain and navigate to the domain structure section select datasource
1. Select Datasource in the work area select New button

1.a Select Generic Data source

2. Enter JDBC Datasource properties : name, JNDI name, Database type

3. Select Database driver

4.XA driver selection nothing to select in the transaction



5. Connection pool parameters

6.a. Connection pool Test confirmation

6.c. Test Configuration Message - Succeeded

7. Target the data source to Cluster for HA

8. Completion of Datasource configuration

Sample Java program to validate the datasource given below:

package vybhava.technologies.jdbc;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Hashtable;
import javax.naming.Context;
import javax.naming.InitialContext;

/**
 * This example demonstrates obtaining a database connection using a
 * DataSource object.
 * Create a DataSource using any DB name it as myDs and its JNDI as jdbc/myDs
 * To compile:  javac -d . SimpleSql.java
 * Execute : java vybhava.technologies.jdbc.SimpleSql
 */
public class SimpleSql {

  public static void main(String argv[])
      throws Exception {

    java.sql.Connection conn = null;
    java.sql.Statement stmt = null;
    ResultSet rs = null;

    try {

      // ============== Get a database connection ==================

      Context ctx = null;

      // Put connection properties in to a hashtable.
      Hashtable ht = new Hashtable();
      ht.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
      ht.put(Context.PROVIDER_URL, "t3://192.168.33.104:7011,192.168.33.104:7012");

      // Get a context for the JNDI lookup
      ctx = new InitialContext(ht);
      // Look up the data source
      javax.sql.DataSource ds = (javax.sql.DataSource) ctx.lookup("jdbc/myDs1");
      //Get a database connection from the data source
      conn = ds.getConnection();
      conn.setAutoCommit(true);

      System.out.println("Making connection...\n");

      // ============== Execute SQL statements ======================
      stmt = conn.createStatement();

      try {
        stmt.execute("drop table empdemo");
        System.out.println("Table empdemo dropped.");
      } catch (SQLException e) {
        System.out.println("Table empdemo doesn't need to be dropped.");
      }

      stmt.execute("create table empdemo (empid int, name varchar(30), dept int)");
      System.out.println("Table empdemo created.");

      int numrows = stmt.executeUpdate("insert into empdemo values (0, 'John Smith', 12)");
   numrows = stmt.executeUpdate("insert into empdemo values (1, 'Pavan Devarakonda', 12)");
   numrows = stmt.executeUpdate("insert into empdemo values (2, 'Suresh', 13)");
      System.out.println("Number of rows inserted = " + numrows);

      stmt.execute("select * from empdemo");

      rs = stmt.getResultSet();
      System.out.println("Querying data...");
      while (rs.next()) {
        System.out.println("  ID: " + rs.getString("empid") +
            "\n  Name: " + rs.getString("name") +
            "\n  Dept: " + rs.getString("dept"));
      }

      numrows = stmt.executeUpdate("delete from empdemo where empid = 0");
      System.out.println("Number of rows deleted = " + numrows);
    } catch (Exception e) {
      System.out.println("Exception was thrown: " + e.getMessage());
    } finally {
   // ========== Close JDBC objects, including the connection ======= 
      try {
        if (stmt != null) {
          stmt.close();
          stmt = null;
        }
      } catch (SQLException e) {
        throw e;
      } finally {
        try {
          if (conn != null) {
            conn.close();
            conn = null;
          }
        } catch (SQLException e) {
          throw e;
        }
      }
    }
  }
}
 Finally you need to compile the above program and execute that. You can see the commands in the comments.

JDBC Datasource validating  with SimpleSql.java compile and execution

WebLogic Books

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

Popular Posts