June 13, 2013

Configure High-Availability Clustering using TCP Unicast with JBoss EAP 6, HTTPD, mod_cluster on RHEL 6

In my previous blogs I have written about HA in JBoss EAP 6 with Apache Webserver (httpd) and that is all done with UDP multicast. In this blog I will show you how to do it with TCP unicast.

/etc/httpd/conf.d/mod_cluster.conf

# mod_proxy_balancer should be disabled when mod_cluster is used
LoadModule proxy_cluster_module modules/mod_proxy_cluster.so
LoadModule slotmem_module modules/mod_slotmem.so
LoadModule manager_module modules/mod_manager.so
LoadModule advertise_module modules/mod_advertise.so

MemManagerFile /var/cache/mod_cluster

<IfModule manager_module>
  #Listen 6666
  <VirtualHost *:80>

    KeepAliveTimeout 300
    MaxKeepAliveRequests 0
    EnableMCPMReceive on
    
    #ServerAdvertise on http://127.0.0.1:6666
    ServerAdvertise off
    AdvertiseFrequency 5
    #AdvertiseSecurityKey secret  
    #AdvertiseGroup 224.0.1.105:23364
 
    #AllowDisplay On
 
    <Location /mod_cluster_manager>
      SetHandler mod_cluster-manager
      Order deny,allow
      Deny from all
      Allow from 127.0.0.1
    </Location>
  </VirtualHost>
</IfModule> 

standalone-ha.xml

In this example we are going to run all JBoss EAP server on the same machine and we are using standalone mode for simplicity reason. But the same apply if you want to run domain mode.

First configure JGroups to use TCP unicast.

        <subsystem xmlns="urn:jboss:domain:jgroups:1.1" default-stack="tcpping">
            ...
            <stack name="tcpping">
                <transport type="TCP" socket-binding="jgroups-tcp"/>
                <protocol type="TCPPING">
                    <property name="initial_hosts">127.0.0.1[7600],127.0.0.1[7800]</property>
                    <property name="port_range">0</property>
                    <property name="timeout">3600</property>
                    <property name="num_initial_members">2</property>
                </protocol>
                <protocol type="MERGE2"/>
                <protocol type="FD_SOCK" socket-binding="jgroups-tcp-fd"/>
                <protocol type="FD"/>
                <protocol type="VERIFY_SUSPECT"/>
                <protocol type="BARRIER"/>
                <protocol type="pbcast.NAKACK"/>
                <protocol type="UNICAST2"/>
                <protocol type="pbcast.STABLE"/>
                <protocol type="pbcast.GMS"/>
                <protocol type="UFC"/>
                <protocol type="MFC"/>
                <protocol type="FRAG2"/>
                <protocol type="RSVP"/>
            </stack>
        </subsystem>

Secondly we need to configure modcluster subsystem in JBoss EAP 6 and set advertise="false" and proxy-list="127.0.0.1:80".

        <subsystem xmlns="urn:jboss:domain:modcluster:1.1">
            <mod-cluster-config advertise-socket="modcluster" proxy-list="127.0.0.1:80" advertise="false" connector="ajp">
                <dynamic-load-provider>
                    <load-metric type="busyness"/>
                </dynamic-load-provider>
            </mod-cluster-config>
        </subsystem>

Now lets restart Apache Webserver (httpd) and start two JBoss server. And last you must deploy a clusterable application.

$ service httpd restart

$ ./standalone.sh --server-config=standalone-ha.xml -Djboss.node.name=jb1

$ ./standalone.sh --server-config=standalone-ha.xml -Djboss.socket.binding.port-offset=200 -Djboss.node.name=jb2

June 12, 2013

Common JBoss EAP 6 CLI Commands for Managing Domain Clusters

Add ServerGroup

[domain@localhost:9999 /] /server-group=third-server-group:add(profile=ha, socket-binding-group=ha-sockets)

Remove ServerGroup

[domain@localhost:9999 /] /server-group=third-server-group:remove

Add Server to ServerGroup

[domain@localhost:9999 /] /host=host1/server-config=station81Host1:add(group=second-server-group, socket-binding-group=ha-sockets, socket-binding-port-offset=300)

Remove Server from ServerGroup

[domain@localhost:9999 /] /host=host1/server-config=station81Host1:remove

Manage Server on ServerGroup

[domain@localhost:9999 /] /host=host1/server-config=station81Host1:start

[domain@localhost:9999 /] /host=host1/server-config=station81Host1:stop

June 8, 2013

How to Set Hostname on RHEL 6

Hostname is usually set when installing the machine, but sometime you need to change it.

To print current hostname

$ hostname
server1.example.com

To temporarily change the hostname.

$ hostname server99.example.com

To permanently change the hostname, edit the /etc/sysconfig/network and set the HOSTNAME property.

$NETWORKING=yes
HOSTNAME=server99.example.com

After saving the configuration, you will need to reboot your machine.

How to Disable/Enable and SELinux on RHEL 6

On test laptops you are not always interesting in having all security enabled, e.g. when developing or testing a applications. And that is true for SELinux.

To see if SELinux is active

$ /usr/sbin/sestatus
SELinux status:                 enabled
SELinuxfs mount:                /selinux
Current mode:                   enforcing
Mode from config file:          enforcing
Policy version:                 23
Policy from config file:        targeted

To temporarily disable SELinux - 1 (enable) or 0 (disable).

$ setenforce 0

To permanently disable SELinux, edit /etc/selinux/config and set SELINUX=disabled.

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
#SELINUX=enforcing
SELINUX=disabled
# SELINUXTYPE= can take one of these two values:
#     targeted - Targeted processes are protected,
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted 

After saving you need to reboot your machine.

How to setup log4j Syslog Appender in JBoss EAP 6

This solution only works for JBoss EAP 6.0.1 and higher

JBoss ships with a own logging framework and which is used via the org.jboss.logging.Logger class. I myself tend to like to use standardized solution, which is for me - log4j.

Log4j ships with some Appenders, but one especially useful for a Linux environment is SyslogAppender. Here I will show you how to setup log4j org.apache.log4j.net.SyslogAppender with JBoss EAP 6.0.1.

Log4j already is shipped with JBoss, so binaries are required for installation. The configuration is either done in standalone.xml or domain.xml.

        <subsystem xmlns="urn:jboss:domain:logging:1.1">
            ...
            <custom-handler name="SYSLOG" class="org.apache.log4j.net.SyslogAppender" module="org.apache.log4j">
              <level name="INFO"/>
              <formatter>
                <pattern-formatter pattern="%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%E%n"/>
              </formatter>
              <properties>
                <property name="syslogHost" value="localhost:514"/>
                <property name="facility" value="LOCAL1"/>
                <property name="facilityPrinting" value="false"/>
              </properties>
            </custom-handler>
            ...
            <root-logger>
                <level name="INFO"/>
                <handlers>
                    ...
                    <handler name="SYSLOG"/>
                </handlers>
            </root-logger>
        </subsystem>

In the above configuration I'm using a local rsyslog server listening on UDP port 514. The log4j does not have a Syslog Appender that supports TCP. To test this configuration I'm using RHEL 6 and in a default installed RHEL an UDP listener is not default configured. To activate it, open /etc/rsyslog.conf and uncomment the below.

$ Provides UDP syslog reception
$ModLoad imudp
$UDPServerRun 514

Now restart rsyslog with:

$ service rsyslog restart

Now start JBoss and watch logging messages in the default log rsyslog message file.

$ less /var/log/messages

After verified the Syslog Appender, you probably want to separate JBoss logging to a separate file. How to configure that is out of the scoop for this blog, but a simplistic configuration in /etc/rsyslog.conf is:

local1.*                                                /var/log/local0.log

After modification, restart rsyslog and rsyslog will automatically create the new log file.

June 7, 2013

How to Install Graphical Printer Configuration Tool on RHEL 6

When installing RHEL 6 with Desktop, you might not get all of the administration tool installed from the beginning. A common tool that is often forgotten is the Printing Configuration tool. To install do the following:

$ yum install system-config-printer

After you can open the printer configuration from System -> Administration -> Printing.

June 3, 2013

New Apache Wicket Book and Good Starting Point for Newbie

A good starting point for learning new framework is to buy a book about. The problem with books is that they get quite fast out-dated for fast developing framework and that is also true for the Apache Wicket project. But quite recently a new e-book have been published for Apache Wicket 6 and the best thing about it, it is free - http://code.google.com/p/wicket-guide/.

You can get a complete list of all Apache Wicket books here http://wicket.apache.org/learn/books/.

And if you want another book I would recommend Wicket in Action.

Another good starting point is to run the components examples (http://www.wicket-library.com/wicket-examples/index.html) on the Apache Wicket page and read the Reference Wiki pages - https://cwiki.apache.org/WICKET/reference-library.html.

The next step if you have not already done that is to start writing codes. When doing so it is good to knew that there is a very good mailing list group for Apache Wicket, which I recommend to search in, if you get stuck - http://wicket.apache.org/help/.