Installing and Managing ActiveMQ on CentOS

I recently had to setup ActiveMQ on CentOS. I found there wasn’t a lot of info on how to do this specifically for CentOS and i had to patch together information from various linux based documentation. Because of this i thought i’d document the process in the hopes that someone might find this useful

As a starting note, if you are using Virtual Machines to host the Queue in a Shared File System Master Slave configuration you must Never save the state of the Virtual Machine. This is because the File store lock is lost when the machine state is saved allowing the slave to start first and get promoted to a Master. The old master does not know the machine had stopped and still thinks its a Master. See http://activemq.2283324.n4.nabble.com/Shared-File-System-Master-Slave-locking-issues-with-VM-s-td4656130.html

CentOS Setup

Install CentOS

  1. Download CentOS DVD from http://www.centos.org
    1. Additional help can be found on their wiki http://wiki.centos.org/
  2. Install Centos
    1. During the installation process select Basic Desktop. This will make it easier to manage by giving you a GUI
    2. For the sake of this document set the default user up as the username ‘admin’

If you’re installing CentOS on a Virtual Machine we were getting warning errors in the kernel after restarting. This was due to the VM only having one processor.

CentOS VM Error

Setup CentOS Environment

The following steps will make it easier to use CentOS

Setup Admin User to be able to use sudo elevation command

  1. Add the user to the sudoers file
    1. Open a terminal
    2. Type “su -“ and hi enter
    3. Type “visudo” and hit enter
    4. Navigate to the bottom with the arrow keys
    5. Insert the following line by pressing “i”to enter insert mode. (spaces are tabs)
      admin   ALL=(ALL)     ALL
      
    6. Press Esc to enter command mode
    7. Save the file by typing “:x”
  2. Test the sudo command
    1. In the terminal type “sudo ls”
    2. type the root password and hit enter

You should see a list of files and folders

Install a better Text Editor

  1. In terminal type “sudo yum install gedit”
  2. Follow the promptsYou can create an elevated session of gedit with this command
    sudo gedit
    

Auto-mount a Windows Share

This is optional but may be require for configuring the server.

Follow the instructions at http://www.lamolabs.org/blog/6000/one-liner-mounting-a-smbcifs-share-as-an-automount-on-centosfedorarhel/

Installing Firewall Security Tool

To easily manage the firewall install the Security Level Configuration Tool. Run the following command


sudo yum install system-config-securitylevel

ActiveMQ Setup and Configuration

Install Java JRE and JDK

  1. Download the Java runtime environment from http://www.oracle.com/technetwork/java/javase/downloads/index.html
    1. Downloading the rpm package will self install
  2. Run with the package installer
    1. Enter the root password
    2. Allow it to download dependencies and install
  3. Repeat for the JDK

Installing ActiveMQ

  1. Download the Active MQ Linux package from http://activemq.apache.org/download.html
  2. Extract the TAR
    1. Open a terminal window
    2. Navigate to the downloads folder (in my case it was /home/admin)
      
      cd Downloads
      

      Terminal by default opens to /home/{user}. It is also case sensitive

    3. Extract the tarYou will need to update the version number with the version downloaded. You can check the directory by using the lscommand
      
      tar xzf apache-activemq-5.6.0-bin.tar.gz
      
    4. Move the ActiveMQ folder to optional folder (/opt) so the path is not user specific.
      
      sudo mv apache-activemq-5.6.0 /opt
      

      The ActiveMQ scripts expect to have them run from /opt/activemq. We symbolic link a versioned folder to this path in the next step

    5. Create a symbolic link to the version specific folder. The link can be updated with a new version without affecting the environment setup
      
      sudo ln -sf /opt/apache-activemq-5.6.0/ /opt/activemq
      

Configure ActiveMQ

Starting ActiveMQ on boot

  1. Add a non-privileged account to run activemq
    sudo adduser --system activemq
    
  2. Ensure the user uses the bash shell
    1. Open the /etc/passwd file
      
      sudo gedit
      
    2. Go to the end of the list and find the line that looks like
      
      activemq:x:496:493::/home/activemq:/bin/bash
      
    3. Ensure the line ends in /bin/bash and not /bin/false
  3. Change the ownership of the activemq directory to the user just added
    
    sudo chown -R activemq: /opt/apache-activemq-5.6.0/
    
  4. Enable the use of JMXThis will enable the use of some admin related commands when using /opt/activemq/bin/activemq and /opt/activemq/bin/activemq. The following commands are supported http://activemq.apache.org/activemq-command-line-tools-reference.html
    1. Edit the activemq default config xml
      sudo gedit /opt/activemq/conf/activemq.xml
      
    2. Set the managementContext element to True
      <managementContext>
       <managementContext createConnector="true"/>
      </managementContext>
      
    3. Restart for it to take affectYou can test this by running the list command to see the running broker instances after we finish the setup
      sudo /opt/activemq/bin/activemq-admin list
      
  5. Register ActiveMQ as a daemon service to start automatically
    1. Create the startup and shutdown scripts
      1. Create a new startup script with gedit
        
        sudo gedit /etc/init.d/activemqstart.sh
        
      2. Add the following to the activemqstart.sh script and save it/etc/init.d/activemqstart.sh
        
        #!/bin/bash
        export JAVA_HOME=/usr
        /opt/activemq/bin/activemq start &
        
      3. Create a new shutdown script with gedit
        
        sudo gedit /etc/init.d/activemqstop.sh
        
      4. Add the following to the activemqstart.sh script and save it
        /etc/init.d/activemqstop.sh

        
        #!/bin/bash
        export JAVA_HOME=/usr
        /opt/activemq/bin/activemq-admin stop
        

        activemq command is used to start an instance of activemq. you use activemq-admin to administer and stop the process. for more information see the command line tools http://activemq.apache.org/activemq-command-line-tools-reference.html

    2. Create the Linux service configuraion script
      1. Create and edit the script /etc/init.d/activemq
        
        sudo gedit /etc/init.d/activemq
        
      2. Add the following to the service configuration script/etc/init.d/activemqtrue
        
        #!/bin/bash
        #
        # activemq       Starts ActiveMQ.
        #
        # chkconfig: 345 88 12
        # description: ActiveMQ is a JMS Messaging Queue Server.
        ### BEGIN INIT INFO
        # Provides: $activemq
        ### END INIT INFO
        
        # Source function library.
        . /etc/init.d/functions
        
        [ -f /etc/init.d/activemqstart.sh ] || exit 0
        [ -f /etc/init.d/activemqstop.sh ] || exit 0
        
        RETVAL=0
        
        umask 077
        
        start() {
               echo -n $"Starting ActiveMQ: "
               daemon /etc/init.d/activemqstart.sh
               echo
               return $RETVAL
        }
        stop() {
               echo -n $"Shutting down ActiveMQ: "
               daemon su -c /etc/init.d/activemqstop.sh activemq
               echo
               return $RETVAL
        }
        restart() {
               stop
               start
        }
        case "$1" in
        start)
               start
               ;;
        stop)
               stop
               ;;
        restart|reload)
               restart
               ;;
        *)
               echo $"Usage: $0 {start|stop|restart}"
               exit 1
        esac
        
        exit $?
        
    3. Enable the ActiveMQ service as a Linux Daemon
      1. Run the following commands in the terminal to make the scripts executable
        sudo chmod +x /etc/init.d/activemqstart.sh
        sudo chmod +x /etc/init.d/activemqstop.sh
        sudo chmod +x /etc/init.d/activemq
        
      2. Run the following commands to register the service as a Linux Daemon
        
        sudo chkconfig --add activemq
        sudo chkconfig activemq on
        
  6. Ensure ActiveMQ starts automatically
    1. Reboot
    2. Open a terminal
    3. Enter the following command to make sure that a process is listening on the activemq port
      
      netstat -an |grep 61616
      

      The command should return something like

      NetstatImage

Add firewall exception

Make sure you have followed the steps Installing Firewall Security Tool

  1. Go to System > Administration > Firewall
  2. Go to Other Ports and select Add
  3. Tick User Defined and add the following ports
    1. 61616 – ActiveMQ queue port
    2. 8161 – ActiveMQ remote admin toolFirewall Exception

Create a Config script

The config script is placed in either the /etc/default or the home directory. ActiveMQ will check this location on startup and will use this file for any defaults such as the data directory

  1. In a terminal window create a config file
    
    sudo /opt/activemq/bin/activemq setup /etc/default/activemq
    
  2. Change the owner of the config file
    
    sudo chown root /etc/default/activemq
    
  3. Change the file permissions of the config file
    
    sudo chmod 600 /etc/default/activemq
    

Setting up Shared File System Master Slave

ActiveMQ can be configured to use a SAN for both the master and slave. The first machine up locks the file store as a Master. Any other machine that attempts to access the store will connect as a slave and take over if the master goes down. A more detailed explanation can be found here

http://activemq.apache.org/shared-file-system-master-slave.html

Setup the Shared File Store

  1. Point the ActiveMQ file store to a location on the SAN
    1. Open the config file
      
      sudo gedit /etc/default/activemq
      
    2. Find and update the line following line to point to the file store
      
      ACTIVEMQ_DATA="location to file store"
      
    3. Restart

Managing ActiveMQ

Monitoring ActiveMQ with the Admin utility

The queue can be monitored via the admin site. By default this will be

http://localhost:8161/admin

ActiveMQ Admin Page

ActiveMQ config file

If you followed Creating a Config script an ActiveMQ will look for a defaults script located in /etc/default/activemq. it can be used to modify various environment settings such as the data location.

ActiveMQ config script

/etc/default/activemq

Finding Broker Information

You can use the activemq-admin query command to display a lot of useful information such as the DataStore location for the specified instance. Not specifying an instance will use the default instance


sudo /opt/activemq/bin/activemq-admin query
Advertisements
  1. #1 by arralsvl on February 13, 2013 - 11:48 am

    Hi,
    would you please explain why is need to create qxtivemq user to use bash shell /bish/bash?

    thank you!

    Arvin

    • #2 by RBurnham on February 13, 2013 - 11:55 am

      I believe its to make it a bit more secure, if anyone got hold of that account they wouldn’t have access to everything.

  2. #3 by dsvanzyl on May 9, 2013 - 9:01 am

    I am failing to see where you start activemq with the user you created.

  3. #6 by Rick Nickle on May 17, 2014 - 3:46 pm

    Is this little bit here a typo?

    2.Add the following to the service configuration script/etc/init.d/activemqtrue

    + expand source

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: