[How-To] Install Keycloak on Ubuntu 24 LTS VM
Purpose
This document will step by step explain the installation process for Keycloak on a Ubuntu 24 LTS VM.
Prerequisites
List of prerequisites:
- Sudo user
- Ubuntu 24 LTS VM
Keycloak Installation on Ubuntu 24.04 (Step-by-Step Guide)
Step 1: Prepare the Ubuntu VM
Ensure your Ubuntu VM is up to date and has the necessary packages installed:
sudo apt update && sudo apt upgrade -y sudo apt install -y unzip curl nano wget gnupg2 software-properties-common
Step 2: Install Java (Required for Keycloak)
Keycloak requires Java 17+. Install OpenJDK 17:
sudo apt install -y openjdk-17-jdk
Verify installation:
java -version
You should see output similar to:
openjdk version "17.0.9" ...
Step 3: Install PostgreSQL (Recommended Database)
Keycloak supports PostgreSQL, MariaDB, and H2 (not recommended for production). Install PostgreSQL:
sudo apt install -y postgresql postgresql-contrib
Start and enable PostgreSQL:
sudo systemctl enable --now postgresql
Set up a database for Keycloak:
Inside the PostgreSQL shell, run:
✅ This creates a database and user for Keycloak.
Step 4: Install Keycloak
Download and extract Keycloak (replace version as needed):
sudo wget https://github.com/keycloak/keycloak/releases/download/24.0.1/keycloak-24.0.1.tar.gz tar -xvzf keycloak-24.0.1.tar.gz
sudo mv keycloak-24.0.1 /opt/keycloak
Create a dedicated Keycloak system user:
Step 5: Configure Keycloak to Use PostgreSQL
Edit Keycloak’s configuration file:
Add the following:
Save and exit.
Step 6: Create a Systemd Service for Keycloak
Create a new service file:
Add the following:
Save and exit.
Reload systemd:
Enable and start Keycloak:
Check status:
✅ Keycloak should now be running!
Step 7: Create an Admin User
Run the following command to create an admin account:
/opt/keycloak/bin/kcadm.sh config credentials --server http://localhost:8080 --realm master --user admin --password admin
(Replace "admin" and "admin" with your desired username and password.)
Step 8: Access the Web UI
- Open a browser and go to:
http://your-server-ip:8080
- Click "Administration Console" and log in with the admin user you created.
✅ Keycloak is now set up and running!
High Availability (HA) & Redundancy Setup
Later, if you want Keycloak redundancy, follow these steps:
-
Deploy a Second Keycloak VM
- Repeat the setup on another Ubuntu VM.
-
Use a Shared PostgreSQL Database
- Instead of using local PostgreSQL, connect both Keycloak VMs to a shared external PostgreSQL instance.
-
Deploy HAProxy as a Load Balancer
- Install HAProxy on a separate VM and configure it to balance traffic between the two Keycloak servers.
-
Enable Keycloak Clustering (Optional, for Sticky Sessions)
- Set up Keycloak with sticky sessions using Infinispan or JDBC persistent sessions.
Final Thoughts
For now, a single VM setup is great. If you want HA later, you’ll just need:
- A second VM running Keycloak
- An external PostgreSQL instance
- HAProxy for load balancing
No Comments