Friday 30 October 2015

JBOSS EAP 6 BASICS



JBoss EAP 6 provides two operating modes for JBoss EAP 6 instances: standalone server or
managed domain.
The two modes differ in how servers are managed, not in their capacity to service end-user requests. It is important to note that the high-availability (HA) cluster functionality is available via either operating mode. A group of standalone servers can be configured to form an HA cluster.

1.About Standalone Servers
Standalone server mode is an independent process and is analogous to the only running mode available in previous JBoss EAP versions.
A JBoss EAP 6 instance running as a standalone server is a single instance only but can optionally run in a clustered configuration.

2.  About Managed Domains
The managed domain operating mode allows for management of multiple JBoss EAP 6 instances from a single control point. Centrally managed JBoss EAP 6 server collections are known as members of a domain. All JBoss EAP 6 instances in a domain share a common management policy.

A domain consists of one domain controller, one or more host controller(s), and zero or more server groups per host.

A domain controller is the central point from which the domain is controlled. It ensures that each server is configured according to the management policy of the domain. The domain controller is also a host controller. One host controller instance is configured to act as a domain controller.

By default, the central management policy is stored in the domain/configuration/domain. xml file. This is the main configuration file for a managed domain. Only the domain master reads this file. On other domain members, it can be removed.

The host controller interacts with the domain controller to help manage the communication between the servers and the domain controller and control the lifecycle of the application server instances running on its host and to assist the domain controller to manage them.  

Multiple host controllers of a domain can interact with only a single domain controller. Hence, all the host controllers and server instances running on a single domain mode have a single domain controller and must belong to the same domain.

By default each host controller reads its configuration from the domain/configuration/host.xml file located in the unzipped JBoss EAP 6 installation file on its host's filesystem. The host.xml file contains the following configuration information that is specific to the particular host:

  • How the host controller contacts the domain controller to register itself and access the domain configuration.
  • How to find and contact a remote domain controller.
  • That the host controller is to act as the domain controller


A server group is a set of server instances which have JBoss EAP 6 installed on them and are managed and configured as one. The domain controller manages the configuration of and applications deployed onto server groups. Consequently, each server in a server group shares the same configuration and deployments.
Each server group needs a unique name and a reference to one profile of the domain configuration

The server instances are independent from the domain controller and started by Process Controller. These are application server instance.

Every server instance(Application servers) of a domain belongs to a virtual server group. The idea is, that all servers of the same server group, perform the same tasks. When you deploy an application you will not deploy it to a server, you will deploy it to a whole server group. It is also possible to mange different server groups in one domain, e.g. production, staging or a test sever group.

The controller and the server instances of each host are separate JVM processes, which will be monitored by a process controller. The process controller is also a separate JVM process that is responsible for spawning the other processes and monitoring their lifecycle. If, the host controller process crashed, the process controller will start up the host controller (If you kill host controller, process control will start it again.) and each server that is configured with the auto-start parameter. However, if the server process of a server instance is terminated unexpectedly, the process controller will not restart the server instance automatically.


If the domain controller crashes, the host controller and server instances will be still available. Only the management and configuration of the server is not possible at this time. The host controller tried in a certain interval a re-connect. After the domain controller is available, the host controller establishes a new connection.

What happens when a JBoss server starts in domain mode?

JBoss goes through a few steps to load the right configuration. There are three components at work:

1. process controller,
2. host controller
3. domain controller.

The process controller is responsible for starting other processes and monitoring them. The host controller is responsible for managing configuration on the physical host and making sure the correct server instances are started by the process controller and the domain controller is responsible for holding the domain configuration.

When JBoss is started in domain mode, by calling either domain.bat or domain.sh, the following steps are performed:

1. The Process Controller (PC) is started in its own JVM(separate process)
2. The PC starts the Host Controller (HC) in a separate JVM
3. The HC parses the host.xml to see if this host is the Domain Controller (DC)

If this host is the DC:
            The local domain.xml and local host.xml settings are combined to make a single configuration for the machine.

If this host is not the DC:
            The HC tries to connect to the DC and combines the remote domain.xml with the local host.xml to make a single configuration for the machine.

4.Each server instance defined in the host.xml (if any) is started in its own JVM.





Sunday 25 October 2015

Create Oracle DataSource And Install Oracle JDBC Driver in JBoss EAP6

1.Install a JDBC Driver


Before your application can connect to a JDBC datasource, your datasource vendor's JDBC drivers(ojdbc6.jar) need to be installed in a location where JBoss EAP 6 can use them. JBoss EAP 6 allows you to deploy these drivers like any other deployment.

I am going to deploy jdbc jar file via CLI

jdbc:oracle:thin@//192.168.1.12:1521/orcl
[jbossas@middleware bin]$ ./jboss-cli.sh --connect --controller=192.168.1.12:9999

[domain@192.168.1.12:9999 /] deploy /u01/app/oracle/product/11.1.0/db_1/jdbc/lib/ojdbc6.jar --server-groups=GB_server_group


Check jdbc jar file installed or not in admin console


Creating a DataSource from JBoss EAP Admin Console

1. Login to the Management Console.

   a. Select the Profiles tab from the top of the console
  • ·         Select the appropriate profile from the drop-down box in the top left.
  • ·         Expand the Subsystems menu on the left of the console.
  • ·         Select Connector → Datasources from the menu on the left of the console





Enter the new datasource attributes in the Create Datasource wizard and proceed with the Next button.

Select JDBC driver, which is already deployed. and click next button.
Enter the connection settings in the Create Datasource wizard and select the Done button.

And finally enable the datasource


The  datasource has been added to the server. It is now visible in either domain.xml file,

fallowing content has been added in the domain.xml

<datasource jta="false" jndi-name="java:/jdbc/GB_DATASOURCE" pool-name="GB_DATASOURCE" enabled="true" use-ccm="false">
                        <connection-url>jdbc:oracle:thin@//192.168.1.12:1521/orcl</connection-url>
                        <driver-class>oracle.jdbc.OracleDriver</driver-class>
                        <driver>ojdbc6.jar</driver>
                        <security>
                            <user-name>scott</user-name>
                            <password>tiger</password>
                        </security>
                        <validation>
                            <validate-on-match>false</validate-on-match>
                            <background-validation>false</background-validation>
                        </validation>
                        <statement>
                            <share-prepared-statements>false</share-prepared-statements>
                        </statement>
                    </datasource>


Management CLI

1. Launch the CLI tool and connect to your server.

2. Run the following command to create a non-XA datasource, configuring the variables as appropriate:

[domain@192.168.1.12:9999 /] data-source add --profile=full --name=KR_datasource --jndi-name=java:/jdbc/KR_DATASOURCE --driver-name=ojdbc6.jar --connection-url=jdbc:oracle:thin@//192.168.1.12:1521/orcl


3. Enable the datasource:

[domain@192.168.1.12:9999 /] data-source enable  --profile=full --name=KR_datasource

Check in admin console



Saturday 24 October 2015

Management Command Line Interface (CLI)

Use the Management CLI to start and stop servers, deploy and undeploy applications, configure system settings, and perform other administrative tasks.

 Launch the Management CLI

Run the EAP_HOME/bin/jboss-cli.sh file by entering the following at a command line:
$ EAP_HOME/bin/jboss-cli.sh

Quit the Management CLI

From the Management CLI, enter the quit command:
[domain@localhost:9999 /] quit

Connect the CLI to the Domain controller with the following operations:

[jbossas@middleware bin]$ ./jboss-cli.sh --connect --controller=192.168.1.12:9999

check domain controller status

[domain@192.168.1.12:9999 /] /host=master:read-attribute(name=server-state)
{
    "outcome" => "success",
    "result" => running
}

The server is in state running. That means the server is up and running without any outstanding configuration changes. Other states are starting, reload-required, restart-required, and stopping.

The state reload-required indicates that the server is running but a reload of all services is required in order to apply configuration changes.

The CLI operation :reload forces the server to shutdown and start again all services. The JVM itself will be not restarted.

The state restart-required means that a JVM restart is required to apply the configuration changes.

Slave(Host controller) status

[domain@192.168.1.12:9999 /] /host=slave01:read-attribute(name=server-state)
{
    "outcome" => "success",
    "result" => running
}

Restart the DC

[domain@192.168.1.12:9999 /] /host=master:shutdown(restart=true)
{
"outcome" => "success"
}

Stop Host controller (Slave)

[domain@192.168.1.12:9999 /] /host=slave01:shutdown
{
    "outcome" => "success",
    "result" => undefined
}

Stop specific application server on Host controller


[domain@192.168.1.12:9999 /] /host=slave01/server-config=GB_SERVER01:stop(server=true)
{
    "outcome" => "success",
    "result" => "STOPPING"
}

check specific application server on Host controller

[domain@192.168.1.12:9999 /] /host=slave01/server-config=GB_SERVER01:read-attribute(name=status)
{
    "outcome" => "success",
    "result" => "STARTED"
}

Deploy an application in standalone server

[standalone@192.168.1.12:9999 /] deploy  /home/jbossas/Desktop/usg.war

Undeploy an applicaiton in standalone server



[standalone@192.168.1.12:9999 /] undeploy usg.war

Disable the application but without removing it

 [standalone@192.168.1.12:9999 /] undeploy usg.war --keep-content

Enable the already deployed application

[standalone@192.168.1.12:9999 /]deploy –name=usg.war


If you want to deploy an application but do not want to enabled then you can use the below command

[standalone@192.168.1.12:9999 /] deploy  /home/jbossas/Desktop/usg.war --disabled

Deploy an application on Domain

Deploy an application to all server groups

[domain@192.168.1.12:9999 /] deploy  /home/jbossas/Desktop/usg.war --all-server-groups

Deploy an application on particular server group


[domain@192.168.1.12:9999 /] deploy /home/jbossas/Desktop/usg.war --server-groups=GB_server_group

Undeploy an application from all server groups

[domain@192.168.1.12:9999 /] undeploy usg.war --all-relevant-server-groups


Undeploy from a particular server group

[domain@192.168.1.12:9999 /] undeploy usg.war --server-groups=main-server-group --keep-content


Deploy the same application to other server group

Now if the application is already been deployed to one server group and you want it to deploy the same application on the other server group you can do it using the below command.


[domain@192.168.1.12:9999 /] deploy --name=usg.war --server-groups=main-server-group



Deploy an application which is disabled

If you want to deploy an application but do not want to enabled then you can use the below command


[domain@192.168.1.12:9999 /]deploy  /home/jbossas/Desktop/usg.war –disabled


[domain@192.168.1.12:9999 /] deploy /home/jbossas/Desktop/usg.war --server-groups=GB_server_group

'usg.war' already exists in the deployment repository (use --force to replace the existing content in the repository).


Note that a successful deploy does not produce any output to the CLI.

Stop all servers in server group
[domain@192.168.1.12:9999 /] /server-group=GB_server_group:stop-servers

Start all servers in server group
[domain@192.168.1.12:9999 /] /server-group=GB_server_group:start-servers

Restart all servers in server group

[domain@192.168.1.12:9999 /] /server-group=GB_server_group:restart-servers

Check application server details ::

[domain@192.168.1.12:9999 /] /host=slave02/server-config=GB_server02:read-resource(include-runtime=true)
{
    "outcome" => "success",
    "result" => {
        "auto-start" => true,
        "cpu-affinity" => undefined,
        "group" => "GB_server_group",
        "name" => "GB_server02",
        "priority" => undefined,
        "socket-binding-group" => "full-sockets",
        "socket-binding-port-offset" => 50,
        "status" => "STARTED",
        "interface" => undefined,
        "jvm" => undefined,
        "path" => undefined,
        "system-property" => undefined
    }
}

JVM Metrics

By default every JVM process expose some MBeans with information about the JVM and the environment. The MBeans with the ObjectName java.lang:type=* are also accessible via the CLI. The following CLI command is an example to get information about the memory usage.

[domain@192.168.1.12:9999 /] /host=slave02/core-service=platform-mbean/type=memory:read-attribute(name=heap-memory-usage)
{
    "outcome" => "success",
    "result" => {
        "init" => 67108864L,
        "used" => 27134640L,
        "committed" => 64880640L,
        "max" => 518979584L
    }
}

If you are not so familiar with the CLI syntax, the CLI provides a GUI. The GUI of the CLI can be started with the following command:
[jbossas@middleware bin]$ ./jboss-cli.sh --connect --controller=192.168.1.12:9999 --gui


Friday 23 October 2015

Configuring a JBOSS as Domain

In this tutorial we will show all the steps to configure a JBOSS as Domain on one physical server(Machine).

The domain controller must be started before any slave servers in any server groups in the domain. Use this procedure first on the domain controller, and then on each associated host controller and each other host associated with the domain.


I am going to configure domain as below Architecture. 

I am going to configure  domain controller (DC) and two Host controllers (HC) on same machine so first need to copy configuration directory from /EAP_HOME/domain/ to other locations.

Here I have created three directories as below in /u02/local/opt/mydomain/ and copied configuration directory  from /EAP_HOME/domain/.

master, slave01, slove02

1.Configure the Domain

a. If you want make your server accessible to outside world, you need to define a property named jboss.bind.address.management  in host-master.xml file (This file located in configuration directory)

<interfaces>
        <interface name="management">
            <inet-address value="${jboss.bind.address.management:192.168.1.12}"/>
        </interface>
    </interfaces>

b. Configure the Host Name Using a System Property

<host name="master" xmlns="urn:jboss:domain:1.6">

Now we can start the domain controller with the following command.

[jbossas@middleware bin]$ pwd
/u02/local/opt/jboss-eap-6.2/bin

[jbossas@middleware bin]$./domain.sh -Djboss.domain.base.dir=/u02/local/opt/mydomain/master --host-config=host-master.xml

Admin console listening on http://192.168.1.12:9990/console


2.Configure the slave 01

a. Configure the Host Name Using a System Property in host-slave.xml (This file located in /Slave01_home/configuration directory)

<host name="slave01" xmlns="urn:jboss:domain:1.5">

b. Need to change jboss.management.native.port number, because DC using same port number. (If you are running slave on diff machine then no need to change this port number)

management-interfaces>
            <native-interface security-realm="ManagementRealm">
                <socket interface="management" port="${jboss.management.native.port:19999}"/>
            </native-interface>
        </management-interfaces>


Now we can start the Host controller (Slave 01)with the following command.

[jbossas@middleware bin]$./domain.sh -Djboss.domain.base.dir=/u02/local/opt/mydomain/slave01/ --host-config=host-slave.xml -Djboss.domain.master.address=192.168.1.12


Once slave01 successfully started , check in admin console either slave01 connected to master or not. 




during the slave starting time some files/directories created in
slave home directory.

[jbossas@middleware slave01]$ pwd
/u02/local/opt/mydomain/slave01
[jbossas@middleware slave01]$ ls -ltr
total 20
drwxr-xr-x 2 jbossas was 4096 Oct 23 01:07 log
drwxr-xr-x 3 jbossas was 4096 Oct 23 01:07 data
drwxr-xr-x 3 jbossas was 4096 Oct 23 01:07 tmp
drwxr-xr-x 4 jbossas was 4096 Oct 23 01:07 servers
drwxrwxr-x 3 jbossas was 4096 Oct 23 01:07 configuration

3.configure  slave 02

a. Configure the Host Name Using a System Property in host-slave.xml (This file located in /u02/local/opt/mydomain/slave02/configuration directory)

<host name="slave02" xmlns="urn:jboss:domain:1.5">

b. Need to change jboss.management.native.port number, because DC using same port number. (If you are running slave on diff machine then no need to change this port number)

management-interfaces>
            <native-interface security-realm="ManagementRealm">
                <socket interface="management" port="${jboss.management.native.port:29999}"/>
            </native-interface>


Now we can start the Host controller (Slave 02)with the following command.

./domain.sh -Djboss.domain.base.dir=/u02/local/opt/mydomain/slave02/ --host-config=host-slave.xml -Djboss.domain.master.address=192.168.1.12

Once slave02 successfully started , check in admin console either slave02 connected to master or not.







If already master address present in host-slave.xml file, then no need to give master address in HC start command.  

host-slave.xml

<domain-controller>
       <remote host="192.168.1.12" port="${jboss.domain.master.port:9999}" security-realm="ManagementRealm"/>
    </domain-controller>

Then run below cmd.


./domain.sh -Djboss.domain.base.dir=/u02/local/opt/mydomain/slave02/ --host-config=host-slave.xml