NEXItaliano

NEXFS › Documentation › Tutorial: NEXFS on three machines

Tutorial: NEXFS on three machines

By Roberto Arato of aratoingegneria.it

In about half an hour this tutorial takes you from three clean Debian 13 machines to a NEXFS cluster that survives the loss of one machine. You don't need NEX. Along the way you will mount the filesystem, choose the number of copies for a folder, take a snapshot, set a quota, switch off a machine and watch the cluster mend itself.

Every command and every answer below is real: the tutorial was followed word by word on three new virtual machines (Debian 13 cloud image, kernel 6.12, 2 GB of memory, one processor each).

What you need

Machine Address Disks
node-1 192.168.203.146 system, plus an empty 10 GB disk /dev/sdb
node-2 192.168.203.147 the same
node-3 192.168.203.148 the same
  • Debian 13 or Ubuntu 24.04/26.04, with a user that can use sudo.
  • The machines reach each other on TCP ports 7400 and 7401.
  • The NEXFS 0.9.11 packages (nexfs, nexfs-server, nexfs-client, nexfs-tools and libnexfs0, files *_0.9.11_amd64.deb), copied into your home on each machine.
  • Your addresses will be different: use yours wherever you see these.

Each machine will be at the same time a meta node (it keeps the filesystem index, in a group of three that votes), a data node (it keeps the blocks of the files, on its own disk) and a client (it mounts the filesystem on /nex).

1. A disk for the blocks

On each machine, format the empty disk and mount it where NEXFS will keep its blocks. Check the name of the disk first with lsblk: everything on it is erased.

lsblk -d -o NAME,SIZE
sudo mkfs.ext4 -q -L nexfs-disk0 /dev/sdb
sudo mkdir -p /srv/nexfs/disk0
echo 'LABEL=nexfs-disk0 /srv/nexfs/disk0 ext4 defaults,nofail 0 2' | sudo tee -a /etc/fstab
sudo systemctl daemon-reload
sudo mount /srv/nexfs/disk0

The label in /etc/fstab keeps the disk in its place even if the disk names change at the next boot, and nofail lets the machine start even if the disk has failed (see Replacing a disk).

2. The packages

On each machine:

sudo apt update
sudo apt install ./nexfs*_0.9.11_amd64.deb ./libnexfs0_0.9.11_amd64.deb attr

nexfs brings the other four: the daemon, the client, nexfsctl with nexfs-setup and the library.

attr gives you getfattr and setfattr, which you will use for quotas. Nothing starts yet: the service starts when the machine joins the cluster.

3. The first machine creates the cluster

On node-1:

sudo nexfs-setup init --disk /srv/nexfs/disk0
The cluster is ready: node node-1 at 192.168.203.146, in 3 seconds.

Entry code (roles data,meta,client, 5 uses, valid 60 minutes):

    YQFW-D008-NSFQ-PHJF-WRWV-B37K-4BS4-FZ10

On each new machine:

    nexfs-setup join 192.168.203.146 YQFW-D008-NSFQ-PHJF-WRWV-B37K-4BS4-FZ10 --data
    nexfs-setup join 192.168.203.146 YQFW-D008-NSFQ-PHJF-WRWV-B37K-4BS4-FZ10 --meta --disk /var/lib/nexfs/disco0
    nexfs-setup join 192.168.203.146 YQFW-D008-NSFQ-PHJF-WRWV-B37K-4BS4-FZ10 --client --mount /nex

Keep the entry code: the other machines need it to join. It works for one hour and five machines.

4. The other two machines join

On node-2 and then on node-3, with your code:

sudo nexfs-setup join 192.168.203.146 CODE --meta --disk /srv/nexfs/disk0
This machine joined the cluster as a meta node: node-2, id 2, in 6 seconds.
This machine joined the cluster as a meta node: node-3, id 3, in 6 seconds.

Each machine creates its own key, proves to node-1 that it knows the code (the code never travels on the network), receives its certificate and joins the group of meta nodes and the data nodes.

Now check from any of the three:

sudo nexfsctl health
{"status": "ok", "reasons": [], "quorum": true, "leader": 1, "meta_nodes": 3, "meta_nodes_up": 3, "state_level": 2, "data_nodes": 3, "data_nodes_up": 3, "blocks": 0, "blocks_degraded": 0, "copies_to_rebuild": 0, "copies_leaving": 0, "blocks_waiting_copies": 0, "rebuild": {"active": false, "moving": 0, "rate_mb_s": 32}, "copies": 3, "bytes_total": 31392067584, "bytes_free": 29724721152, "bytes_used": 1667346432, "read_bytes_s": 0, "write_bytes_s": 0}

"status": "ok": three meta nodes, three data nodes, every block with all its copies. From now on new blocks are written in three copies, one per machine.

5. Mount the filesystem

The three machines are already part of the cluster, so they only need to mount it. On each machine:

sudo systemctl enable --now nexfs-client@nex.service
df -h /nex
Filesystem      Size  Used Avail Use% Mounted on
nexfs           9.8G  531M  9.3G   6% /nex

The size is the space of the three disks divided by three, because each block is kept on all three. The mount comes back by itself at every boot.

A machine that is only a client (no disk, no vote) joins with nexfs-setup join ADDRESS CODE --client --mount /nex and mounts in one step.

6. One filesystem, three machines

On node-1:

sudo mkdir /nex/shared
sudo chown $USER: /nex/shared
echo "written on node-1" > /nex/shared/hello.txt

On node-2, at once:

cat /nex/shared/hello.txt
echo "and appended on node-2" >> /nex/shared/hello.txt

On node-3:

cat /nex/shared/hello.txt
On node-2:
written on node-1

On node-3:
written on node-1
and appended on node-2

When a program closes a file on one machine, the others see it as soon as they open it. fsync returns only when the data is on the disks of the machines that keep its copies.

7. Copies per folder

Not everything needs three copies. Scratch files, build outputs and caches can live with one, and take a third of the space:

sudo mkdir /nex/scratch
sudo chown $USER: /nex/scratch
sudo nexfsctl copies 1 /scratch
dd if=/dev/urandom of=/nex/scratch/big.bin bs=1M count=200 status=none
dd if=/dev/urandom of=/nex/shared/big.bin bs=1M count=200 status=none
sudo nexfsctl space
{"path": "/scratch", "copies": 1}
{"total": 31392067584, "free": 28945268736, "inodes": 1027, "copies": 3, "converting": false}

How much each machine keeps, a few seconds later (sudo du -sm /srv/nexfs/disk0 on each one):

node-1: 301 MB
node-2: 245 MB
node-3: 257 MB

About 800 MB in all: the 200 MB in /nex/scratch once, the 200 MB in /nex/shared three times. The path given to nexfsctl copies is the one inside the filesystem (/scratch is /nex/scratch). sudo nexfsctl copies default /scratch goes back to the number of the cluster. The change applies at once to new files, and in the background to those already there.

8. A snapshot

Every folder has a hidden .snap folder. Creating a folder inside it takes a picture of the folder, at once, without copying anything:

mkdir /nex/shared/.snap/before
echo "a mistake" > /nex/shared/hello.txt
cat /nex/shared/.snap/before/hello.txt
cp /nex/shared/.snap/before/hello.txt /nex/shared/hello.txt
cat /nex/shared/hello.txt
written on node-1
and appended on node-2
written on node-1
and appended on node-2

The first two lines come from the snapshot, taken before the mistake; the last two are the file after copying it back. The owner of a folder can take its snapshots, without sudo. Inside .snap everything is read-only and as it was. rmdir /nex/shared/.snap/before removes the snapshot and frees the blocks that only it was keeping.

9. A quota

/nex/shared already holds a little more than 200 MB (big.bin). Limit it to 300 MB and try to write 200 MB more:

getfattr -n nexfs.dir.rbytes /nex/shared
sudo setfattr -n nexfs.quota.max_bytes -v 300000000 /nex/shared
dd if=/dev/zero of=/nex/shared/too-much.bin bs=1M count=200
getfattr: Removing leading '/' from absolute path names
# file: nex/shared
nexfs.dir.rbytes="209715241"

dd: error writing '/nex/shared/too-much.bin': Disk quota exceeded
87+0 records in
86+0 records out
90177536 bytes (90 MB, 86 MiB) copied, 4.53125 s, 19.9 MB/s

The quota is checked from whichever machine writes, and the counts of a folder (nexfs.dir.rbytes, rfiles, rsubdirs) are always exact. -v 0 removes the limit.

rm /nex/shared/too-much.bin
sudo setfattr -n nexfs.quota.max_bytes -v 0 /nex/shared

10. A machine breaks

Switch off node-3 without warning (pull the plug, or power it off from the hypervisor). The other two notice it within a few seconds; after about twenty seconds, on node-1:

sudo nexfsctl health --no-traffic
{"status": "warning", "reasons": [{"code": "meta_node_down", "severity": "warning", "message": "metadata node 3 (node-3) does not answer"}, {"code": "data_node_down", "severity": "warning", "message": "data node 3 (node-3) does not answer"}], "quorum": true, "leader": 1, "meta_nodes": 3, "meta_nodes_up": 2, "state_level": null, "data_nodes": 3, "data_nodes_up": 2, "blocks": 122, "blocks_degraded": 0, "copies_to_rebuild": 0, "copies_leaving": 0, "blocks_waiting_copies": 0, "rebuild": {"active": false, "moving": 0, "rate_mb_s": 32}, "copies": 3, "bytes_total": 31392067584, "bytes_free": 28793667584, "bytes_used": 2598400000, "read_bytes_s": null, "write_bytes_s": null}

The cluster keeps working with two machines out of three: the remaining meta nodes are still a majority, and every block still has copies on node-1 and node-2. You can go on writing:

dd if=/dev/urandom of=/nex/shared/while-down.bin bs=1M count=50 status=none
sudo nexfsctl health --no-traffic
{"status": "warning", "reasons": [{"code": "meta_node_down", "severity": "warning", "message": "metadata node 3 (node-3) does not answer"}, {"code": "data_node_down", "severity": "warning", "message": "data node 3 (node-3) does not answer"}, {"code": "blocks_degraded", "severity": "warning", "message": "13 blocks have fewer complete copies than wanted (13 copies to rebuild)"}], "quorum": true, "leader": 1, "meta_nodes": 3, "meta_nodes_up": 2, "state_level": null, "data_nodes": 3, "data_nodes_up": 2, "blocks": 135, "blocks_degraded": 13, "copies_to_rebuild": 13, "copies_leaving": 0, "blocks_waiting_copies": 0, "rebuild": {"active": true, "moving": 0, "rate_mb_s": 32}, "copies": 3, "bytes_total": 31392067584, "bytes_free": 28688601088, "bytes_used": 2703466496, "read_bytes_s": null, "write_bytes_s": null}

The new blocks have two copies instead of three: blocks_degraded says how many are missing one. Now switch node-3 back on. When it is up, NEXFS starts by itself, catches up on the index and rebuilds the missing copies:

sudo nexfsctl health --no-traffic
{"status": "ok", "reasons": [], "quorum": true, "leader": 1, "meta_nodes": 3, "meta_nodes_up": 3, "state_level": 2, "data_nodes": 3, "data_nodes_up": 3, "blocks": 113, "blocks_degraded": 0, "copies_to_rebuild": 0, "copies_leaving": 0, "blocks_waiting_copies": 0, "rebuild": {"active": false, "moving": 0, "rate_mb_s": 32}, "copies": 3, "bytes_total": 31392067584, "bytes_free": 28726317056, "bytes_used": 2665750528, "read_bytes_s": null, "write_bytes_s": null}

"status": "ok" again, 26 seconds after node-3 was switched on, with nothing to do by hand. If a machine is gone for good, the Administration guide shows how to drain it, remove it and add another one.

Where to go from here

  • Installation: the same steps, with data-only and client-only machines.
  • The client: mount options, snapshots, folder attributes.
  • Administration: adding nodes, maintenance, upgrades, checks and repairs.
  • Commands: every nexfsctl command with an example.