February 2, 2011

Installing Apache Active MQ on Ubuntu

After creating a Sales Demonstration system for an industry trade show using Ubuntu 10.10, I decided to create a personal development system based on one of my personal favorite free operating systems, Ubuntu. An old laptop was pressed into service as a meager server on which I could refresh my admin skills and provide a target for testing prototype concepts rambling around my brain. One of the first services this little laptop will host is Apache Active MQ 5.4.2 which was released December of 2010. (Authors Note: This article has been updated to support Ubuntu 11 and ActiveMQ 5.5)

Although Ubuntu has a large collection of software available in many repositories, there is no way, currently, to perform an apt-get for Active MQ. It has to be installed by hand. Fortunately, this is a relatively simple matter. There are a couple of stumbling blocks which prevented a smooth install for me so I thought this article might help others avoid them.

Ensure you have Java installed

I prefer to have have the sun-java6-bin and sun-java6-jre packages for this purpose. I'm currently testing the free versions which come with Ubuntu. I have a separate link which describes installing sun-java on Ubuntu. It's like 5 commands; no big deal.

Initial Install

Go to the download page for Apache Active MQ and select the latest available release tarball and extract it on your server.

tar xzf apache-activemq-5.5.0-bin.tar.gz

Move it to /opt where optional software package are intended to be placed.

sudo mv apache-activemq-5.5.0 /opt

The activemq scripts expect to find Active MQ installed in /opt/activemq. I personally do not like having a non-versioned directory like that. Moving the package to /opt/activemq as would be expected by the scripts can make it difficult months down the line to upgrade. What version is installed? Will you remember? Now, this is a personal preference, but I like to know at any time what versions of software I have installed so I generally create a sym-link so the script finds things where it expects and I can see what version is installed. It is also easier to switch versions by simply linking /opt/activemq to another directory containing a different version. If it works fine, I can delete the old version, if not, I can switch the like back all this happens without changing any of the scripts. Here is how I did it:

sudo ln -sf /opt/apache-activemq-5.5.0/ /opt/activemq

Add Non-Privileged Account

It's never a good idea to run a service as root, so it is a common practice to add a dedicated user account which doesn't have much authority and run the service as this account. This will have the added benefit of making the process easier to identify with tools such as ps and top.

sudo adduser -system activemq

Some (many?, most?) systems will give a system user a false login shell. This will keep the activemq script from running so you will have to make sure the account uses the bash shell. First, open the /etc/passwd file in your favorite editor. Don't forget to use sudo as it is a privileged file. Here is the line when using vi:

sudo vi /etc/passwd

Go to the end of the list of accounts and make sure the shell for this account looks something like the following line. Don't worry about the numbers and such, but make sure the last argument contains /bin/bash and not something like /bin/false, for example, the line should look something like the following:

activemq:x:116:65534::/home/activemq:/bin/bash

Recursively change the ownership of the entire activemq directory to the activemq user you just added.

sudo chown -R activemq: /opt/apache-activemq-5.5.0/

Next, sym-link the init script provided by Active MQ to /etc/init.d/activemq:

sudo ln -sf /opt/activemq/bin/activemq /etc/init.d/

Tell Ubuntu to start Active MQ on boot:

sudo update-rc.d activemq defaults

At this point you will probably get a warning about missing LSB information. LSB information is a block of information which directs how the links are made. See http://wiki.debian.org/LSBInitScripts for more details.

Now, let's build a default configuration file:

sudo /etc/init.d/activemq setup /etc/default/activemq

Change the owner and group of the config file:

sudo chown root:nogroup /etc/default/activemq

Change the file permissions so its read-write by root only:

sudo chmod 600 /etc/default/activemq

Editing the Configuration


Unfortunately, this is where you will have to begin searching through your configuration file and make changes specific to your version of software and setup. There have been some changes between releases of Active MQ so the instructions may not match what you see in your files.

Edit the newly generated /etc/default/activemq file. I'll use vi:

sudo vi /etc/default/activemq

You're looking for ACTIVEMQ_USER="". Enter the name of your activemq user name between the quotes.

Now we will configure the Active MQ broker to listen for JMX connections. Further down the file, un-comment the JMX configuration lines:

ACTIVEMQ_SUNJMX_START="-Dcom.sun.management.jmxremote.port=11099 "
ACTIVEMQ_SUNJMX_START="$ACTIVEMQ_SUNJMX_START -Dcom.sun.management.jmxremote.password.file=${ACTIVEMQ_CONFIG_DIR}/jmx.password"
ACTIVEMQ_SUNJMX_START="$ACTIVEMQ_SUNJMX_START -Dcom.sun.management.jmxremote.access.file=${ACTIVEMQ_CONFIG_DIR}/jmx.access"
ACTIVEMQ_SUNJMX_START="$ACTIVEMQ_SUNJMX_START -Dcom.sun.management.jmxremote.ssl=false"
ACTIVEMQ_SUNJMX_START="$ACTIVEMQ_SUNJMX_START -Dcom.sun.management.jmxremote"

The above configuration lines enable JMX on port 11099 and use two file to control access through JMX.

The next section will specify how the shutdown script will connect to the broker (via JMX) and log into the management console to issue the shutdown command. This line will connect to broker via port 11099 and log in as controlRole with a password of abcd1234. Keep these values (or whatever you change them to) in mind as you will need to make sure they are registered in the data/jmx.password and data/jmx.access files in the next steps.

ACTIVEMQ_SUNJMX_CONTROL="--jmxurl service:jmx:rmi:///jndi/rmi://127.0.0.1:11099/jmxrmi --jmxuser controlRole --jmxpassword abcd1234"
# ACTIVEMQ_SUNJMX_CONTROL=""
# Specify the queue manager URL for using "browse" option of sysv initscript
ACTIVEMQ_QUEUEMANAGERURL="--amqurl tcp://localhost:61616"

Save your changes to the configuration file and exit the editor.

Now, you must edit the conf/jmx.password and conf/jmx.access files. Use the sample data they provide in the comments immediately above the lines. Remember to use the values you specified (or left alone) int the --jmxuser and --jmxpassword of the ACTIVEMQ_SUNJMX_CONTROL configuration line above.

Ensure that these JMX access control files are readable by only the activemq user account!

sudo chmod 600 /opt/apache-activemq-5.5.0/conf/jmx.password
sudo chmod 600 /opt/apache-activemq-5.5.0/conf/jmx.access

Doing that enables the init script to connect to the locally running software via JMX, a management console. Without this configured correctly you're looking at issuing a shutdown command and seeing a ton of Java errors followed by thirty seconds (configurable) of timeout before the script finally issues a KILL on the process.

Now run the service

sudo /etc/init.d/activemq start

Then look in the /opt/activemq/data directory for the PID and log files. You can tail the log file to see what is happening:

sudo tail -f /opt/activemq/data/activemq.log

All Done!

The Active MQ broker should be running. You can test this in a variety of ways including using the telnet command to connect to the broker on 61616, the JMX port on 11099 or more simply by opening a browser connection to the HTTP management port: http://localhost:8161

22 comments:

sleepy March 30, 2011 at 8:45 PM  
Great article, just what I needed being a noob at setting it up.
Sandeep May 3, 2011 at 4:50 AM  
This is really a helpful post...thanks a lot to u.
SMiTTY August 7, 2011 at 1:45 PM  
Excellent post. Thanks for the kickstart in getting this going.
Unknown January 8, 2012 at 12:47 AM  
Thank you so much for this detailed and structured post. I was under the impression that activemq should work out-of-the-box (a lot of the other guides and docs simply say start activemq with no configuration after you download the package from apt).

I know you're not using the apt package but still thank a lot!
Unknown May 23, 2012 at 4:35 PM  
Thank you so much! Struggled for three days trying out different install steps until I came across yours and it actually worked!
edi November 20, 2012 at 10:39 AM  
I think jmxuser should be 'control':

ACTIVEMQ_SUNJMX_CONTROL="--jmxurl service:jmx:rmi:///jndi/rmi://127.0.0.1:11099/jmxrmi --jmxuser control --jmxpassword abcd1234"
# ACTIVEMQ_SUNJMX_CONTROL=""
# Specify the queue manager URL for using "browse" option of sysv initscript
ACTIVEMQ_QUEUEMANAGERURL="--amqurl tcp://localhost:61616"
Anonymous,  March 18, 2013 at 10:44 AM  
I used your post to install ActiveMQ 5.8.0 on Ubuntu, thanks!

A tip for others who wanted to move the ACTIVEMQ_DATA directory (I wanted to put mine in /var/local/activemq): The log files assume that it is ACTIVEMQ_BASE/data, which caused errors on startup because that directory did not exist. I had to make some changes to $ACTIVEMQ_BASE/conf/log4j.properties to get it to work:

log4j.appender.logfile.file=${activemq.data}/activemq.log
log4j.appender.audit.file=${activemq.data}/audit.log
Andrew March 27, 2013 at 1:45 AM  
Fantastic blog! Tried manual install but couldn't get it to run. Following your post I now have ActiveMQ 5.8 running as a service on Ubuntu 12.04 using Java 1.7.0_17. Thanks!
Be Smiley April 15, 2013 at 6:32 PM  
Thanks for the instructions. I ran into a nasty problem with a simple fix. If you get java Connection "no route to host" errors when stopping you may have to adjust your /etc/hosts file.

Where /etc/hostname contains 'foo' your /etc/hosts file must map 'foo' to an IP in the 127.x.x.x range.

127.0.0.1 localhost
127.0.1.1 foo
Thomas Carlyle May 27, 2013 at 4:50 AM  
I was wondering on how to set up the configuration script to load the activemq-security.xml

I have been following http://activemq.apache.org/encrypted-passwords.html in order to encrypt my configuration passwords, but I could not figure it out where in the init or configuration stript I should set the loading.

I tried setting the variable COMMANDLINE_ARGS="$@ xbean:../conf/activemq-security.xml" without success
Shreyas July 4, 2013 at 5:38 AM  
Thanks. You saved lot of time :)
Unknown September 25, 2013 at 6:48 AM  
Thanks, this saved me a lot of time trying to get MCollective running on Ubuntu.
Unknown September 25, 2013 at 6:49 AM  
Thanks, your article saved me a lot of time getting ActiveMQ running for MCollective on Ubuntu.
Unknown February 11, 2014 at 3:18 PM  
Excellent!, very clear, used to install in Ubuntu 13.04
tks.
Unknown June 25, 2014 at 10:00 AM  
Cool! I followed all the steps without any problem with "ubuntu 12.04" and "activemq 5.9.1". Many thanks.
Paul June 28, 2014 at 2:44 AM  
Worked like a charm, thanks for making that an easy task!!!
Jorge David July 21, 2014 at 6:31 PM  
Thanks!!!!

There was no problem during installation :)
Jorge David July 21, 2014 at 6:31 PM  
This comment has been removed by the author.
Unknown October 19, 2014 at 6:21 AM  
Hi,

I got the following stacktrace when stopping activemq...
ERROR: java.lang.IllegalArgumentException: JMX URL already specified.
java.lang.IllegalArgumentException: JMX URL already specified.
at org.apache.activemq.console.command.AbstractJmxCommand.handleOption(AbstractJmxCommand.java:349)
at org.apache.activemq.console.command.ShutdownCommand.handleOption(ShutdownCommand.java:165)
at org.apache.activemq.console.command.AbstractCommand.parseOptions(AbstractCommand.java:73)
at org.apache.activemq.console.command.AbstractCommand.execute(AbstractCommand.java:45)
at org.apache.activemq.console.command.AbstractJmxCommand.execute(AbstractJmxCommand.java:387)
at org.apache.activemq.console.command.ShellCommand.runTask(ShellCommand.java:150)
at org.apache.activemq.console.command.AbstractCommand.execute(AbstractCommand.java:57)
at org.apache.activemq.console.command.ShellCommand.main(ShellCommand.java:104)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.apache.activemq.console.Main.runTaskClass(Main.java:262)
at org.apache.activemq.console.Main.main(Main.java:115)
Stopping broker: localhost
.. FINISHED



Could you help me?
How to resolve it?
Unknown February 6, 2015 at 6:18 AM  
Thanks a lot!!
It saved me struggling up for days.
Anonymous,  March 11, 2016 at 1:55 AM  
How to stop service?

sudo /etc/init.d/activemq stop

This gives an error. Any command?

Ict Job openings December 26, 2023 at 11:52 PM  
This comment has been removed by the author.

About This Blog

This is a low frequency blog on implementing SOA designs using message brokering. It is a list of practical tips developed over several years deploying service oriented systems for targeted and mass deployments in the telecommunications carrier and electric utility markets.

Recent Articles

Blog Archive

   Copyright © Steve Coté - All Rights Reserved.

Back to TOP