This tutorial walks you through the process of deploying a Redis cluster on Ubuntu Server. The instructions work on all clouds supported by Juju—even bare metal servers—but this tutorial includes specific instructions to deploy the cluster to AWS, Google Compute Platform or Azure.
You will be able to configure the exact scale that you require and deploy it into any region supported by each cloud.
What you’ll learn
- Deploy a Redis cluster
- Tweak the cluster’s settings to add authentication
- Test our deployment
What you’ll need
- Juju installed (install it by running
snap install juju --claasicor by following the instructions on the Juju documentation)
- (Optional) An Ubuntu SSO account (visit login.ubuntu.com to create one)
- (Optional) Credential information for AWS, GCP or Azure (created when you create an account with your preferred cloud provider)
Looking for a fully hosted solution? Use Juju as a Service (JAAS)
JAAS is a hosted service provided by Canonical, the company behind Ubuntu. It’s a “Juju controller” for free. The Juju controller talks to the cloud provider programmatically to provision machines and manage software deployments. Once they’re online, the controller then installs the software that we care about: Redis. To use JAAS for this tutorial, create an account on jaas.ai and run ‘juju login jaas’ in a terminal.
How this tutorial is structured
The top of each step provides a command to be executed in the terminal window. Explanatory text then follows for people who want to know more.
To open a terminal window in Ubuntu, open the Terminal app or holding
A “model” is Juju a term to describe a logical service made up applications. A model might represent a whole web app, including its web server, databases and work queues.
For our purposes, our Redis cluster will make up the entire model. We’ll use the name
To create the model on AWS, use the following command:
juju add-model redis-cluster-tutorial aws/us-west-1
Where can I deploy my model?
The command at the top of this page uses the “US West 1” region from the AWS cloud provider by specifying
To get a list of cloud providers and supported regions, just omit that argument from the command:
juju add-model redis-cluster-tutorial
Why am I being asked to sign in?
juju add-model command will probably launch a browser window asking you to log in.
Juju (and JAAS) need to be granted permission to act on your behalf. Juju works by talking to the cloud provider programmatically. This login process confirms that you’re willing to delegate authority to Juju to do so.
Deploy a multi-node Redis cluster
To install Redis, we’ll use the
juju deploy command.
juju deploy works with the model that we’ve just defined to install software there.
Enter this command in the command line:
juju deploy cs:~omnivector/redis \ --config cluster-enabled=true \ --constraints 'mem=4G' \ --num-units 3
Explaining the syntax
That command can be a little confusing if you haven’t encountered Juju before. Here is an explanation of each part of the command that you used:
||This is the charm that we're deploying. It is made up of the parts "
||Sets the configuration option
||Specify that the virtual machines that we want Juju to deploy on our behalf have at least 4GB of RAM.|
||Set the desired scale of our cluster to be 3 virtual machines|
It’s important to include the option
--config cluster-enabled. Without it, three independent Redis instances will be deployed.
Use whatever scale you want
If you would like to use a 5 node cluster, for example, change the
--num-units option to 5. The
--contraints option can also be tweaked.
What is a charm?
A charm is software that deploys other software and makes it easy to maintain. The
cs:~omnivector/redis charm has its own website.
What is “Omnivector”?
cs:~omnivector/redis is the Juju Charm Store account for Omnivector Solutions. Omnivector Solutions is a commercial enterpise based in the Oregon, USA. From their website:
Omnivector is a member of the Juju Experts program. Their team has written the Redis charm that we’re deploying and released it as open source software.
Wait for Redis to be deployed
juju status command provides a live view of what is happening behind the scenes.
Will eventually produce an output similar to this:
Model Controller Cloud/Region Version SLA Timestamp redis-cluster-tutorial jaas aws/us-west-1 2.6.8 unsupported 16:54:19+13:00 App Version Status Scale Charm Store Rev OS Notes redis 5.0.5 active 3 redis jujucharms 25 ubuntu Unit Workload Agent Machine Public address Ports Message redis/0* active idle 0 184.108.40.206 6379/tcp successfully clustered redis/1 active idle 1 220.127.116.11 6379/tcp successfully clustered redis/2 active idle 2 18.104.22.168 6379/tcp successfully clustered Machine State DNS Inst id Series AZ Message 0 started 22.214.171.124 i-0924efebda490847f bionic us-west-1b running 1 started 126.96.36.199 i-0865d0af27dae812f bionic us-west-1c running 2 started 188.8.131.52 i-037f8bdc3cf0b3d22 bionic us-west-1b running
Once all of the workloads are in the “active” state, it’s time to move on.
Hint: use the watch command to avoid retyping
watch command enables you to repeatedly execute a command without needing to retype it. Try
watch -c -n5 juju status --color
Add password authentication and enable TCP Keep Alive
Redis is now installed and working correctly. Well done! You’re now able to tweak the deployment.
Add authentication password
To require that Redis clients specify a password when they execute commands, use the
juju config command. The command supports setting multiple options at the same time by adding additional setting=value pairs.
juju config redis password=password123
Increase TCP Keep Alive parameter
Use the same command with different arguments to increase the TCP Keep Alive connection settings.
juju config redis tcp-keepalive=30
Expose the Redis cluster to the Internet
Our Redis cluster is now ready. To make it accessible to the Internet, enter this command in the terminal:
juju expose redis
juju expose command talks to the cloud’s firewall systems to make them publicly accessible.
To test that everything is functional, we’ll use the Redis command line tools:
Install the Redis CLI command:
apt to install the Redis CLI client
sudo apt install -y redis-tools
Find the public address of one of the nodes
To know where to ping, we’ll make use of the output from
juju status again.
juju status --format=oneline
This command will spend a moment or two probing the model, then report something similar to this:
- redis/0: 184.108.40.206 (agent:idle, workload:active) 6379/tcp - redis/1: 220.127.116.11 (agent:idle, workload:active) 6379/tcp - redis/2: 18.104.22.168 (agent:idle, workload:active) 6379/tcp
Ping the cluster
With the Redis CLI installed and a host to connect to, let’s send the
redis-cli -h 22.214.171.124 ping;
With some luck, it will produce this encouraging response:
Redis is installed and active in the cloud.
We recommend creating an account at the Juju Discourse forum. That’s the best place to ask any questions.