How to Install Apache ActiveMQ on CentOS 7
Apache ActiveMQ is a free and open source message broker and integration pattern server. It supports many cross language clients and protocols from JAVA, C++, C, Python, Perl, PHP etc. It provides many features such as Message Groups, Virtual Destinations, Wildcards and Composite Destinations etc. It can be easily integrated to spring applications.
In this tutorial, we will install Apache ActiveMQ on CentOS 7 server.
- Minimal CentOS 7 server
- Root privileges. This guide is written as the root user, if you are logged in as sudo user, run sudo -i.
Update Base System
Before installing any package it is recommended that you update the packages and repository using the following command.
yum -y update
Once your system is updated, proceed further to install JAVA.
ActiveMQ supports both OpenJDK and Oracle JAVA, in this tutorial we will install the latest version of Oracle Java into the server. Run the following command to download the RPM package.
wget –no-cookies –no-check-certificate –header “Cookie:oraclelicense=accept-securebackup-cookie” “http://download.oracle.com/otn-pub/java/jdk/8u131-b11/d54c1d3a095b4ff2b6607d096fa80163/jdk-8u131-linux-x64.rpm”
If you do not have wget installed, you can run the yum -y install wget to install wget. Now install the downloaded RPM using the following command.
yum -y localinstall jdk-8u131-linux-x64.rpm
You can now check the Java version using the following command.
You will get the following output.
[[email protected] ~]# java -version java version "1.8.0_131" Java(TM) SE Runtime Environment (build 1.8.0_131-b11) Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode)
You will also need to check if JAVA_HOME environment variable is set. Run the following command for same.
If you get a null or blank output, you will need to manually set the JAVA_HOME variable. Edit the .bash_profile file using your favourite editor. In this tutorial, we will use nano editor. Run the following command to edit .bash_profile using nano.
Now add the following lines at the at the end of the file.
export JAVA_HOME=/usr/java/jdk1.8.0_131/ export JRE_HOME=/usr/java/jdk1.8.0_131/jre
Now source the file using the following command.
Now you can run the echo $JAVA_HOME command again to check if the environment variable is set or not.
[[email protected] ~]# echo $JAVA_HOME /usr/java/jdk1.8.0_131/
ActiveMQ provides binaries for Unix systems which are precompiled and can be used directly. The only required dependency was to install JAVA into the system. As we have installed JAVA we can proceed further to download ActiveMQ.
If you do not have wget installed, you can run yum -y install wget. You can always find the link to the latest version on ActiveMQ download page.
Extract the archive using the following command.
tar -zxvf apache-activemq-*-bin.tar.gz -C /var
Change the name of the ActiveMQ directory for the sake of simplicity by running.
mv /var/apache-activemq-*/ /var/activemq/
ActiveMQ is now installed on your system.
Change your current directory to ActiveMQ installation directory.
You can immediately start ActiveMQ as a foreground process by running the following command.
To start ActiveMQ as background process, run:
You should get the following output if started successfully.
[[email protected] activemq]# ./bin/activemq start INFO: Loading '/var/activemq//bin/env' INFO: Using java '/usr/java/jdk1.8.0_131//bin/java' INFO: Starting - inspect logfiles specified in logging.properties and log4j.properties to get details INFO: pidfile created : 'https://websetnet.b-cdn.net/var/activemq//data/activemq.pid' (pid '27680')
To stop ActiveMQ, you can run the following command.
Creating Systemd Service
Although you can easily run ActiveMQ using the commands above, it is recommended to use a systemd service for managing ActiveMQ process. Using Systemd service will ensure that ActiveMQ will start automatically at boot time and failures.
Create a systemd service file using your favorite text editor. In this tutorial, we will be using nano editor. If you do not have nano installed, you can run yum -y install nano.
Now populate the file with the following content.
[Unit] Description=ActiveMQ service After=network.target [Service] Type=forking ExecStart=/var/activemq/bin/activemq start ExecStop=/var/activemq/bin/activemq stop User=root Group=root Restart=always RestartSec=9 StandardOutput=syslog StandardError=syslog SyslogIdentifier=activemq [Install] WantedBy=multi-user.target
Now you can start ActiveMQ using:
systemctl start activemq
To configure ActiveMQ to automatically start at boot time, use.
systemctl enable activemq
To check if ActiveMQ service is started correctly, you can run the following command to check the status of the ActiveMQ service.
systemctl status activemq
You should get output similar to shown below.
? activemq.service - ActiveMQ service Loaded: loaded (/etc/systemd/system/activemq.service; enabled; vendor preset: disabled) Active: active (running) since Sat 2017-07-15 17:05:24 UTC; 6s ago Process: 28815 ExecStart=/var/activemq/bin/activemq start (code=exited, status=0/SUCCESS) Main PID: 28867 (java) CGroup: /system.slice/activemq.service ??28867 /usr/bin/java -Xms64M -Xmx1G -Djava.util.logging.config.file=logging.properties -Djava.security.auth... Jul 15 17:05:24 centos systemd: Starting ActiveMQ service... Jul 15 17:05:24 centos activemq: INFO: Loading '/var/activemq//bin/env' Jul 15 17:05:24 centos activemq: INFO: Using java '/usr/bin/java' Jul 15 17:05:24 centos activemq: INFO: Starting - inspect logfiles specified in logging.propertie...tails Jul 15 17:05:24 centos activemq: INFO: pidfile created : 'https://websetnet.b-cdn.net/var/activemq//data/activemq.pid' (pid '28867') Jul 15 17:05:24 centos systemd: Started ActiveMQ service.
Using Admin Web Panel
To access the administrative panel of ActiveMQ, start the ActiveMQ service. Using your favourite web browser, open the following URL.
If you have firewalld installed, you will have to allow port 8161 through the firewall. Run the following command for same.
firewall-cmd –zone=public –permanent –add-port=8161/tcp
The initial username and password for Apache ActiveMQ are admin and admin. Once you are logged in, you will see the following interface.
You should change your password as soon as you are logged in.
You can now use Apache ActiveMQ server to manage the communication between multiple clients and servers. You can learn more about Apache ActiveMQ by going to ActiveMQ site.