Sunday, January 25, 2015

Monitoring ActiveMQ Using Tomcat Web Container

So far I have covered tutorial about ActiveMQ with the following aspects:

In this post, I will cover the topic on how to setup Apache Tomcat to monitoring ActiveMQ node in a Master-Slave cluster. In the next post, I will expain the more advanced high availability features for ActiveMQ, namely, Network Of Brokers

Installation

Current release of apache tomcat is version 8.0.17. We can download it from http://tomcat.apache.org/download-80.cgi. I am using RedHat Linux, so I downloaded tar.gz version.

After download Tomcat, we need to download two more archives:

Here are the download files I have:

[amq@SANDBOXFUSEV01 current]$ ll /software/TOMCAT/
total 42069
-rwxr-xr-x. 1 16777217 wheel  6371237 Jan 20 09:16 activemq-all-5.10.0.jar
-rwxr-xr-x. 1 16777217 wheel 12753574 Jan 20 09:16 activemq-web-console-5.10.0.war
-rwxr-xr-x. 1 16777217 wheel  9264418 Jan 20 09:15 apache-tomcat-8.0.17.tar.gz
[amq@SANDBOXFUSEV01 current]$

Once it is download executed the following commands:

cd /opt/app/amq/tomcat
tar -vxzf /software/TOMCAT/apache-tomcat-8.0.17.tar.gz

Here is the directory structures:

[amq@SANDBOXFUSEV01 tomcat]$ pwd
/opt/app/amq/tomcat
[amq@SANDBOXFUSEV01 tomcat]$ ll
total 4
drwxrwxr-x. 9 amq amq 4096 Jan 20 11:09 apache-tomcat-8.0.17
lrwxrwxrwx. 1 amq amq   20 Jan 20 12:38 current -> apache-tomcat-8.0.17
[amq@SANDBOXFUSEV01 tomcat]$

Now we need to copy the activemq-all-5.10.0.jar to tomcat's lib directory and copy activemq-web-console-5.10.0.war to webapps with the following commands:

cp /software/TOMCAT/activemq-all-5.10.0.jar /opt/app/amq/tomcat/current/lib/.
cp /software/TOMCAT/activemq-web-console-5.10.0.war  /opt/app/amq/tomcat/current/webapps/.

Configuration Using TCP Connector

With all the software in place, we need to modify catalina.sh file by adding the following lines: [I attach few extra lines, so that you know where are the lines in the catalina.sh file]

# Uncomment the following line to make the umask available when using the
# org.apache.catalina.security.SecurityListener
#JAVA_OPTS="$JAVA_OPTS -Dorg.apache.catalina.security.SecurityListener.UMASK=`umask`"

JMX_OPTS=" -Dwebconsole.jmx.url=service:jmx:rmi:///jndi/rmi://sandboxfusev01:11099/jmxrmi"
JMX_OPTS="$JMX_OPTS,service:jmx:rmi:///jndi/rmi://sandboxfusev01:12099/jmxrmi"

JAVA_OPTS="-Dwebconsole.type=properties "
JAVA_OPTS="$JAVA_OPTS -Dwebconsole.jms.url=\"failover:(tcp://sandboxfusev01:61616,tcp://sandboxfusev01:61626)\" "
JAVA_OPTS="$JAVA_OPTS $JMX_OPTS "
JAVA_OPTS="$JAVA_OPTS -Dwebconsole.jmx.user=admin "
JAVA_OPTS="$JAVA_OPTS -Dwebconsole.jmx.password=activemq"


# ----- Execute The Requested Command -----------------------------------------

After configuring the Tomcat for monitoring ActiveMQ, you may disable the embeded web console from ActiveMA. By doing this, you can simple comment out the line:



Configuration Using NIO+SLL Connector

If ActiveMQ's transport connector uses nio+ssl, the connection url will have the following form:

"failover:(nio+ssl://activemq-host-name:61617,nio+ssl://activemq-host-name:61627)" \

For more details about how to configure ActiveMQ with nio+ssl, see my blog at:

In order to connect ActiveMQ brokers, we need update the catalina.sh file with the following:

JMX_OPTS=" -Dwebconsole.jmx.url=service:jmx:rmi:///jndi/rmi://devrhamqv01:11099/jmxrmi"
JMX_OPTS="$JMX_OPTS,service:jmx:rmi:///jndi/rmi://devrhamqv01:12099/jmxrmi"

JAVA_OPTS="-Dwebconsole.type=properties "
#JAVA_OPTS="$JAVA_OPTS -Dwebconsole.jms.url=\"failover:(tcp://host-name:61616,tcp://hostname:61626)\" "
JAVA_OPTS="$JAVA_OPTS -Dwebconsole.jms.url=\"failover:(nio+ssl://host-name01:61617,nio+ssl://host-name:61627)\" "
JAVA_OPTS="$JAVA_OPTS -Dwebconsole.jms.user=admin"
JAVA_OPTS="$JAVA_OPTS -Dwebconsole.jms.password=admin"

JAVA_OPTS="$JAVA_OPTS -Djavax.net.ssl.keyStore=/opt/app/activemq/cluster/master-slave/north/conf/shared.ks "
JAVA_OPTS="$JAVA_OPTS -Djavax.net.ssl.keyStorePassword=amqadmin@ "
JAVA_OPTS="$JAVA_OPTS -Djavax.net.ssl.trustStore=/opt/app/activemq/cluster/master-slave/north/conf/shared.ks "

JAVA_OPTS="$JAVA_OPTS $JMX_OPTS "
JAVA_OPTS="$JAVA_OPTS -Dwebconsole.jmx.user=admin "
JAVA_OPTS="$JAVA_OPTS -Dwebconsole.jmx.password=activemq"

Monitoring ActiveMQ In Action

Now lets start tomcat by running startup.sh. Make sure the ActiveMQ-WEB is load successfully. You can check the log file at /opt/app/amq/tomcat/current/logs/catalina.out. And the following lines should be shown:

25-Jan-2015 04:18:48.567 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployWAR Deployment of web application archive /opt/app/amq/tomcat/apache-tomcat-8.0.17/webapps/activemq-web-console-5.10.0.war has finished in 2,863 ms

Open the web broser with the following URL:

http://sandboxfusev01:8080/activemq-web-console-5.10.0/

As shown in the above picture, tomcat container has successfully connected to the north ActiveMQ node on the host SANDBOXFUSEV01

we verify north node is running be the following:

[amq@SANDBOXFUSEV01 bin]$ ./north status
INFO: Using default configuration
(you can configure options in one of these file: /etc/default/activemq /home/amq/.activemqrc)

INFO: Invoke the following command to create a configuration file
/opt/app/amq/apache-activemq-5.10.0/bin/activemq setup [ /etc/default/activemq | /home/amq/.activemqrc ]

INFO: Using java '/usr/bin/java'
ActiveMQ is running (pid '17720')
[amq@SANDBOXFUSEV01 bin]$

We know that is correct. Now let's stop the north node and see what happen. After refresh the web browser I see the following:

The new master ActiveMQ node is north from SANDBOXFUSEV02. I did not find a particular order about which slave will become next master. It seems whichever slave grab the lock at a particular moment after the master dies, will be come the new master.

Enable TLS/SSL

For details about configuring TLS/SSL, please refer: https://tomcat.apache.org/tomcat-8.0-doc/ssl-howto.html. Here are the procedure I have executed:

  1. generate private key using keytool
  2. put the keystore $HOME/$HOSTNAME.ks
  3. update $TOMCAT_HOME/conf/server.xml
  4. open the port 8443 from firewall using system-config-firewall

And here is the connector configuration:

    

Summary

We have successfuly configured the tomcat to monitor ActiveMQ instance. The good thing about using Tomcat we container to monitoring activemq instance is that it automatically connects to the master node. The installation and configuration are fairly straightforward.

2 comments:

Anypoint Studio Error: The project is missing Munit lIbrary to run tests

Anypoint Studio 7.9 has a bug. Even if we following the article: https://help.mulesoft.com/s/article/The-project-is-missing-MUnit-libraries-...