You stood up a Nomad cluster last week. Every job spec ends with a service stanza that lists “consul” as the registry, but you never actually deployed Consul — the agents are pointing at a placeholder address. Jobs are running, the UI shows them green, and an internal service that depends on calling another internal service by its DNS name silently falls back to a hard-coded IP that the team has been “meaning to remove for ages.” This article is the missing step: a three-server Consul cluster on AlmaLinux 9 that Nomad treats as the source of truth for service discovery, DNS, and health-check state.
What’s happening
Consul is two things in one binary. It’s a key-value store backed by Raft — the same consensus algorithm Nomad uses for its own state — and it’s a service catalog where every agent on every node registers the services it runs, with their health-check definitions. The agents gossip with each other via Serf to maintain membership; the servers run Raft to agree on cluster state. Three servers is the minimum quorum. Beyond that, every machine that runs workloads runs a Consul client agent that talks to the servers over RPC and answers DNS queries for *.service.consul on UDP/TCP 8600.
The handoff to Nomad is via the consul block in nomad.hcl: Nomad’s agent registers itself with Consul as a service, every job’s service stanza becomes an entry in the Consul catalog, and Consul’s health-check engine probes each instance and reports up/down. Applications resolve web.service.consul via the local Consul agent’s DNS port and get back the IPs of all healthy instances. When an instance fails its health check, it disappears from the DNS response within seconds — no orchestration needed on the client side. This is the difference between a Nomad cluster that runs jobs and a Nomad cluster that runs a service-discovery-aware platform.
How to verify
Healthy three-server Consul cluster:
consul members
# Node Address Status Type Build Protocol DC Partition Segment
# consul-s01 10.20.0.31:8301 alive server 1.17.3 2 dc1 default <all>
# consul-s02 10.20.0.32:8301 alive server 1.17.3 2 dc1 default <all>
# consul-s03 10.20.0.33:8301 alive server 1.17.3 2 dc1 default <all>
All three alive, all type server. Add any client agents you joined.
Raft state:
consul operator raft list-peers
# Node ID Address State Voter RaftProtocol
# consul-s01 abc... 10.20.0.31:8300 leader true 3
# consul-s02 def... 10.20.0.32:8300 follower true 3
# consul-s03 ghi... 10.20.0.33:8300 follower true 3
Exactly one leader. All three voters.
Service registration round-trip — register a dummy service, query it via DNS, deregister:
# Register
consul services register -name=demo -port=8080 \
-tag="env=dev" -check="{\"http\":\"http://127.0.0.1:8080/\",\"interval\":\"10s\"}"
# DNS lookup against local agent
dig @127.0.0.1 -p 8600 demo.service.consul +short
# Should return one or more IPs
# SRV with port
dig @127.0.0.1 -p 8600 demo.service.consul SRV +short
# 1 1 8080 hostname.node.dc1.consul.
If DNS responds with NXDOMAIN, the agent isn’t bound on 8600 or the recursor chain is misconfigured. If DNS responds but the IPs are wrong, an agent registered the service with an incorrect bind address.
Nomad ↔ Consul integration is live if Nomad shows up in the Consul catalog:
consul catalog services
# consul
# nomad
# nomad-client
The presence of nomad and nomad-client confirms Nomad’s auto_advertise worked.
The fix
The installer below targets the three server nodes. For client nodes (which co-locate with your Nomad clients), use the same script with SERVER_NODE=false — the agent ports, gossip key, and ACL bootstrap line all flip accordingly. The script handles base OS hardening (SELinux enforcing, firewalld, fail2ban, dnf-automatic), HashiCorp YUM repository, Consul 1.17 install, gossip key, TLS files, ACL bootstrap, and a systemd unit that survives a consul reload.
Generate the gossip key and CA on a workstation first:
# On your workstation
consul keygen
# Save output
# CA + per-node certs
consul tls ca create
consul tls cert create -server -dc=dc1 -domain=consul
consul tls cert create -client -dc=dc1 -domain=consul
# Distribute consul-agent-ca.pem, dc1-server-consul-*.pem to servers
# Distribute consul-agent-ca.pem, dc1-client-consul-*.pem to clients
Then the server installer:
#!/usr/bin/env bash
set -euo pipefail
### AlmaLinux 9 Consul 1.17 server installer
### Run on each of the 3 server nodes after editing the variables below
### Assumes consul-agent-ca.pem + per-node certs present at /etc/consul.d/tls/
if [[ "$(id -u)" -ne 0 ]]; then
echo "Run as root."
exit 1
fi
# === EDIT PER NODE ===
NODE_NAME="consul-s01"
NODE_IP="10.20.0.31"
PEER_IPS=("10.20.0.31" "10.20.0.32" "10.20.0.33")
DATACENTER="dc1"
GOSSIP_KEY="REPLACE_WITH_CONSUL_GOSSIP_KEY"
SERVER_NODE=true # set to false for client-only agents
# =====================
echo
echo "========================================"
echo "Consul ${NODE_NAME} (${NODE_IP})"
echo "========================================"
echo
echo "==> Base OS update"
dnf -y update
dnf -y install epel-release
dnf -y install vim curl wget chrony fail2ban dnf-automatic \
policycoreutils-python-utils lsof tcpdump bind-utils tar gzip \
iproute net-tools jq socat firewalld unzip
systemctl enable --now chronyd
echo "==> SELinux enforcing"
sed -i 's/^SELINUX=.*/SELINUX=enforcing/' /etc/selinux/config
setenforce 1 || true
echo "==> firewalld"
systemctl enable --now firewalld
firewall-cmd --permanent --add-port=8300/tcp # RPC
firewall-cmd --permanent --add-port=8301/tcp # Serf LAN
firewall-cmd --permanent --add-port=8301/udp
firewall-cmd --permanent --add-port=8302/tcp # Serf WAN (servers)
firewall-cmd --permanent --add-port=8302/udp
firewall-cmd --permanent --add-port=8500/tcp # HTTP API
firewall-cmd --permanent --add-port=8501/tcp # HTTPS API
firewall-cmd --permanent --add-port=8600/tcp # DNS
firewall-cmd --permanent --add-port=8600/udp
firewall-cmd --reload
echo "==> SSH hardening"
sed -i 's|^[#[:space:]]*PermitRootLogin.*|PermitRootLogin prohibit-password|' /etc/ssh/sshd_config
sed -i 's|^[#[:space:]]*PasswordAuthentication.*|PasswordAuthentication no|' /etc/ssh/sshd_config
sshd -t && systemctl restart sshd
echo "==> fail2ban + dnf-automatic"
cat > /etc/fail2ban/jail.d/sshd.local <<'FAIL2BAN'
[sshd]
enabled = true
port = ssh
backend = systemd
maxretry = 4
findtime = 10m
bantime = 1h
FAIL2BAN
systemctl enable --now fail2ban
cat > /etc/dnf/automatic.conf <<'DNFAUTO'
[commands]
upgrade_type = security
random_sleep = 900
download_updates = yes
apply_updates = yes
[emitters]
emit_via = stdio
DNFAUTO
systemctl enable --now dnf-automatic.timer
echo "==> HashiCorp YUM repo"
dnf -y install dnf-plugins-core
dnf config-manager --add-repo https://rpm.releases.hashicorp.com/RHEL/hashicorp.repo
dnf -y install consul-1.17.3
echo "==> Pinning Consul"
dnf versionlock add consul || true
echo "==> Sysctl tweaks"
cat > /etc/sysctl.d/99-consul.conf <<'SYSCTL'
net.core.somaxconn = 4096
net.ipv4.tcp_max_syn_backlog = 8192
net.ipv4.ip_local_port_range = 10240 65535
fs.file-max = 2097152
SYSCTL
sysctl --system
echo "==> Consul config"
mkdir -p /etc/consul.d/tls /opt/consul
chown -R consul:consul /opt/consul
chmod 755 /etc/consul.d
chmod 700 /etc/consul.d/tls
# Expect already present at /etc/consul.d/tls/:
# consul-agent-ca.pem
# dc1-server-consul-0.pem
# dc1-server-consul-0-key.pem
# (or dc1-client-consul-* for client nodes)
chmod 600 /etc/consul.d/tls/*.pem || true
chown -R consul:consul /etc/consul.d/tls
if [[ "${SERVER_NODE}" == "true" ]]; then
SERVER_LINE='server = true'
BOOTSTRAP_LINE='bootstrap_expect = 3'
CERT_NAME='dc1-server-consul-0'
else
SERVER_LINE='server = false'
BOOTSTRAP_LINE=''
CERT_NAME='dc1-client-consul-0'
fi
cat > /etc/consul.d/consul.hcl <<EOF
datacenter = "${DATACENTER}"
node_name = "${NODE_NAME}"
data_dir = "/opt/consul"
log_level = "INFO"
bind_addr = "${NODE_IP}"
client_addr = "0.0.0.0"
advertise_addr = "${NODE_IP}"
${SERVER_LINE}
${BOOTSTRAP_LINE}
retry_join = [
"${PEER_IPS[0]}",
"${PEER_IPS[1]}",
"${PEER_IPS[2]}"
]
encrypt = "${GOSSIP_KEY}"
acl {
enabled = true
default_policy = "deny"
enable_token_persistence = true
down_policy = "extend-cache"
}
tls {
defaults {
ca_file = "/etc/consul.d/tls/consul-agent-ca.pem"
cert_file = "/etc/consul.d/tls/${CERT_NAME}.pem"
key_file = "/etc/consul.d/tls/${CERT_NAME}-key.pem"
verify_incoming = false
verify_outgoing = true
verify_server_hostname = true
}
internal_rpc {
verify_incoming = true
}
https {
verify_incoming = false
}
}
auto_encrypt {
allow_tls = true
}
ports {
http = 8500
https = 8501
grpc = 8502
dns = 8600
}
ui_config {
enabled = true
}
telemetry {
prometheus_retention_time = "60s"
disable_hostname = true
}
connect {
enabled = true
}
performance {
raft_multiplier = 1
}
EOF
chown -R consul:consul /etc/consul.d
chmod 640 /etc/consul.d/consul.hcl
echo "==> systemd unit"
cat > /etc/systemd/system/consul.service <<'CONSUL'
[Unit]
Description=Consul
Documentation=https://developer.hashicorp.com/consul
Requires=network-online.target
After=network-online.target
ConditionFileNotEmpty=/etc/consul.d/consul.hcl
[Service]
EnvironmentFile=-/etc/consul.d/consul.env
User=consul
Group=consul
ExecStart=/usr/bin/consul agent -config-dir=/etc/consul.d/
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process
KillSignal=SIGTERM
LimitNOFILE=65536
Restart=on-failure
RestartSec=5
TimeoutStopSec=60
[Install]
WantedBy=multi-user.target
CONSUL
systemctl daemon-reload
systemctl enable --now consul
echo "==> Waiting for Consul HTTP API (up to 60s)"
for i in {1..30}; do
if curl -fs "http://${NODE_IP}:8500/v1/status/leader" >/dev/null 2>&1; then
break
fi
sleep 2
done
echo
echo "========================================"
echo "DONE — ${NODE_NAME}"
echo "========================================"
echo
echo "Listeners:"
ss -lntp | grep -E ':(8300|8301|8302|8500|8501|8502|8600)\b' || true
echo
echo "Members (may be partial until peers are up):"
consul members 2>/dev/null || true
echo
echo "Next on the LAST server to come up (only once):"
echo " consul acl bootstrap"
echo "Save the SecretID. Then write an agent policy and an agent token for every node:"
echo " consul acl policy create -name agent-policy -rules @agent-policy.hcl"
echo " consul acl token create -policy-name agent-policy"
echo "And write that token into /etc/consul.d/consul-agent.token on each node."
After all three servers are up and gossip is converged, bootstrap ACLs from a single server — exactly once, irreversible:
export CONSUL_HTTP_ADDR=http://10.20.0.31:8500
consul acl bootstrap
# AccessorID: xxx
# SecretID: yyy <-- save this; it is the only management token until you create more
Lock that SecretID in the same secrets manager you used for the Nomad bootstrap token (a different one, ideally — Vault, see the next article). Create an agent policy with node "" { policy = "write" } plus service_prefix "" { policy = "write" }, generate a token, and write that token into /etc/consul.d/consul-agent.token on every node — that is the token the agent uses for its own catalog writes. Without it, the agent registers fine but cannot anti-entropy push corrections, and you will see stale entries persist after restarts.
Once Consul is up and ACLs are bootstrapped, point your Nomad servers’ consul.token field at a separate Nomad-specific Consul token (least privilege: catalog write on the nomad and nomad-client service prefixes), reload Nomad on each node, and watch consul catalog services light up.
We deploy this stack as the foundation for Nomad-based platforms under Managed Cloud Ops, with monitoring of Raft quorum and gossip health baked in — Cloud PaaS for the operated tier, or scoping call if you want us to plan the rollout.