• Get In Touch
January 6, 2017

How to Install Apache ActiveMQ on Ubuntu 14.04

Want your very own server? Get our 1GB memory, Xeon V4, 25GB SSD VPS for £10.00 / month.
Get a Cloud Server

ActiveMQ is one of the most popular and powerful open source messaging and integration patterns server.

ActiveMQ Features

Several ActiveMQ features:

  • Support a wide variety of language clients and protocol including but not limited to Java, C, C++, Ruby and Python.
  • On Java, C, C++ and C# we can use OpenWire for high performance client
  • Stomp support that enable us easily writing client code in C, Ruby, Perl, Python, PHP, ActionScript/Flash, Smalltalk to talk not only to ActiveMQ but also another popular message broker
  • Support AMQP v1.0
  • Support mQTT v3.1

Goals

In this tutorial we’ll learn how-to install and do basic configuration of Apache ActiveMQ and all of its prerequisite on Ubuntu 14.04.

Prerequisites

We assume that we have these items before we install Apache ActiveMQ:

  • Fresh install of Ubuntu Server 14.04. You can use any ubuntu flavors but using ubuntu server will make sure your server have minimalist ubuntu installation so your system will not be loaded by unnecessary softwares.
  • JDK 8. We will use Oracle JDK 8 for this tutorial. If you prefer OpenJDK you can instal OpenJDK 8.

Update Base System

Before we install Apache ActiveMQ and its prerequisites let’s update the system to the latest update using the following commands:

$ sudo apt-get update
$ sudo apt-get -y upgrade

Install Oracle JDK

Now, let’s install Java Development Kit 8. We will use Oracle JDK instead of OpenJDK version of JDK 8.

We’ll also use webupd8team ppa repository instead of installing JDK manually.
Add webupd8team PPA repository.

$ sudo add-apt-repository ppa:webupd8team/java
 Oracle Java (JDK) Installer (automatically downloads and installs Oracle JDK7 / JDK8 / JDK9). There are no actual Java files in this PPA.

More info (and Ubuntu installation instructions):
- for Oracle Java 7: http://www.webupd8.org/2012/01/install-oracle-java-jdk-7-in-ubuntu-via.html
- for Oracle Java 8: http://www.webupd8.org/2012/09/install-oracle-java-8-in-ubuntu-via-ppa.html

Debian installation instructions:
- Oracle Java 7: http://www.webupd8.org/2012/06/how-to-install-oracle-java-7-in-debian.html
- Oracle Java 8: http://www.webupd8.org/2014/03/how-to-install-oracle-java-8-in-debian.html

Important!!! For now, you should continue to use Java 8 because Oracle Java 9 is available as an early access release (it should be released in 2016)! You should only use Oracle Java 9 if you explicitly need it, because it may contain bugs and it might not include the latest security patches! Also, some Java options were removed in JDK9, so you may encounter issues with various Java apps. More information and installation instructions (Ubuntu / Linux Mint / Debian): http://www.webupd8.org/2015/02/install-oracle-java-9-in-ubuntu-linux.html
 More info: https://launchpad.net/~webupd8team/+archive/ubuntu/java
Press [ENTER] to continue or ctrl-c to cancel adding it

gpg: keyring `/tmp/tmpaz5gxp9d/secring.gpg' created
gpg: keyring `/tmp/tmpaz5gxp9d/pubring.gpg' created
gpg: requesting key EEA14886 from hkp server keyserver.ubuntu.com
gpg: /tmp/tmpaz5gxp9d/trustdb.gpg: trustdb created
gpg: key EEA14886: public key "Launchpad VLC" imported
gpg: no ultimately trusted keys found
gpg: Total number processed: 1
gpg:               imported: 1  (RSA: 1)
OK

Update repository metadata.

$ sudo apt-get update

Install Oracle JDK 8.

$ sudo apt-get -y install oracle-java8-installer

Package configuration. Choose OK.

HP_NO_IMG/data/uploads/users/70fed463-d441-452e-bb7e-e0e3fa684498/1594637328.png” alt=”” />

Accepting Oracle Binary Code Lisence Terms. Choose Yes

HP_NO_IMG/data/uploads/users/70fed463-d441-452e-bb7e-e0e3fa684498/1525872870.png” alt=”” />

Check Java version by running command below.

$ java -version
java version "1.8.0_101"
Java(TM) SE Runtime Environment (build 1.8.0_101-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.101-b13, mixed mode)

Install ActiveMQ

Download Apache ActiveMQ from ActiveMQ mirror :

$ wget -c "http://www.apache.org/dyn/closer.cgi?filename=/activemq/5.14.3/apache-activemq-5.14.3-bin.tar.gz&action=download" -O apache-activemq-5.14.3-bin.tar.gz

Extract downloaded file

$ tar xzf apache-activemq-5.14.3-bin.tar.gz

Rename extracted directory to activemq

$ mv apache-activemq-5.14.3 activemq

We will create user and group named activemq that will be used to run ActiveMQ. Create the group first

$ sudo addgroup --quiet --system activemq

Create activemq system user.

$ sudo adduser --quiet --system --ingroup activemq --no-create-home --disabled-password activemq

Modify /etc/passwd entry to change home and group for activemq user.

$ sudo usermod -c "ActiveMQ Broker" -d /opt/activemq -g activemq activemq

Change ownership of /opt/activemq directory to user activemq and group activemq.

$ sudo chown -R activemq:activemq /opt/activemq

Change the permission of /opt/activemq directory.

$ sudo chmod u=rwx,g=rxs,o= /opt/activemq

Configure ActiveMQ

Create default file for file by copying bin/env file to /etc/default/activemq.

$ sudo cp /opt/activemq/bin/env /etc/default/activemq

Change the ownership of /etc/default/activemq file to user and group root.

$ sudo chown root:root /etc/default/activemq

Now let’s start configuring ActiveMQ. Open /etc/default/activemq file.

Find these lines:

# ACTIVEMQ_HOME="<Installationdir>/"
# ACTIVEMQ_BASE="$ACTIVEMQ_HOME"
# ACTIVEMQ_CONF="$ACTIVEMQ_BASE/conf"
# ACTIVEMQ_DATA="$ACTIVEMQ_BASE/data"
# ACTIVEMQ_TMP="$ACTIVEMQ_BASE/tmp"

Replace with:

ACTIVEMQ_HOME="/opt/activemq/"
ACTIVEMQ_BASE="$ACTIVEMQ_HOME"
ACTIVEMQ_CONF="$ACTIVEMQ_BASE/conf"
ACTIVEMQ_DATA="$ACTIVEMQ_BASE/data"
ACTIVEMQ_TMP="$ACTIVEMQ_BASE/tmp"
ACTIVEMQ_USER=""

Replace with:

ACTIVEMQ_USER="activemq"

Copy init script to /etc/init.d using command below:

$ cd /opt/activemq
$ sudo cp bin/activemq /etc/init.d

Change ownership of ActiveMQ init script to user and group root

$ sudo chown root:root /etc/init.d/activemq

Set activemq to start on boot using update-rc.d

$ sudo update-rc.d activemq defaults

Now let’s start ActiveMQ service using command below:

$ sudo service activemq start

ActiveMQ will show some output regarding the startup process:

INFO: Loading '/etc/default/activemq'
INFO: Using java '/usr/bin/java'
INFO: Starting - inspect logfiles specified in logging.properties and log4j.properties to get details
INFO: changing to user 'activemq' to invoke java
INFO: pidfile created : '/opt/activemq/data/activemq.pid' (pid '22291')

To check whether ActiveMQ is already running or not we can use command below:

$ sudo service activemq status
INFO: Loading '/etc/default/activemq'
INFO: Using java '/usr/bin/java'
ActiveMQ is running (pid '22291')

We can also use ps to check whether ActiveMQ process is running or not.

$ ps aux | grep activemq
activemq 22516  108  7.9 2962096 80584 ?       Sl   09:14   0:03 /usr/bin/java -Xms64M -Xmx1G -Djava.util.logging.config.file=logging.properties -Djava.security.auth.login.config=/opt/activemq/conf/login.config -Dcom.sun.management.jmxremote -Djava.awt.headless=true -Djava.io.tmpdir=/opt/activemq/tmp -Dactivemq.classpath=/opt/activemq/conf:/etc//../lib/: -Dactivemq.home=/opt/activemq -Dactivemq.base=/opt/activemq -Dactivemq.conf=/opt/activemq/conf -Dactivemq.data=/opt/activemq/data -jar /opt/activemq/bin/activemq.jar start

ActiveMQ default port is 61616 we can use netstat to check if ActiveMQ already listen on that port.

$ sudo netstat -naptu | grep 61616
tcp6       0      0 :::61616                :::*                    LISTEN      22516/java 

ActiveMQ also has a web console that listens on port 8161 we can also check using netstat to check if ActiveMQ is already listening on that port:

$ sudo netstat -naptu | grep 8161
tcp6       0      0 :::8161                 :::*                    LISTEN      22516/java  

Accessing ActiveMQ Web Admin

To access the web admin we can point our browser to http://activemq-ipaddress:8161/admin

It will prompt authentication form. Input admin as default username and password.

HP_NO_IMG/data/uploads/users/7d0b29d6-eaf0-48d0-84b2-e1e14356af78/1382898690.png” alt=”” />

From this web admin we can manage and monitor our ActiveMQ installation.

HP_NO_IMG/data/uploads/users/7d0b29d6-eaf0-48d0-84b2-e1e14356af78/15008667.png” alt=”” />

Monitoring ActiveMQ With Hawt.io

Beside using ActiveMQ default web admin we can also monitor our ActiveMQ installation using Hawt.io but we need to install Hawtio first.

We can download the latest version of Hawt.io from Hawt.io Getting Stated Page.

Let’s download hawt.io offline .war using wget

$ wget -c https://oss.sonatype.org/content/repositories/public/io/hawt/hawtio-default-offline/1.4.67/hawtio-default-offline-1.4.67.war

Unzip downloaded .war:

$ unzip hawtio-default-offline-1.4.67.war -d hawtio

Move extracted war to webapps directory:

$ sudo mv hawtio /opt/activemq/webapps

We need to change ACTIVEMQ_OPTS to add hawtio options. Open /etc/default/activemq

Find the line:

ACTIVEMQ_OPTS="$ACTIVEMQ_OPTS_MEMORY -Djava.util.logging.config.file=logging.properties -Djava.security.auth.login.config=$ACTIVEMQ_CONF/login.config"

Replace with:

ACTIVEMQ_OPTS="$ACTIVEMQ_OPTS_MEMORY -Djava.util.logging.config.file=logging.properties -Djava.security.auth.login.config=$ACTIVEMQ_CONF/login.config -Dhawtio.realm=activemq -Dhawtio.role=admins -Dhawtio.rolePrincipalClasses=org.apache.activemq.jaas.GroupPrincipal"

Open /opt/activemq/conf/jetty.xml, find line:

<ref bean="rewriteHandler"/>

Add these line below the line.

<bean class="org.eclipse.jetty.webapp.WebAppContext">
    <property name="contextPath" value="/hawtio" />
    <property name="resourceBase" value="${activemq.home}/webapps/hawtio" />
    <property name="logUrlOnStart" value="true" />
</bean>                            

Now restart ActiveMQ process

$ sudo service activemq restart

Now point our browser to http://activemq-ipaddress:8161/hawtio. Login using admin as username and password.

HP_NO_IMG/data/uploads/users/7d0b29d6-eaf0-48d0-84b2-e1e14356af78/386616084.png” alt=”” />

Hawtio Welcome Page
HP_NO_IMG/data/uploads/users/7d0b29d6-eaf0-48d0-84b2-e1e14356af78/1150081362.png” alt=”” />

Hawtio ActiveMQ dashboard.

HP_NO_IMG/data/uploads/users/7d0b29d6-eaf0-48d0-84b2-e1e14356af78/1191669204.png” alt=”” />

Summary

In this tutorial we learned how-to install ActiveMQ on Ubuntu 14.04. We also learned accessing ActiveMQ web admin and installing Hawtio as alternative web admin for ActiveMQ.

Want your very own server? Get our 1GB memory, Xeon V4, 25GB SSD VPS for £10.00 / month.
Get a Cloud Server

Share this Article!

Related Posts

Node.js Authentication – A Complete Guide with Passport and JWT

Node.js Authentication – A Complete Guide with Passport and JWT

Truth be told, it’s difficult for a web application that doesn’t have some kind of identification, even if you don’t see it as a security measure in and of itself. The Internet is a kind of lawless land, and even on free services like Google’s, authentication ensures that abuses will be avoided or at least […]

Node.js and MongoDB: How to Connect MongoDB With Node

Node.js and MongoDB: How to Connect MongoDB With Node

MongoDB is a document-oriented NoSQL database, which was born in 2007 in California as a service to be used within a larger project, but which soon became an independent and open-source product. It stores documents in JSON, a format based on JavaScript and simpler than XML, but still with good expressiveness. It is the dominant […]

Using MySQL with Node.js: A Complete Tutorial

Using MySQL with Node.js: A Complete Tutorial

Although data persistence is almost always a fundamental element of applications, Node.js has no native integration with databases. Everything is delegated to third-party libraries to be included manually, in addition to the standard APIs. Although MongoDB and other non-relational databases are the most common choice with Node because if you need to scale an application, […]

Node.Js Vs Django: Which Is the Best for Your Project

Node.Js Vs Django: Which Is the Best for Your Project

Django and NodeJs are two powerful technologies for web development, both have great functionality, versatile applications, and a great user interface. Both are open source and can be used for free. But which one fits your project best? NodeJs is based on JavaScript, while Django is written in Python. These are two equally popular technologies […]

Nodejs Vs PHP:  Which Works Best?

Nodejs Vs PHP: Which Works Best?

Before getting into the “battle” between Node.js and PHP we need to understand why the issue is still ongoing. It all started with the increased demand for smartphone applications, their success forcing developers to adapt to new back-end technologies that could handle a multitude of simultaneous requests. JavaScript has always been identified as a client-side […]