32.7. Walkthrough: Clustered SMB with Samba and CTDB

Samba has a second high-availability architecture available to it, one that Chapter 21 pointed forward to: CTDB, the clustered trivial database that lets several smbd instances present one server. The practice environment for this chapter has no shared LUN and no cluster filesystem, so this walkthrough is a design and configuration guide assembled from the packaged ctdb(7), ctdb.conf(5), and smb.conf(5) documentation as shipped in Debian 13. The package and file inspection commands below were executed on the walkthrough's running hosts; the deployment steps that follow are the documented procedure, and no successful run of them is claimed here.

32.7.1. Active-Passive SMB versus CTDB and Concurrent Shared-Storage Designs

Design Storage SMB instances Client view Complexity
Active-passive (Samba under Pacemaker) replicated or shared block device, one mount one at a time one server; brief interruption on failover low - the NFS walkthrough's shape with smbd in place of nfsd
Clustered Samba with CTDB one shared cluster filesystem, all nodes mounted all nodes concurrently one server name; connections migrate on node loss high - CTDB, cluster filesystem, and fencing all required

The active-passive shape needs no new software: substitute an smbd service resource for the nfsserver resource of section 32.6.3, keep the filesystem and address layers, and the group works the same way. Its limits are single-node throughput and a failover interruption per event.

CTDB removes both limits by letting every node serve. Each node runs ctdbd and a full smbd; CTDB replicates Samba's databases across the nodes, elects a leader, and moves public addresses - the addresses clients actually connect to - between healthy nodes as membership changes. A client whose node dies is meant to reconnect, with SMB3 durable-handle semantics carrying its open state to the new owner. The price is that every node must see the same files at the same time, which requires a shared cluster filesystem, and that the whole design is only as safe as its protection against a partitioned cluster - which is CTDB's cluster lock, described below.

32.7.2. Selecting a Supported Shared Filesystem and Verifying Locking and Fencing

CTDB requires a filesystem that all nodes mount concurrently and whose locks are coherent across nodes: a lock taken on one node must be reliably unavailable to the others. On Debian 13, both cluster filesystems that Samba's documentation names are packaged: the kernel builds GFS2 (with DLM locking support) and OCFS2 as loadable modules, and the gfs2-utils (3.6.1) and ocfs2-tools (1.8.8) packages are in the main archive. Building the shared filesystem layer - device, DLM, fencing, mount - is the subject of Chapter 33, which builds and tests it; this walkthrough assumes a working cluster filesystem mounted at /srv/clusterfs on both nodes.

Two verifications belong to the storage layer before Samba is involved. First, locking coherence: CTDB's documentation points to the ping_pong test, which counts lock handoffs between two nodes on the shared filesystem - a low, inconsistent count means the filesystem is not safe for clustered Samba. Second, fencing: a cluster filesystem depends on failed nodes being fenced so their locks can be recovered; the fencing design of section 32.4 applies unchanged, and CTDB does not remove the requirement.

32.7.3. Consistent Domain Membership, Numeric Identities, ACLs, and Extended Attributes

Every node presents the same server, so every node must resolve users the same way. Three identity requirements:

  • Domain membership: if the cluster joins an Active Directory domain, all nodes join as member hosts with the same smb.conf; Samba's directory-backed identity (winbind or the embedded Samba AD case) is covered by Chapter 21, and the centralized-identity options of Chapter 35 are the general form of the same rule.
  • Numeric identities: file ownership is stored as numeric UID and GID. With a standalone server, the account database must be replicated (CTDB itself replicates Samba's TDB databases, including the standalone passdb, which is exactly the work it exists to do); with a domain, idmap configuration must be identical on all nodes so the same user maps to the same UID everywhere.
  • ACLs and extended attributes: share-level ACLs, DOS attributes, and audit information live in xattrs; the cluster filesystem must support them with the same semantics on every node. Verify with getfacl and setfacl from two nodes before trusting shares to clients.

32.7.4. CTDB Node Membership, Recovery Lock, Persistent State, and Public Addresses

The packages first. On ha1, as john:

$ dpkg-query -W ctdb samba 2>/dev/null
ctdb    2:4.22.11+dfsg-0+deb13u1
samba   2:4.22.11+dfsg-0+deb13u1

CTDB's own documentation is installed with it:

$ man -w ctdb ctdb.conf smb.conf 2>/dev/null
/usr/share/man/man1/ctdb.1.gz
/usr/share/man/man5/ctdb.conf.5.gz
/usr/share/man/man5/smb.conf.5.gz

And the shipped configuration file, whose comments are worth reading before they are replaced, begins:

# See ctdb.conf(5) for documentation
#
# See ctdb-script.options(5) for documentation about event script
# options

[logging]
    # Enable logging to syslog
    location = syslog

    # Default log level
    log level = NOTICE

[cluster]
    # Shared cluster lock file to avoid split brain.  Daemon
    # default is no cluster lock.  Do NOT run CTDB without a
    # cluster lock file unless you know exactly what you are
    # doing.
    #
    # Please see the CLUSTER LOCK section in ctdb(7) for more
    # details.
    #
    # cluster lock = !/bin/false CLUSTER LOCK NOT CONFIGURED

CTDB is not running on these hosts, because the practice environment has no shared filesystem for it:

$ sudo systemctl is-active ctdb
inactive

The command exits with status 3. The ctdb tool itself, which administers a running cluster, is present:

$ sudo ctdb --help 2>&1 | head -20
Usage: [OPTION...]
  -d, --debug=STRING       debug level
  -t, --timelimit=INT      timelimit (in seconds)
  -n, --node=INT           node specification - integer
  -Y                       enable machine readable output
  -x, --separator=CHAR     specify separator for machine readable output
  -X                       enable machine parsable output with separator |
  -v, --verbose            enable verbose output
  -T, --maxruntime=INT     die if runtime exceeds this limit (in seconds)

Help options:
  -?, --help               Show this help message
      --usage              Display brief usage message

A deployment on the two practice nodes would add four pieces of configuration.

The private node list, /etc/ctdb/nodes on both nodes, identical - one address per line on the cluster network:

192.168.233.11
192.168.233.12

The public addresses, /etc/ctdb/public_addresses, typically the same on all nodes - each line names an address, its mask, and its interface:

192.168.232.170/24 eth1
192.168.232.171/24 eth1

CTDB assigns these to healthy nodes at runtime and reassigns them when a node fails; unlike Pacemaker or Keepalived addresses, they are owned by CTDB from the first moment.

The cluster lock, in the [cluster] section of ctdb.conf - a file on the shared filesystem whose lock only one node can hold:

[cluster]
    cluster lock = /srv/clusterfs/ctdb.lock

And Samba's own declaration in /etc/smb.conf on both nodes:

[global]
    clustering = yes

The cluster lock is the split-brain defense. The ctdb(7) manual is explicit - running CTDB without a cluster lock "is not recommended as there will be no split brain protection" - and the shipped configuration file above carries the same warning in its comment. The lock is implemented by a helper that takes an fcntl lock on the file and rechecks that the file's inode is unchanged; the filesystem must therefore provide lock coherence, which is why section 32.7.2 made that a requirement. The node that holds the lock is the cluster leader, and election by lock acquisition is what keeps a partitioned CTDB cluster from electing two leaders: only the partition that can reach the shared filesystem's locks can lead at all.

32.7.5. Assigning One Owner for Cluster Resources and Avoiding Competing VIP Managers

CTDB manages its public addresses itself, so the rule of section 32.9.6 - one manager per address - applies to CTDB clusters with full force. A deployment that also runs Pacemaker or Keepalived on the same nodes must partition the address space: CTDB owns the public addresses clients connect to, and no other resource manager touches them. The clean designs are a CTDB-only cluster, where CTDB is the whole availability layer, or a storage node that runs CTDB for Samba and keeps Pacemaker for services with separate addresses. What must not exist is a public address in /etc/ctdb/public_addresses that also appears in a virtual_ipaddress or IPaddr2 resource: two managers will both, eventually, believe they own it, and the duplicate-owner state demonstrated with VRRP in section 32.9.5 is the mild form of what follows.

The same partitioning applies to the storage: if the shared filesystem needs a mount-ordering or fencing service, that service belongs to exactly one manager as well. A common pattern on real storage appliances is CTDB for SMB, with Pacemaker managing only the cluster filesystem's fencing prerequisites - and nothing that overlaps CTDB's own address and service management.

32.7.6. Checking SMB Dialect, Durable Handle, Reconnect, and Open-File Semantics

The client-facing checks for a CTDB cluster, as documented for Samba 4.22:

  • Dialect: modern clients negotiate SMB3; smbclient against a public address, and the Samba log's negotiated-protocol lines, confirm which dialect each connection uses.
  • Durable handles: SMB3 durable handles are the mechanism that lets a client reconnect its open file to a surviving node after its node fails; Chapter 21 used smbclient for share-level testing, and the same tool with an open file plus a deliberately stopped node is the acceptance test.
  • Reconnect behavior: clients should be tested from at least two hosts against at least two public addresses, so a failure exercises both address movement and connection migration.
  • Open-file semantics: oplocks and leases must be consistent across nodes - the shared filesystem's lock coherence is what makes a lease taken on one node meaningful on another.

None of these checks were run on the walkthrough's hosts, for the storage reason stated at the walkthrough's start; they are the documented acceptance path for a deployment.

32.7.7. Testing Concurrent Clients, Node Failure, Network Partitions, and Permission Preservation

The test plan follows the same shape as the NFS walkthrough's, adapted to the all-active design:

  1. Establish a baseline from two independent clients: connect to both public addresses, write distinguishable files, and record permissions with getfacl.
  2. Exercise concurrent access: two clients writing the same share through different public addresses must see each other's files with correct locking - a shared file written from both clients with an exclusive SMB lock held from one is the clustered analogue of the flock test in section 32.6.5.
  3. Remove a node: stop ctdb and smbd on one node, or power it off when the deployment's fencing is real. The expected observations: its public addresses appear on the survivor, clients reconnect, and the client that held an exclusive lock can take it again - the reclaim is CTDB's database recovery, which the leader drives.
  4. Partition the cluster network: the partition that cannot take the cluster lock must not serve. This is the CTDB analogue of the quorum arithmetic in section 32.3.5, and it is the single most important test a CTDB deployment can run, because a cluster lock on a filesystem whose locks are not coherent is a lock in name only.
  5. Re-verify permissions: getfacl output from both nodes and both clients must match the baseline; xattr and ACL drift between nodes is an early symptom of a broken underlying filesystem.

32.7.8. Maintenance, Shared-Storage Failure, Backup Restore, and Deployment Acceptance

Rolling maintenance stops one node at a time - CTDB moves that node's public addresses away, the node is updated and rebooted, and it rejoins - with the same version discipline as section 32.12.2: all nodes run the same samba and ctdb versions, and the shared filesystem's tools match its on-disk format.

Shared-storage failure is the failure CTDB handles best and worst at once. If the storage becomes unreachable, no node can take the cluster lock, no leader exists, and the cluster stops serving rather than serving divergent data - the correct, conservative outcome. But every copy of the data shared the same storage, so unlike the DRBD pair, a storage-layer failure is a restore event, not a failover event. Backups must come from outside the shared filesystem exactly as section 32.6.7 argued for the replicated pair, and the restore test is the same: restore to a scratch location, compare checksums, and read the result with a real client.

Deployment acceptance for clustered SMB is the combination of the checks above: two clients, both addresses, one node removed, one partition, one lock exercise, one measured recovery - and one restore read. Until those have all passed at least once, the cluster is a hypothesis.