These instructions target Ubuntu 8.10, but they should work on 8.04 and 7.10 as well. I haven't tested those myself, so if you try them on a different version, I'd love to hear how it goes.
Prerequisites
ActiveMQ is a Java application, so you'll need a JRE installed.
sudo apt-get install openjdk-6-jre
Installing ActiveMQ
- Grab the latest stable release. I used 5.2.0.
wget http://www.apache.org/dist/activemq/apache-activemq/5.2.0/apache-activemq-5.2.0-bin.tar.gz - Unpack it somewhere sensible. I use
/usr/local, though I suspect there are better choices — leave a comment if you know of one.sudo tar -xzvf apache-activemq-5.2.0-bin.tar.gz -C /usr/local/ - Configure the broker name in
/usr/local/apache-activemq-5.2.0/conf/activemq.xmlby replacing all instances of "localhost" with the actual machine name. - Start ActiveMQ by running
/usr/local/apache-activemq-5.2.0/bin/activemq. - Fire up a browser and navigate to
http://brokername:8161/admin. You should see the ActiveMQ admin console.
Keeping ActiveMQ running
Running ActiveMQ as root (or indeed any service you don't absolutely have to) is a Bad Idea. Create a dedicated activemq user and hand over ownership of the data directory.
sudo adduser --system activemq
sudo chown -R activemq /usr/local/apache-activemq-5.2.0/data
I use DaemonTools to keep ActiveMQ alive. If you haven't already, install DaemonTools first.
Create a service directory for ActiveMQ and populate it with the required scripts.
sudo mkdir -p /usr/local/apache-activemq-5.2.0/service/activemq/{,log,log/main}
/usr/local/apache-activemq-5.2.0/service/activemq/run should look like this:
#!/bin/sh
exec 2>&1
USER=activemq
exec softlimit -m 1073741824 \
setuidgid $USER \
/usr/local/apache-activemq-5.2.0/bin/activemq
/usr/local/apache-activemq-5.2.0/service/activemq/log/run should look like this:
#!/bin/sh
USER=activemq
exec setuidgid $USER multilog t s1000000 n10 ./main
Make both run scripts executable, set the log/main directory ownership, and symlink the service directory into /etc/service/.
sudo sh -c "find /usr/local/apache-activemq-5.2.0/service/activemq -name 'run' |xargs chmod +x,go-wr"
sudo chown activemq /usr/local/apache-activemq-5.2.0/service/activemq/log/main
sudo ln -s /usr/local/apache-activemq-5.2.0/service/activemq /etc/service/activemq
Now fire it up.
sudo svc -u /etc/service/activemq
Tail the logs to make sure everything looks healthy.
sudo tail -F /etc/service/activemq/log/main/current
Troubleshooting
When I first did this I got a bunch of stack traces with the following message:
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.apache.activemq.xbean.XBeanBrokerService#0' defined in class path resource [activemq.xml]: Invocation of init method failed; nested exception is java.lang.RuntimeException: java.io.FileNotFoundException: /usr/local/apache-activemq-5.2.0/data/kr-store/state/hash-index-store-state_state (Permission denied)
This happened because I stopped ActiveMQ after changing ownership of the data directory, causing it to dump a state file owned by the wrong user. If you hit the same problem, just re-run the chown on the data directory.
Thanks
Thanks to Sean O'Halpin, who introduced me to message queues and ActiveMQ, and to Dave Evans, who introduced me to DaemonTools.