High availability on two VMs
The installation most sites ask for: two VMs, each running an engine and nexus-proxy, over one
state directory exported by an NFS server, with one virtual address that clients call. This page is
the procedure, in the order it runs. Why two engines can share one state directory, and what happens
when one is lost, is in
Running more than one engine; what the process that
carries the virtual address does is in The virtual address.
The shape
Two VMs, A and B. On each, nexus-proxy listens on 443, an engine on 9090, and the --vrrp
process carries the virtual address. Each proxy balances over both engines, so a proxy whose own
engine is down still serves through the other VM’s engine. One NFS server exports the state
directory to both VMs. The virtual address is held by one VM at a time, the one VRRP elects, and
moves to the other when that VM or its proxy stops answering. The page uses these example addresses
throughout: A 10.0.0.11, B 10.0.0.12, the virtual address 10.0.0.10, the NFS server
10.0.0.5, and the name api.example.org resolving to 10.0.0.10 in the client’s DNS. On a site
that also serves IPv6, the IPv6 virtual address is 2001:db8::10, in the name’s AAAA record,
carried by a second --vrrp process on each VM. A and B are the engine addresses the
proxy’s configuration already uses, so that
block runs as written.
The dashed outline marks the single point that this page does not install: the NFS server.
What stays single
The NFS server remains a single point of failure: with it gone, no request is served, whatever the state of the engines. Making it redundant is outside this page.
The virtual address needs two things from the network: both VMs on one layer-2 segment, and IP
protocol 112 to 224.0.0.18 allowed between them (for IPv6, to ff02::12, together with ICMPv6
Neighbor Advertisements). If it is filtered, both VMs hold the address at once and clients reach
either at random; see The network it needs.
The procedure
Run every step as root. Each heading says on which VM it runs.
On both VMs: the kit
Verify the kit as Verifying a kit, offline says, then extract it.
On both VMs: the account
Run the block of The same account on both hosts
with the same <uid> and <gid> on both VMs, then the rest of the block of
The service account and its configuration
as written.
On both VMs: the shared state directory
Add this line to /etc/fstab:
10.0.0.5:/srv/nexus /var/lib/nexus nfs4 hard,vers=4.1,_netdev 0 0/srv/nexus is an example export path; /var/lib/nexus is the
state directory. The options hold hard and
vers=4.1, and neither soft nor nolock; _netdev makes systemd mount it after the network is
up. Then run mount /var/lib/nexus, and findmnt /var/lib/nexus shows the export mounted there.
Why each option is needed is in
What the filesystem has to support;
why the engine does not start without the mount is in
The engine waits for its mount.
On both VMs: the engine
Run the blocks of The state directory and
A service unit as written, then
systemctl edit nexus and write this drop-in:
[Service]ExecStart=ExecStart=/opt/nexus/nexus serve --host 0.0.0.0 --port 9090 --db /var/lib/nexus/registry.db --trusted-proxy 10.0.0.11 --trusted-proxy 10.0.0.12It is the drop-in of
Each engine listens for the proxy and trusts it
with another trusted list. Each proxy connects to the engines from its VM’s own address, to the
engine on its own VM included, so both VM addresses are trusted on both engines. The virtual
address is added as a /32 and is never the source of those connections. Check the address a VM
connects from with ip route get <other VM address>: the src it prints is the one to list if it
differs from the example. Allow port 9090 on each VM only from 10.0.0.11 and 10.0.0.12, with
the host’s firewall.
On VM A only: the state key and the first tenant, key and UI account
If a flow needs a state key, generate it once, on A, as
The state key, if any flow needs one
says, and write it into A’s /etc/nexus/nexus.env as NEXUS_SECRET_NEXUS_STATE_KEY=<key>. Start
A’s engine with systemctl enable --now nexus: enable starts it again when the VM restarts, as
the proxy’s unit is started. Then make the first tenant, key and UI account on A, as
The first tenant, key and UI account, once
says.
On VM B: the same state key, then the engine
Copy the NEXUS_SECRET_NEXUS_STATE_KEY line from A’s /etc/nexus/nexus.env into B’s; do not
retype it. Then start B’s engine with systemctl enable --now nexus. A different key is refused
at start while A’s engine runs (see the state key lock in
What is elected, and what is merely serialised).
Create no tenant, key or UI account on B.
On both VMs: nexus-proxy
Run the blocks of On Linux, from the kit,
The configuration and
The unit, each as written, with one addition to the
configuration: "status_listen": "127.0.0.1:9100", the address the virtual address checks. On both
VMs the configuration’s engines are the two VM addresses. Both proxies serve the same certificate
and key, issued for api.example.org. The listen stays 0.0.0.0:443, so the proxy receives on
the virtual address whichever VM holds it; a listen on one address would not. On a site that also
serves IPv6, the listen is "listen": "[::]:443", which receives on both families.
On both VMs: the virtual address
Run the blocks of The account and the file,
IPv4 and
The unit, each as written on A; on B with two
substitutions in the file, "priority": 100 and "peer": "10.0.0.11". Then allow VRRP from the
other VM, on A:
nft add rule inet filter input ip saddr 10.0.0.12 ip daddr 224.0.0.18 ip protocol vrrp acceptOn B the same line names 10.0.0.11. Then run systemctl enable --now nexus-vrrp@v4 on both VMs,
A first.
On a site that also serves IPv6, run the block of IPv6
as written on A, and on B with "priority": 100 and "peer" set to A’s link-local address, which
ip -6 addr show dev eth0 scope link on A prints. On A, allow VRRP from B’s link-local address:
nft add rule inet filter input ip6 saddr <B's link-local> ip6 daddr ff02::12 meta l4proto vrrp acceptOn B the same line names A’s. Then run systemctl enable --now nexus-vrrp@v6 on both VMs, A first.
With preempt true, its default, A takes the
address back when it returns. Set it to false on both VMs to leave the address where it is.
The check
From a machine on the VMs’ segment:
curl --resolve api.example.org:443:10.0.0.11 https://api.example.org/healthcurl --resolve api.example.org:443:10.0.0.12 https://api.example.org/healthcurl --resolve api.example.org:443:10.0.0.10 https://api.example.org/healthAll three answer 200, and ip -4 addr show on A lists 10.0.0.10 while on B it does not. With
VM A stopped, the request to 10.0.0.10 answers 200 and B lists the address; with A started
again, A lists it again. On an IPv6 site, check the same with [2001:db8::10] and
ip -6 addr show. --resolve sends the request to one address under the certificate’s name, so
the check does not depend on DNS.
The name
api.example.org resolves to 10.0.0.10 (A) in the client’s DNS and, on an IPv6 site, to
2001:db8::10 (AAAA).