# DMZs and servers as one cluster

In a [cluster](High-Availability.md), several servers can feed the same [DMZ](DMZ.md) at the same time, and several DMZs can stand behind one load balancer that sends each request wherever it likes. Whichever DMZ and whichever server a request reaches, it runs on the user's own session. A load balancer no longer has to keep a user on one DMZ.

```
  one DMZ, two servers                         two DMZs, two servers

          +-------+                             load balancer (no stickiness)
          |  DMZ  |                              /                    \
          +--^-^--+                        +-------+              +-------+
             | |                           | DMZ 1 |              | DMZ 2 |
      +------+ +------+                    +--^-^--+              +--^-^--+
      |               |                       | |  \            /    | |
 +----+-----+   +-----+----+                  | +---\----------/-----+ |
 | Server 1 |<->| Server 2 |              +---+------+          +------+---+
 +----------+   +----------+              | Server 1 |<-------->| Server 2 |
                                          +----------+          +----------+
```

The arrows point at who is dialed: a server always opens the link to its DMZ. The servers are members of one cluster and replicate users and settings. Every DMZ is [paired](DMZ-Pairing.md), and every server is one of its servers.

## One DMZ, two servers

Pair the DMZ from one server. On the other server, make a DMZ port for the same DMZ; in **Pair a DMZ** it offers **Link to a DMZ paired already**, which needs no code: the DMZ knows that server as a member of the cluster. See [Pairing a DMZ](DMZ-Pairing.md#a-second-server-for-the-same-dmz).

Both servers then keep a link to the DMZ at the same time, and neither takes it from the other.

**Its settings.** The DMZ runs with the settings of the server that linked it first, its **primary**. The others send theirs too; the DMZ answers them and sets them aside, so two servers never take turns. Change a DMZ's settings on its primary: replication brings the change to the other servers, and the DMZ takes it from the primary. When the primary goes away, the next server becomes the primary and sends its settings.

**Where each request goes.** The DMZ decides, for each thing it asks of a server:

| What | Goes to |
|---|---|
| a user's file listing, upload, download, share, User Options | the server that holds that user's session. The DMZ asks the servers once which one it is, and remembers. |
| a sign-in and the account lookup that follows it | the server the user name picks. Every DMZ picks the same server for the same name while the same servers are up, so the code a user is asked for and the code they type, or a passkey's question and its answer, reach the same server. |
| a password reset link | the server that made the link |
| anything else: mail, alerts, status | the primary |

**Its log.** With the DMZ's log sent to the server (`dmz_log_in_internal_server`), every server gets every line.

**On the Cluster page** the DMZ's tile reads **Fed by 2 servers**, and its detail lists them. See [The map and the node detail](Cluster-Map.md).

## Two DMZs, two servers

Each server has a DMZ port for each DMZ and links both. The load balancer spreads users over the DMZs as it likes; stickiness is not needed.

A user's web session lives on the DMZ that signed them in. When a request of that user reaches the other DMZ, that DMZ asks its servers which DMZ holds the session, and the request runs there, carried over the links the servers already have to both DMZs. The answer comes back the same way. The user notices nothing.

Nothing new is opened for this: the DMZs never talk to each other directly, so there is no firewall rule between them and no trust between them to set up. Every byte travels over the links that are already pinned to both ends' keys.

What it costs: a request on the "wrong" DMZ travels through a server twice. A load balancer that keeps each user on one DMZ avoids that. It is now a saving, no longer a requirement.

What passes this way: web pages, signing in (with a code or a passkey), uploads in several parts, downloads, the file manager's calls. A request that signs in by itself (WebDAV with a password on each request, the API with a token) runs where it lands and needs nothing of this.

**SFTP and FTPS** connections stay on one DMZ by nature. **FTP's** extra connection for each transfer must reach the DMZ that gave its address: give each DMZ its own range of passive ports and let the balancer pass each range to its DMZ. See [A load balancer in front](HA-Load-Balancer.md#ftp-needs-care).

## When a node stops

| What stops | Web sessions | SFTP and FTP connections | An upload under way |
|---|---|---|---|
| a server | stay on their DMZ. The DMZ signs each of them in on the server left, for the user's next request, without asking anything: the password is checked again, the second factor counts as passed (the user passed it on the DMZ). | stay; their next file operation goes to the server left in the same way | the part on the stopped server is lost; the web page sends that part again, and the file is written on the other server. A single SFTP or FTP upload fails, as it would on a direct connection. |
| a DMZ | lost: a session lives in its DMZ's memory. The user's next request reaches the other DMZ, which finds no session, and the user signs in again. | dropped with the connection; the program connects again, to the other DMZ | lost |

A DMZ whose server went away, and that has another, does not close its ports: `stop_dmz_ports_internal_down` acts only when no server answers at all.

## Settings

None of these is needed. They are server settings of the DMZ, read from its settings file (`prefs_dmz1.XML` on the server for a DMZ called `dmz1`), or a `-Dcrushmft.<name>=<value>` when the DMZ is started.

| Setting | Does | Unless you change it |
|---|---|---|
| `dmz6_locate_ms` | how long a DMZ waits for its servers to say which holds a user's session (asked once per session) | 2000 |
| `dmz6_hop_locate_ms` | how long a DMZ waits for its servers to say which DMZ holds a web session | 3000 |
| `dmz6_hop_lookups_per_second` | how many web sessions a DMZ may look for on the other DMZs in one second. Made-up cookies would otherwise cost every DMZ a question each; over the limit a request runs where it landed. | 200 |

## Things to know

- **Every node needs a CrushMFT 27 build of 2026-11-27 or later.** A DMZ of an earlier build linked by two servers lets them take it from each other again and again; update the DMZ first.
- **The servers must be one cluster** and replicate users and settings: a user signs in on whichever server the name picks, and after a server stops, on the other one.
- **Keep the DMZs' settings the same**: their ports, by number or at least by name. A request passed to another DMZ runs on the port with the same number there, else the one with the same name.
- **Without a DMZ**, two servers behind a load balancer find each other's web sessions in the same spirit: see [Session replication](Session-Replication.md).
- **What was tried**: two servers and two DMZs on one test machine, with a load balancer that sent every connection to the other DMZ than the last: signing in with a password, with a code and with a passkey, adding a passkey, uploads in three parts, listings and downloads, SFTP, a server stopped in the middle of a session (the next request worked in a fraction of a second, signed in as before) and a DMZ stopped (the user signed in again on the other). A real load balancer was not used.
