Install ActiveMQ

Install Java
First make sure Java runtime is installed via this command:
java -version
if you get result like this:
java version "9"
Java(TM) SE Runtime Environment (build 9+181)
Java HotSpot(TM) 64-Bit Server VM (build 9+181, mixed mode)
then you have Java. if not then install it from this script:
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java9-installer
sudo update-alternatives --config java
Explain:
  • add Java repository to apt-get
  • update apt-get
  • install Java 9
  • return a list of installed Java versions

Java Configuration
Java needs "JAVA_HOME" environment variable to run. so we going to add it manually.
sudo vim /etc/environment
add this line at the end of the file:
JAVA_HOME="/usr/lib/jvm/java-9-oracle"
save and exit reload environment variables:
source /etc/environment
Test
echo $JAVA_HOME
result:
/usr/lib/jvm/java-9-oracle
Install ActiveMQ
Full Script:
cd /home/ubuntu/
wget http://www-eu.apache.org/dist//activemq/5.15.2/apache-activemq-5.15.2-bin.tar.gz
tar -xzvf apache-activemq-5.15.2-bin.tar.gz
cd apache-activemq-5.15.2
Explain:
  • open a location to download ActiveMQ in.
  • download ActiveMQ 5.15.2 tar file.
  • extract it in current location.
  • open the extracted directory.

Use IPv4
before run ActiveMQ .. we need to make a small modification
by default Java runtime will use IPv6 if applicable.
we need to tell ActiveMQ to use IPv4 instead of default IPv6
there are two ways to do this .. whether to disable ipv6 in the OS
or by edit activmq main script to make qctivemq start with ipv4.
we going to use second method .. edit activemq main script:
after open ActiveMQ directory
cd apache-activemq-5.15.2

we going to edit the script using vim
vim bin/activemq

<<== Be careful when modify this script ==>>

we will search for invoke_start() function in this function you will find line like this:
ACTIVEMQ_OPTS="$ACTIVEMQ_OPTS $ACTIVEMQ_SUNJMX_START $ACTIVEMQ_SSL_OPTS -Djava.awt.headless=true -Djava.io.tmpdir=\"${ACTIVEMQ_TMP}\""
after this line exactly add the following line:
ACTIVEMQ_OPTS="$ACTIVEMQ_OPTS  -Djava.net.preferIPv4Stack=true "
final result
invoke_start(){
    if ( checkRunning );then
      PID="`cat $ACTIVEMQ_PIDFILE`"
      echo "INFO: Process with pid '$PID' is already running"
      exit 0
    fi

    ACTIVEMQ_OPTS="$ACTIVEMQ_OPTS $ACTIVEMQ_SUNJMX_START $ACTIVEMQ_SSL_OPTS -Djava.awt.headless=true -Djava.io.tmpdir=\"${ACTIVEMQ_TMP}\""
    ACTIVEMQ_OPTS="$ACTIVEMQ_OPTS  -Djava.net.preferIPv4Stack=true "

    echo "INFO: Starting - inspect logfiles specified in logging.properties and log4j.properties to get details"
    invokeJar "$ACTIVEMQ_PIDFILE" start
    exit "$?"
}
then save and exist vim editor Run ActiveMQ
open ActiveMQ directory
cd apache-activemq-5.15.2
then run this command as is
./bin/activmq start
to stop it
./bin/activmq stop
to get ActiveMQ status
./bin/activmq status
to make sure that ActiveMQ is listining to ports using IPv4
run this command
netstat -tlpn
this command will give you a list of open ports in the system and which application is use it try to find this port 8161 if the result like this:
tcp6       0      0 :::8161                 :::*                    LISTEN      2143/java
then ActiveMQ still use the default IPv6
if the result like this:
tcp        0      0 0.0.0.0:8161            0.0.0.0:*               LISTEN      2143/java
then ActiveMQ successfully use IPv4

DONE


Back To List