Setup ActiveMQ Artemis on Ubuntu 18.04

Hasnat Saeed
5 min readJul 11, 2019

--

In this tutorial, we will setup Apache ActiveMQ Artemis 2.8.1 on Ubuntu 18.04.

Step 1 — Install JDK

Artemis requires Java 8 or later versions to work. We can check and verify that Java is installed with the following command.

$ java -version

If java is not installed run below commands to install Java.

$ sudo apt-get update$ sudo apt-get install default-jdk -y

After installation check, if java is installed correctly by executing below command:

$ java -version

If java is installed, the output should look similar to above depending upon what is the latest version of java at that time.

Step 2 — Creating an ‘Artemis’ User and Group

We should not run Artemis under the root user for security reasons. Let’s create a group artemis and add a user artemis to it. Additionally, we are going to install Artemis under /opt/artemis directory which will be artemis user home directory:

$ sudo groupadd artemis$ sudo useradd -s /bin/false -g artemis -d /opt/artemis artemis

Step 3 — Download and Install ‘Artemis’

Now we need to download and install Artemis. We can download the Artemis archive from its official download website or mirrors. Download and Install Artemis 2.8.1 archive file using the following commands. You can also visit the official download page to download the latest available version.

We are going to install Artemis to /opt directory. So we will download the Artemis 2.8.1 package to that location.

Change directory to /opt and download Artemis 2.8.1 to that directory.

$ cd /opt$ sudo wget https://archive.apache.org/dist/activemq/activemq-artemis/2.8.1/apache-artemis-2.8.1-bin.tar.gz

Extract the tar package and rename the extracted directory to artemis

$ sudo tar -xvzf apache-artemis-2.8.1-bin.tar.gz$ sudo mv apache-artemis-2.8.1 artemis

Step 4 — Change Permission and Ownership of the ‘Artemis’ Home Directory

Next, we will modify ownership and permission of /opt/artemis directory. We will also give executed permission to opt/artemis/bin/ directory.

sudo chown -R artemis: artemissudo chmod o+x /opt/artemis/bin/

Step 5 — Creating an Artemis Broker Instance

An Artemis broker instance is the directory containing all the configuration and runtime data, such as logs and data files, associated with a broker process. It is recommended that you do not create the instance directory under Artemis home directory i.e. /opt/artemis. This separation is encouraged so that we can more easily upgrade when the next version of ActiveMQ Artemis is released.

Let's create a broker instance under /var/lib/ directory. To create an instance run the following commands in your command line shell:

$ cd /var/lib$ sudo /opt/artemis/bin/artemis create test-broker

Once the above command is executed the user will be prompted to enter details fo default user and password as shown below. Provide the necessary details and continue.

A broker instance directory will contain the following subdirectories:

  • bin: holds execution scripts associated with this instance.
  • etc: hold the instance configuration files
  • data: holds the data files used for storing persistent messages
  • log: holds rotating log files
  • tmp: holds temporary files that are safe to delete between broker runs

As shown in the snapshot above, the broker instance can be started with the below command:

$ sudo /var/lib/test-broker/bin/artemis run

Once the broker instance starts we can access the admin console at http://localhost:8161/console.

However, the console is bound to localhost and cannot be accessed remotely!!

Step 6 — Making Artemis Admin Console Remotely Accessible

To be able to access Artemis admin console remotely, we have to edit the bootstrap.xml and jolokia-access.xml under /var/lib/test-broker/etc/ directory.

Open boostrap.xml

$ sudo nano /var/lib/test-broker/etc/bootstrap.xml

By default, Artemis admin console is bound to localhost only. To allow remote access edit the <web></web> tag and change the attribute value of bind to http://0.0.0.0:8161 as shown below:

Save and exit.

We also need to enable CORS, so edit jolokia-access.xml

$ sudo nano /var/lib/test-broker/etc/jolokia-access.xml

Edit the <allow-origin></allow-origin> tag as shown below:

Save and exit.

We can now access Artemis admin console remotely once it starts.

Step 7— Creating a SystemD Service File for Artemis

To install Artemis as a system service we will create a file called artemis.service in the /etc/systemd/system directory.

$ sudo nano /etc/systemd/system/artemis.service

Add the following to artemis.service file

[Unit]Description=Apache ActiveMQ Artemis
After=network.target
[Service]Type=forking
User=artemis
Group=artemis
ExecStart=/var/lib/test-broker/bin/artemis-service start
ExecStop=/var/lib/test-broker/bin/artemis-service stop
UMask=0007
RestartSec=10
Restart=always
[Install]WantedBy=multi-user.target

Save and exit. We also need to make artemis user owner of the test-broker directory.

$ sudo chown artemis: /var/lib/test-broker

Restart systemctl daemon.

$ sudo systemctl daemon-reload

To start the artemis service.

$ sudo systemctl start artemis

To monitor the Artemis log file.

$ sudo tail -f /var/lib/test-broker/log/artemis.log

If there is no error, you will get similar to below output:

To enable Artemis service on system boot:

$ sudo systemctl enable artemis

We can now access Artemis admin console at:

http://<public-ip>:8161/console/

Enter the user and password as configured in Step 5.

This concludes our tutorial on setting Apache ActiveMQ Artemis on Ubuntu 18.04.

Please feel free to comment. Thanks.

Important Links:

https://activemq.apache.org/components/artemis/

https://activemq.apache.org/components/artemis/documentation/

--

--