Key | Value |
---|---|
Summary | RabbitMQ offers reliable, fast messaging. |
Categories | deploy-applications |
Difficulty | 4 |
Author | Tim McNamara tsm@canonical.com |
Introduction
Reliable, fast messaging is integral to all complex application stacks. RabbitMQ is an implementation of the AMQP protocol that offers both.
This tutorial takes you through the process of installing RabbitMQ in a high-availability RabbitMQ cluster on Ubuntu Server using Juju.
Traditionally, the initial install process has felt brittle and difficult. By the end of this tutorial, it shouldnât feel like that anymore.
Requirements
Duration: 5:00
Juju software
This tutorial assumes that you have installed Juju and registered your security credentials.
If you are new to Juju, consider our Getting Started with Juju tutorial.
Running controller
Duration 5:00
You should have access to a live Juju controller. This can be achieved in 2 ways:
- Run
juju login jaas
to make use of the Canonical-hosted controller. This service is offered at no cost, but credentials are provided to Canonical. - Run
juju bootstrap
. This option may incur hosting costs, but the controller runs fully in your control.
Add a Juju model
Duration 1:00
The Juju âmodelâ is a workspace for inter-related applications. It houses machines, containers, applications, and other components such as firewall rules.
To add a model to the controller, run the juju add-model
command followed by the model name. You may name your model anything you want. Below we call it âmessagingâ.
$ juju add-model messaging
Deploy RabbitMQ
Duration: 5:00
The juju deploy
command deploys charms. A charm is managed software, that is, software enriched with all the operational know-how for it to function well in the cloud. The rabbitmq-server
charm is managed RabbitMQ.
$ juju deploy rabbitmq-server -n3 --config min-cluster-size=3 rabbitmq
The rabbitmq-server
charm is managed RabbitMQ that works with every OpenStack installation managed by Canonical.
Configure users
Duration: 6:00
Juju provides the ability to interact with our cluster without knowing the host IP addresses beforehand. One of the units of the rabbitiq-server
charm thatâs been deployed is designated as the âleaderâ.
The juju exec --unit <application>/leader
syntax enables commands to be executed on the host itself. The connection information is resolved by Juju.
Remove the guest user account
RabbitMQ comes with a default user account with the username guest
and the password guest
. In production environments, this account should be removed. This can be done via the rabbitmqctl delete_user
command.
$ juju exec --unit rabbitmq/leader 'rabbitmqctl delete_user guest'
Add other user accounts
To add a new user account to RabbitMQ, use the rabbitmqctl add_user
command. Below we use it to add a user account called demo
.
$ export RABBIT_PASSWORD=$(head -c20 /dev/urandom | hex)
$ juju exec --unit rabbitmq/leader "rabbitmqctl add_user demo $RABBIT_PASSWORD"
To add any user tags, provide them to the rabbitmqctl set_user_tags
command:
$ juju exec --unit rabbitmq/leader "rabbitmqctl set_user_tags demo administrator"
Add virtual host(s)
Duration: 2:00
Virtual hosts (vhosts) are the primary mechanism through which access control is enforced with RabbitMQ. To create a virtual host, simply use the rabbitmqctl add_vhost
command. Below we use it to create a virtual host called âvh1
â.
$ juju run --unit rabbitmq/leader "rabbitmqctl add_vhost vh1"
Users are provided with permissions to specific vhosts via the rabbitmqctl set_permissions
command:
$ juju run --unit rabbitmq/leader "rabbitmqctl set_permissions -p 'vh1' 'demo' '.*' '.*' '.*'"
Declare exchange(s)
Duration: 2:00
An AMQP exchange is a message routing construct, created in RabbitMQ with the rabbitmqadmin
command. You can use Juju to access this:
$ juju run --unit rabbitmq/leader "rabbitmqadmin --vhost=vh1 declare exchange name=hub type=fanout -u demo -p $RABBIT_PASSWORD"
(Optional) Enable management plugin
Duration: 2:00
The RabbitMQ management plugin enables a monitoring dashboard.
Enable the dashboard
The rabbitmq-plugins
command can enable the management plugin for your cluster.
$ juju run --unit rabbitmq/leader "rabbitmq-plugins enable rabbitmq_management"
Access the dashboard from the Internet
To access the management dashboard from the Internet, ask Juju to open the firewall:
$ juju exec --unit rabbitmq/0 'open-port 15672'
$ juju expose rabbitmq