浙江省高等学校教师教育理论培训

微信搜索“教师资格证岗前培训”小程序

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

http://barkingiguana.com/2008/12/13/deploying-activemq-on-ubuntu-810/

Deploying ActiveMQ on Ubuntu 8.10

I used Ubuntu 8.10 in this article but the instructions will probably work on 8.04 and 7.10 as well. I've not tested those though, and I'm not sure if it'll work on other versions of Ubuntu. Feedback would be awesome.

Prerequisites

ActiveMQ is a Java aplication so, well, you'll need Java installed.

sudo apt-get install openjdk-6-jre

Installing ActiveMQ

  1. Grab the latest stable release using wget. 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
  2. Unpack it somewhere. I use /usr/local although I believe this may be bad practice. Leave a comment if there's somewhere better for this!
    sudo tar -xzvf apache-activemq-5.2.0-bin.tar.gz -C /usr/local/
  3. Configure the broker name in /usr/local/apache-activemq-5.2.0/conf/activemq.xml (replace all instances of "localhost" with the actual machine name)
  4. Start ActiveMQ by running /usr/local/apache-activemq-5.2.0/bin/activemq
  5. Fire up a browser and browse to http://brokername:8161/admin. You should see the ActiveMQ admin console.

Keeping ActiveMQ running

Running ActiveMQ (or indeed any service you don't absolutely have to) as root is a Bad Idea. Create an activemq user and make the data directory be owned by them.

sudo adduser --system activemq
sudo chown -R activemq /usr/local/apache-activemq-5.2.0/data

I run ActiveMQ under DaemonTools to make sure it's always up. If you haven't already, install DaemonTools.

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 exectuable, the log/main directory owned by activemq and symlink the activemq 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 turn the keys and start it up.

sudo svc -u /etc/service/activemq

Tail the logs to make sure everything is happening as you'd expect.

sudo tail -F /etc/service/activemq/log/main/current

Trouble-shooting

When I 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 was because I stopped ActiveMQ after I changed ownership of the data directory causing it to dump the state file owned by another user. If you get the same problem just change the ownership of the data directory again.

Thanks

Thanks to Sean O'Halpin who introduced me to message queues and ActiveMQ (but who doesn't have a homepage or blog that I can link to) and Dave Evans who introduced me to Daemon Tools.

Craig
13 Dec 2008

 

posted on 2012-02-06 09:21  lexus  阅读(311)  评论(0编辑  收藏  举报