# ServerBeat: a shared address

ServerBeat lets two or more servers share one IP address. One of them holds the address and does the work. The others watch it, and when it stops answering, one of them takes the address over within seconds. Users, DNS and firewall rules point at the shared address and never have to change.

It is high availability without anything in front of the servers: no load balancer, no extra machine.

ServerBeat needs an Enterprise licence.

## How it works

- You choose a free address in the servers' network: the **virtual IP**.
- Each server has a ServerBeat item among its listeners, naming that address and the other servers.
- The servers talk to each other every second and agree on who holds the address: the one with the highest **priority** that is up.
- The holder adds the address to its network card, as a second address of the machine. The operating system does that on the server's command.
- When the holder stops answering, the next one waits a moment, takes the address, and its listeners answer on it.

Only one server has the address at any time.

## The servers must be in one cluster

ServerBeat's own talk is encrypted and tied to the servers' keys. There is no other form of it in CrushMFT 27: no shared secret, no unencrypted connection.

So the servers that share an address must be members of one [cluster](Cluster.md) before ServerBeat does anything. A ServerBeat item on a server that is in no cluster does not start, and says why:

> ServerBeat needs this server and the servers it shares the IP with to be in one cluster: Server Admin, Cluster.

It neither takes the address nor gives it up. The alert **Server Port Failed** fires as for any listener that does not start.

Order of work on new servers: create the cluster, join the second server, then add the ServerBeat items.

## Setting it up

In [Preferences, IP / Servers](Ports.md), add an item of the type **ServerBeat Virtual IP (ServerBeat://)** on each server.

| Field | Is |
|---|---|
| **IP**, **Port** | this server's own address in the network, and a port on which the servers talk to each other about the shared address. The same port on all. |
| **Virtual IP** | the shared address. The small field beside it is the number of the alias on the network card; leave it at 1 unless that number is taken. |
| **Participating server IPs** | the own addresses of all servers that share it, "Comma separated." |
| **Netmask** | of the network, such as `255.255.255.0` |
| **Ethernet Adapter OS Name** | the network card as the operating system calls it: `eth0`, `ens192`, "Ethernet" |
| **Priority** | "Higher number has priority." |
| **Master Takeover Delay** | seconds a server waits, after losing sight of the holder, before it takes the address |
| **Test Connection** | checks that this server reaches the others |

The form also has **ServerBeat secret key**. It is from earlier versions and is not used: the servers know each other by their cluster keys.

### Priority

Use two levels: one server with a high number, the others with the same lower one. For three servers: 200, 100, 100.

The server with the high number holds the address whenever it is up. When it comes back after a failure, it takes the address back.

### The commands

The server adds and removes the address by running a command of the operating system: `ip` on Linux, `netsh` on Windows. The fields let you change them for a system that needs another:

| Field | Is |
|---|---|
| **Command to assign the VIP**, **Command to release the VIP** | the commands. `{adapter}`, `{index}`, `{vip}` and `{netmask}` in them are filled in. |
| **Command for OS's that need ifup**, **… ifdown** | for systems that bring an alias up and down with separate commands |
| **Command to run after becoming master** | a command of your own, run when this server has taken the address: to tell a router, for example |
| **Issue a start ports request when we become master** | the server starts its listeners again when it takes the address, so that they answer on it |

The account the server runs as must be allowed to change the machine's network addresses. On Linux that means root, or the right to run `ip` given by `sudo` or capabilities. On Windows, a service account needs the right to run `netsh` for the interface.

## What uses the shared address

- **Users and partners** connect to it. Give the listeners of each server the shared address, or let them listen on all addresses.
- **Scheduled jobs** run on the holder only, so each job runs once: see [Jobs in a cluster](Jobs-Engines-Cluster.md).
- **Scheduled reports** likewise.
- **DMZs**, with the server setting `serverbeat_dmz_master` set to true: only the holder feeds the DMZs, and the other servers stand by for them.

## More than two servers

With three or more servers, a server that loses sight of all the others cannot know whether they are down or whether it is itself cut off. If it took the address, two servers might hold it at once.

So with three or more, a server takes the address only while it sees more than half of the servers. One that is alone holds back, and reports: "No quorum: only 1 of 3 nodes reachable, so this node will not take the VIP."

With exactly two servers there is no "more than half" but both, so the rule does not apply: a server that loses sight of the other takes the address. If only the link between the two is cut, both may hold it for that time. Give two servers a second network path between them where you can, and a sensible takeover delay.

| Server setting | Does | Unless you change it |
|---|---|---|
| `serverbeat_disable_master_during_uncertainty` | a holder that loses sight of the others gives the address up until it sees them again | false |
| `serverbeat_dmz_master` | only the holder feeds the DMZs | false |

## Watching it

| Where | Shows |
|---|---|
| the Cluster page | the mark **Holds the shared IP** on the holder's tile |
| a node's detail, **Links**, **Shared IP** | who **Holds it** and this node's **Priority** |
| the health check `serverbeat` | `OK`, `DISABLED` where it is not used, or `IMPAIRED` with the reason |
| the alert **ServerBeat Alert** | the address changing hands |
| the alert **ServerBeat Impaired** | ServerBeat cannot do its work |

## What users notice at a takeover

Connections to the server that failed are broken. Programs that try again connect to the same address and reach the new holder within seconds. Web users log in again: see [Session replication](Session-Replication.md). Transfers start again or resume.

## ServerBeat or a load balancer

| | ServerBeat | A [load balancer](HA-Load-Balancer.md) |
|---|---|---|
| extra machines | none | the balancer, itself in two copies |
| servers working | one; the others wait | all |
| the servers must be | in one network segment, so that an address can move between them | anywhere |
| takeover | seconds | seconds |

## Things to know

- **One network segment.** An address can only move between machines on the same local network. Two sites need a load balancer or DNS.
- **Cloud networks** usually do not let a machine take an address by itself. There, use the cloud's own load balancer.
- **Test it.** Stop the holder and watch the address move, before you depend on it.
- **Coming from CrushFTP 11**: version 11 servers and CrushMFT 27 servers do not share an address with each other. Update all servers of a ServerBeat group together, create the cluster, and ServerBeat starts.
- **Not run for this page.** ServerBeat changes a machine's network addresses, and was not run on the test machine. The page is from the form, the server's code and its design record.
