Yet Another James Green Web Developer, Aquarist

31Aug/1010

Installing ActiveMQ on Ubuntu

Apache ActiveMQ boxOr, "no, there's no .deb for it yet".

ActiveMQ is a software message queue from the Apache Software Foundation. If you're reading this you most likely know what it is and probably have reasons to use it on an Ubuntu machine but have found out that it does not exist in the perfect world that is, apt-get.

And I did promise the solution, so here it is.

Initially

So, hop over to the download page and select the latest available release tarball and extract it on your server. This concludes the super-simple bit.

Ensure you have java installed. I have the sun-java6-bin and sun-java6-jre packages for this purpose for Ubuntu 9.10 and 10.04.

For Security

Next, you might want to add a dedicated user account which doesn't have much at all. Examine the adduser command options to disable login, disable password and disable the home directory. This adds up to a locked-down user account. Recursively change the ownership of the entire activemq directory firstly to root, then change the data directory to the activemq user you just added.

With sudo, move the entire activemq directory into /opt - this is not particularly standard for Ubuntu but given the ActiveMQ scripts default to /opt/activemq and this package does not originate from a Debian package it seems appropriate enough.

Adding Startup

Next, symlink the init script as provided by ActiveMQ 5.4.0+ from /etc/init.d/activemq:

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

While here you might as well tell Ubuntu to start ActiveMQ on boot:

$ sudo update-rc.d activemq defaults

Defaults and Local Configuration

Now, let's build a default configuration file:

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

And edit the newly generated /etc/default/activemq file. You're looking initially for ACTIVEMQ_USER="". Enter the name of your activemq user between the quotes. Further down, uncomment the 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"

And right underneath that lot:

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"

Now, you must create the data/jmx.password and data/jmx.access files (use the sample data they provide in the comments immediately above the lines). Ensure that these jmx files are only readable by the activemq user account!

Doing that lot enables the init script to connect to the locally running software via JMX, a management console. Without this configures correctly you're looking at issuing a shutdown command and seeing a ton of Java errors followed by thirty seconds of timeout before the script finally issues a KILL on the pid. Not exactly elegant nor convenient.

That's it. There really isn't anything more to it but I thought I'd better note it as I'd been struggling to understand why the out-of-the-box configuration led to such poor shutdowns on each of my boxes.

Comments (10) Trackbacks (0)
  1. Great tutorial, worked perfectly! Thank you!

  2. One thing I’m having trouble with is how to setup persistence with Oracle DB. Any suggestions there?

  3. An example of using Oracle for persistence is given in http://fusesource.com/docs/broker/5.0/persistence/persistence.pdf on page 27. The ActiveMQ persistence docs are currently held at http://activemq.apache.org/persistence.html

  4. I wish I had found this sooner… thank you!

  5. Or, if you’d rather use upstart, this will work with the new activemq script

    (/etc/init/activemq.conf)

    # this should be late enough. Not a good choice for people with kde, or headless servers…
    start on (started dbus and started gdm)

    respawn
    exec sudo -u karlnet /opt/apache-activemq/bin/activemq console

    Then any apps you have can just have
    start on started activemq
    stop on stopped activemq

    and they’ll happily do their thing without having to muck around with numbered sequencing of initv scripts.

  6. This is a great post. However as a motivated Ubuntu newbie, I am having trouble with your security section. You wrote: “Examine the adduser command options to disable login, disable password and disable the home directory.”. The bottom line is this: the user I want to define is “activemquser”. Can you please post the adduser command I should issue, complete with all the parameters filled in? Thanks in advance. :-)

  7. Your instructions worked and I got activeMQ 5.4.2 to run. There was only one error in your directions. ${ACTIVEMQ_CONFIG_DIR} appends “conf” not “data”. So, your sentence “you must create the data/jmx.password and data/jmx.access files” should be changed to “you must create the conf/jmx.password and conf/jmx.access files”. And, those two files already exist so the instructions should be to modify them instead of create them.
    I never could have gotten activeMQ to run in Ubuntu 10.04 on my own without your superb directions. Thank you so much!!!
    The only problem outstanding for me is that when I type “jconsole” I cannot connect to activeMQ locally or remotely. Am not sure why this is. I must be doing something wrong. Everything else works. i.e. all of the following work for me: (I am not using localhost, as you can see).

    http://192.168.179.139:8161/demo/
    http://192.168.179.139:8161/camel/
    http://192.168.179.139:8161/admin/
    http://192.168.179.139:8161/fileserver/

  8. Note: When installing 5.5.0 release on Ubuntu, the correct activemq binary is located in /opt/activemq/bin/linux-x86-32|64/.

    Please note when creating the symlink to /etc/init.d/.

    Also you might want to change the path to the activemq.pid file in the activemq file. As is, it stores the pid file at the same path as the activemq file.

    Thanks for a great article. Helped a lot!

    Cheers!

  9. Thanks so much for these instructions. Now I have a weird question. I had followed these instructions for 5.4.2 and it worked. It was running fine, then one day it just stopped. Somehow, it seems that config files literally disappeared (like the jmx.password file was just gone, there was no activemq.xml, etc). I couldn’t get it working again. So today I started over, installed 5.5 and it doesn’t work. I’m not even getting useful logging. Here’s the output:

    INFO: Loading ‘/etc/default/activemq’
    INFO: Using java ‘/usr/bin/java’
    INFO: changing to user ‘activemquser’ to invoke java
    No directory, logging in with HOME=/
    Java Runtime: Sun Microsystems Inc. 1.6.0_20 /usr/lib/jvm/java-6-openjdk/jre
    Heap sizes: current=251264k free=249951k max=251264k
    JVM args: -Xms256M -Xmx256M -Dorg.apache.activemq.UseDedicatedTaskRunner=true -Djava.util.logging.config.file=logging.properties -Dorg.apache.activemq.audit=true -Dactivemq.classpath=/opt/activemq/conf; -Dactivemq.home=/opt/activemq -Dactivemq.base=/opt/activemq
    ACTIVEMQ_HOME: /opt/activemq
    ACTIVEMQ_BASE: /opt/activemq
    Usage: Main [--extdir ] [task] [task-options] [task data]

    Tasks (default task is start):
    start – Creates and starts a broker using a configuration file, or a broker URI.
    create – Creates a runnable broker instance in the specified path
    stop – Stops a running broker specified by the broker name.
    list – Lists all available brokers in the specified JMX context.
    query – Display selected broker component’s attributes and statistics.
    browse – Display selected messages in a specified destination.
    journal-audit – Allows you to view records stored in the persistent journal.
    purge – Delete selected destination’s messages that matches the message selector
    encrypt – Encrypts given text
    decrypt – Decrypts given text

    It just stops, like there is some permission thing somewhere. I’m at my wits end, and ready to ditch Ubuntu! Do you have any suggestions?

  10. Donna: Sounds like something in the background either uninstalled ActiveMQ or removed the folder in which it was installed. Either way, I can assure you it’s not normal! Hop on to the activemq-users mailing list for more detailed help.


Leave a comment

(required)

No trackbacks yet.