OpenLDAP Replication with syncrepl on AlmaLinux 10 (Provider/Consumer and Multi-Provider)

OpenLDAP on AlmaLinux series, part 4. Part 1 installed slapd with cn=config, part 2 added users, groups and a read-only bind account, and part 3 enabled StartTLS and LDAPS with a private CA. This part adds a second server with syncrepl replication. Part 5 joins Linux clients with SSSD, and part 6 adds password policies.

With only ldap1.example.lan, every login on every client depends on one slapd process on one VM. A reboot for patching, a full disk or a broken update means nobody can log in. OpenLDAP fixes that with syncrepl, its built-in replication engine. A second server (ldap2.example.lan) keeps a full, current copy of the directory and serves reads and binds when the first one is down.

In this guide you load the syncprov overlay on the provider, create a dedicated read-only replication account with the right ACL and size limits, configure ldap2 as a refreshAndPersist consumer over StartTLS with starttls=critical, and check that both servers hold the same data by comparing contextCSN. An optional final section turns the pair into multi-provider replication (formerly called mirror mode), so both servers accept writes.

All the LDIF, commands and error messages below were run on the same EL10 build as parts 1 to 3: slapd 2.6.13 from EPEL 10 with the AlmaLinux 10 openldap-clients 2.6.13 tools. Two slapd instances ran side by side in a lab (on different ports, with the hostnames mapped to them), and the outputs are copied from that lab with the standard ports put back. The systemd, firewalld and SELinux commands are the standard AlmaLinux 10 ones, but they could not be run in that lab; I point those out where they appear. I checked the option names and defaults against slapd-config(5) and slapo-syncprov(5) from the 2.6.13 package and the replication chapter of the OpenLDAP 2.6 Administrator’s Guide.

Applies to: AlmaLinux 10.x with openldap-servers 2.6 from EPEL 10, set up as in parts 1 to 3. The LDIF is the same on RHEL 10, Rocky Linux 10, Oracle Linux 10, CentOS Stream 10 and any OpenLDAP 2.5/2.6 server that uses cn=config (including RHEL 9 family systems with EPEL or Symas OpenLDAP builds). OpenLDAP 2.4 used olcMirrorMode instead of olcMultiProvider. 2.6 still accepts the old name as an alias.

Lab layout

HostIPRole in this part
ldap1.example.lan192.168.1.70Provider: the existing server from parts 1 to 3, gets the syncprov overlay
ldap2.example.lan192.168.1.72New consumer (read-only replica); becomes a second provider in the optional multi-provider section
client1.example.lan192.168.1.71Test client; uses both servers in part 5
SettingValue used here
Base DN (suffix)dc=example,dc=lan, data database olcDatabase={2}mdb on both servers
Root DNcn=admin,dc=example,dc=lan
Replication bind DNcn=replicator,ou=Services,dc=example,dc=lan (new, read-only)
Replication IDrid=001 on ldap2 (and rid=002 on ldap1 for multi-provider)
TransportStartTLS on 389/tcp with starttls=critical, CA from part 3 (/etc/openldap/certs/ca.crt)
LDIF files/root/ldap/60-*.ldif to 67-*.ldif, continuing the numbering from earlier parts

How syncrepl works in two minutes

  • Provider is the server that holds the master copy. It runs the syncprov overlay, which answers LDAP Content Synchronization (RFC 4533) searches.
  • Consumer is the server that copies the data. It has an olcSyncrepl attribute on its database telling it which provider to pull from, as whom, and what to pull. The consumer starts the connection: replication is pull, so the firewall must allow consumer → provider on 389.
  • refreshOnly polls the provider every interval. refreshAndPersist does one full refresh and then leaves the search open, so the provider pushes each change within milliseconds. This guide uses refreshAndPersist.
  • entryCSN (Change Sequence Number) is an operational attribute stamped on every entry at every change, for example 20261122091323.906761Z#000000#000#000000: a UTC timestamp, a counter, the server ID (000) and a modifier count.
  • contextCSN lives on the suffix entry and holds the newest CSN the database has seen, one value per server ID. When ldap1 and ldap2 show the same contextCSN values, they are in sync. This is the main health check.
  • Cookie: the consumer sends its contextCSN when it reconnects, so after a restart or outage it only receives what changed (not the whole tree).

Prerequisites

  • ldap1 as built in parts 1 to 3: data in olcDatabase={2}mdb, the module list cn=module{0},cn=config from part 2, TLS from part 3, and the entryCSN,entryUUID eq index from part 1 (03-indexes.ldif). syncprov needs those indexes for performance.
  • ldap2: a fresh AlmaLinux 10 VM with the same packages as ldap1 (epel-release, openldap-servers, openldap-clients), set up with the cn=config steps of part 1: 01-database.ldif (same suffix, rootDN and rootPW), 02-monitor.ldif, the cosine, nis and inetorgperson schemas, 03-indexes.ldif, 04-acl.ldif and 05-loglevel.ldif. Do not load 10-base.ldif or any part 2 entries on ldap2; the consumer must start empty and get every entry from ldap1.
  • Identical schema on both servers. If you did the optional dynlist step in part 2, ldap2 also needs the dyngroup schema, dynlist.la in cn=module{0} and the dynlist overlay, in the same order as on ldap1. An entry using an objectClass the consumer does not know stops replication (see Troubleshooting).
  • Time sync on both servers (chronyc tracking). CSNs are timestamps; a server with a clock in the future can make its changes win conflicts in multi-provider mode.
  • Name resolution: ldap1.example.lan and ldap2.example.lan resolve on both servers. Replication connects by name and checks the name against the certificate.
  • Network: ldap2 can reach ldap1 on 389/tcp (for multi-provider, also the reverse).

Step 1: Give ldap2 its own TLS certificate

Part 3 promised that ldap2 gets a certificate from the same private CA. On the host with the CA (/root/ldap-ca on ldap1), repeat step 2 of part 3 with ldap2’s names:

cd /root/ldap-ca
umask 077
openssl genpkey -algorithm RSA -pkeyopt rsa_keygen_bits:3072 -out ldap2.key
openssl req -new -key ldap2.key -subj "/O=Example LAN/CN=ldap2.example.lan" -out ldap2.csr

cat > ldap2.ext <<'EOF'
basicConstraints = critical, CA:FALSE
keyUsage = critical, digitalSignature, keyEncipherment
extendedKeyUsage = serverAuth
subjectAltName = DNS:ldap2.example.lan, DNS:ldap2, IP:192.168.1.72
subjectKeyIdentifier = hash
authorityKeyIdentifier = keyid,issuer
EOF

openssl x509 -req -in ldap2.csr -CA ca.crt -CAkey ca.key -CAcreateserial \
  -days 397 -sha256 -extfile ldap2.ext -out ldap2.crt
openssl verify -CAfile ca.crt ldap2.crt
openssl x509 -in ldap2.crt -noout -subject -ext subjectAltName
Certificate request self-signature ok
subject=O=Example LAN, CN=ldap2.example.lan
ldap2.crt: OK
subject=O=Example LAN, CN=ldap2.example.lan
X509v3 Subject Alternative Name: 
    DNS:ldap2.example.lan, DNS:ldap2, IP Address:192.168.1.72

Copy ca.crt, ldap2.crt and ldap2.key to ldap2 (for example with scp). Do not copy the CA key. Install them exactly like on ldap1 and point slapd at them with a copy of 50-tls.ldif that names ldap2.crt and ldap2.key:

# on ldap2
mkdir -p /etc/openldap/certs
install -m 0644 -o root -g root ca.crt ldap2.crt /etc/openldap/certs/
install -m 0640 -o root -g ldap ldap2.key /etc/openldap/certs/
restorecon -Rv /etc/openldap/certs

sed 's/ldap1\./ldap2./g' 50-tls.ldif > /root/ldap/50-tls.ldif   # the copy from ldap1
ldapmodify -Q -Y EXTERNAL -H ldapi:/// -f /root/ldap/50-tls.ldif
ldapwhoami -x -ZZ -H ldap://ldap2.example.lan -D cn=admin,dc=example,dc=lan -W
dn:cn=admin,dc=example,dc=lan

Set TLS_CACERT /etc/openldap/certs/ca.crt in /etc/openldap/ldap.conf on ldap2 too (part 3, step 8), so the client tools on both servers trust the CA. Hint: with an empty ldap2, the whoami above works but a search under dc=example,dc=lan returns No such object (32). That is expected until replication runs.

Step 2: Load the syncprov module on ldap1

The EPEL build ships syncprov as a loadable module (/usr/lib64/openldap/syncprov.la). Add it to the module list created in part 2:

cat > /root/ldap/60-syncprov-module.ldif <<'EOF'
dn: cn=module{0},cn=config
changetype: modify
add: olcModuleLoad
olcModuleLoad: syncprov.la
EOF

ldapmodify -Q -Y EXTERNAL -H ldapi:/// -f /root/ldap/60-syncprov-module.ldif
modifying entry "cn=module{0},cn=config"

If you skipped the optional dynlist step in part 2 and have no cn=module{0} yet, create it with changetype: add, objectClass: olcModuleList, cn: module, olcModulePath: /usr/lib64/openldap and olcModuleLoad: syncprov.la.

Step 3: Add the syncprov overlay to the data database

cat > /root/ldap/61-syncprov-overlay.ldif <<'EOF'
dn: olcOverlay=syncprov,olcDatabase={2}mdb,cn=config
changetype: add
objectClass: olcOverlayConfig
objectClass: olcSyncProvConfig
olcOverlay: syncprov
olcSpCheckpoint: 100 10
olcSpSessionLog: 1000
EOF

ldapmodify -Q -Y EXTERNAL -H ldapi:/// -f /root/ldap/61-syncprov-overlay.ldif
adding new entry "olcOverlay=syncprov,olcDatabase={2}mdb,cn=config"
  • olcSpCheckpoint: 100 10: syncprov keeps contextCSN in memory and writes it to disk at shutdown. The checkpoint also writes it after 100 write operations or 10 minutes, so an unclean shutdown (power loss, OOM kill) loses less. Checkpointing is off by default.
  • olcSpSessionLog: 1000: an in-memory log of the last 1000 modify/delete operations. A consumer that reconnects after a short outage can then get just the changes instead of a full present-phase comparison. The log starts empty after every slapd restart.

The overlay is added after dynlist (if you have it), so it shows up as {1}syncprov. Running the LDIF a second time fails with ldap_add: Other (e.g., implementation specific) error (80), overlay_config(): overlay "syncprov" already in list. That is harmless: it only means the overlay is already there.

Step 4: Create a read-only replication account

The consumer needs to read everything, including userPassword hashes, or users cannot bind against ldap2. Do not use cn=admin for that. A dedicated account that can only read is easier to audit and limits the damage if its password leaks from ldap2’s config. It goes into ou=Services next to cn=sssd-bind from part 2:

slappasswd -s 'Repl#Lab2026'     # use your own long random password
{SSHA}VRZYAsoOApki3ShGk+IdWxYgjOc4BjUp
cat > /root/ldap/62-replicator.ldif <<'EOF'
dn: cn=replicator,ou=Services,dc=example,dc=lan
objectClass: organizationalRole
objectClass: simpleSecurityObject
cn: replicator
description: Read-only bind account for syncrepl consumers
userPassword: {SSHA}VRZYAsoOApki3ShGk+IdWxYgjOc4BjUp
EOF

ldapadd -x -ZZ -H ldap://ldap1.example.lan -D cn=admin,dc=example,dc=lan -W -f /root/ldap/62-replicator.ldif
adding new entry "cn=replicator,ou=Services,dc=example,dc=lan"

Step 5: Give the replicator read access and unlimited search limits

Two things stop a replication account from getting all the data, and neither one gives a clear error:

  • ACLs. The part 1 rule for userPassword is by self write by anonymous auth by * none, so the replicator could not read password hashes. Replication still "works": every entry arrives, but without userPassword, and every user bind against ldap2 fails with Invalid credentials (49).
  • Size and time limits. slapd returns at most 500 entries per search by default (olcSizeLimit). Once the directory grows past that, the initial refresh stops with Size limit exceeded and the consumer retries forever with a partial copy.

Add an ACL rule in front of the existing ones (position {0}), and an olcLimits rule for the same DN:

cat > /root/ldap/63-replicator-acl.ldif <<'EOF'
dn: olcDatabase={2}mdb,cn=config
changetype: modify
add: olcAccess
olcAccess: {0}to * by dn.exact="cn=replicator,ou=Services,dc=example,dc=lan" read by * break
-
add: olcLimits
olcLimits: dn.exact="cn=replicator,ou=Services,dc=example,dc=lan" time.soft=unlimited time.hard=unlimited size.soft=unlimited size.hard=unlimited
EOF

ldapmodify -Q -Y EXTERNAL -H ldapi:/// -f /root/ldap/63-replicator-acl.ldif
ldapsearch -Q -LLL -Y EXTERNAL -H ldapi:/// -b "olcDatabase={2}mdb,cn=config" -s base \
  olcAccess olcLimits -o ldif_wrap=no
dn: olcDatabase={2}mdb,cn=config
olcAccess: {0}to * by dn.exact="cn=replicator,ou=Services,dc=example,dc=lan" read by * break
olcAccess: {1}to attrs=userPassword by self write by anonymous auth by * none
olcAccess: {2}to attrs=shadowLastChange by self write by users read by * none
olcAccess: {3}to * by users read by * none
olcLimits: {0}dn.exact="cn=replicator,ou=Services,dc=example,dc=lan" time.soft=unlimited time.hard=unlimited size.soft=unlimited size.hard=unlimited

Adding a value with an explicit {0} index inserts it at the top and renumbers the old rules, so nothing is replaced. by * break lets everyone else fall through to the old rules unchanged. Check that the account can read password hashes but cannot write:

ldapsearch -x -LLL -ZZ -H ldap://ldap1.example.lan -D cn=replicator,ou=Services,dc=example,dc=lan -W \
  "(uid=jdoe)" userPassword
dn: uid=jdoe,ou=People,dc=example,dc=lan
userPassword:: e1NTSEF9VHpzUTRGeWt3QVI5cm9LcUl1ZHNZOFIzQXFsQ3NlZTA=
printf 'dn: uid=jdoe,ou=People,dc=example,dc=lan\nchangetype: modify\nreplace: loginShell\nloginShell: /bin/sh\n' | \
  ldapmodify -x -ZZ -H ldap://ldap1.example.lan -D cn=replicator,ou=Services,dc=example,dc=lan -W
ldap_modify: Insufficient access (50)

Now the provider has a contextCSN on the suffix entry, which syncprov maintains from now on:

ldapsearch -x -LLL -ZZ -H ldap://ldap1.example.lan -D cn=admin,dc=example,dc=lan -W \
  -s base -b dc=example,dc=lan contextCSN
dn: dc=example,dc=lan
contextCSN: 20261122091249.397132Z#000000#000#000000

Step 6: Configure ldap2 as a consumer

On ldap2, add the replication agreement to its own olcDatabase={2}mdb. Continuation lines must start with exactly one space; the quotes around values with spaces or commas are required:

cat > /root/ldap/64-syncrepl-consumer.ldif <<'EOF'
dn: olcDatabase={2}mdb,cn=config
changetype: modify
add: olcSyncrepl
olcSyncrepl: rid=001
  provider=ldap://ldap1.example.lan
  bindmethod=simple
  binddn="cn=replicator,ou=Services,dc=example,dc=lan"
  credentials="Repl#Lab2026"
  searchbase="dc=example,dc=lan"
  scope=sub
  schemachecking=on
  type=refreshAndPersist
  retry="5 5 300 +"
  timeout=1
  starttls=critical
  tls_cacert=/etc/openldap/certs/ca.crt
  tls_reqcert=demand
-
add: olcUpdateRef
olcUpdateRef: ldap://ldap1.example.lan
EOF

chmod 600 /root/ldap/64-syncrepl-consumer.ldif
ldapmodify -Q -Y EXTERNAL -H ldapi:/// -f /root/ldap/64-syncrepl-consumer.ldif
modifying entry "olcDatabase={2}mdb,cn=config"
ParameterMeaning
rid=001Replica ID, unique per consumer agreement on this server (0-999). Shows in every log line.
providerProvider URI. Use the name in ldap1’s certificate, not the IP, or the TLS hostname check fails.
bindmethod, binddn, credentialsThe replicator from step 4. The password is stored in clear text in ldap2’s cn=config (readable only by root and ldap); that is one more reason to use a read-only account.
searchbase, scope=subReplicate the whole tree. The default attrs is "*,+" (all user and operational attributes).
schemachecking=onReject replicated entries that do not match ldap2’s schema. Default is off; on is safer for full replication and makes schema mismatches visible.
type=refreshAndPersistStay connected and receive changes as they happen.
retry="5 5 300 +"Retry every 5 seconds 5 times, then every 300 seconds forever. Without retry, syncrepl retries once per hour.
timeout=1Seconds to wait for the bind to complete. network-timeout covers the TCP connect.
starttls=criticalSend StartTLS before binding and give up if it fails. starttls=yes would quietly carry on in clear text.
tls_cacert, tls_reqcert=demandVerify ldap1’s certificate against the part 3 CA. demand is the default; it is written out so nobody “fixes” an error by changing it to never. TLS options you leave out default to slapd’s own olcTLS* settings.
olcUpdateRefA replica cannot be written to. Clients that try get a referral to ldap1 instead of an error.

If you followed part 3, step 10, ldap1 has olcSecurity: ssf=1, so a consumer without starttls cannot even bind: the log on ldap2 shows ldap_sasl_bind_s failed (13), and ldap1 logs err=13 ... text=confidentiality required. That is the setting doing its job. provider=ldaps://ldap1.example.lan (port 636) without starttls also works and was tested; pick one and use it everywhere.

Step 7: Verify that replication works

The initial refresh

A few seconds after the ldapmodify, ldap2 holds the whole tree. With olcLogLevel: stats from part 1, journalctl -u slapd on ldap2 shows only the connections. To watch replication itself, temporarily add sync (olcLogLevel: stats sync). These are the last lines of the initial refresh in the lab:

syncrepl_entry: rid=001 be_add cn=replicator,ou=Services,dc=example,dc=lan (0)
do_syncrep2: rid=001 LDAP_RES_INTERMEDIATE - REFRESH_DELETE
do_syncrep2: rid=001 cookie=rid=001,csn=20261122091249.397132Z#000000#000#000000
ldapsearch -x -LLL -ZZ -H ldap://ldap2.example.lan -D cn=admin,dc=example,dc=lan -W -b dc=example,dc=lan dn
dn: dc=example,dc=lan
dn: ou=People,dc=example,dc=lan
dn: ou=Groups,dc=example,dc=lan
dn: ou=Services,dc=example,dc=lan
dn: cn=jdoe,ou=Groups,dc=example,dc=lan
dn: cn=asmith,ou=Groups,dc=example,dc=lan
dn: cn=sysadmins,ou=Groups,dc=example,dc=lan
dn: cn=developers,ou=Groups,dc=example,dc=lan
dn: uid=jdoe,ou=People,dc=example,dc=lan
dn: uid=asmith,ou=People,dc=example,dc=lan
dn: cn=sssd-bind,ou=Services,dc=example,dc=lan
dn: cn=vpn-users,ou=Groups,dc=example,dc=lan
dn: cn=replicator,ou=Services,dc=example,dc=lan

(Blank lines between entries removed.) The 13 entries match ldap1. The replicated entries keep their original entryUUID and entryCSN, and userPassword is there, which proves the step 5 ACL works.

Compare contextCSN on both servers

This is the check to script and monitor. Put the replicator password in a root-only file without a trailing newline (printf, not echo). With a newline, -y sends the newline as part of the password and the bind fails with Invalid credentials (49):

printf '%s' 'Repl#Lab2026' > /root/.ldap-repl.pw && chmod 600 /root/.ldap-repl.pw

for h in ldap1.example.lan ldap2.example.lan; do
  printf '%-18s ' "$h"
  ldapsearch -x -LLL -ZZ -H ldap://$h -D cn=replicator,ou=Services,dc=example,dc=lan \
    -y /root/.ldap-repl.pw -s base -b dc=example,dc=lan contextCSN |
    awk '/^contextCSN/ {printf "%s ", $2} END {print ""}'
done
ldap1.example.lan  20261122091249.397132Z#000000#000#000000
ldap2.example.lan  20261122091249.397132Z#000000#000#000000

Identical values mean in sync. If ldap2 lags behind for more than a few seconds while ldap1 is being written to, look at its log. In single-provider mode there is one value with server ID 000; in multi-provider mode there is one value per server ID.

Live changes

Make changes on ldap1 and read them back from ldap2 a second later. A password reset, an add and a delete:

ldappasswd -x -ZZ -H ldap://ldap1.example.lan -D cn=admin,dc=example,dc=lan -W \
  -s 'Jdoe#Repl2026' uid=jdoe,ou=People,dc=example,dc=lan
ldapwhoami -x -ZZ -H ldap://ldap2.example.lan -D uid=jdoe,ou=People,dc=example,dc=lan -w 'Jdoe#Repl2026' 
dn:uid=jdoe,ou=People,dc=example,dc=lan
ldapadd -x -ZZ -H ldap://ldap1.example.lan -D cn=admin,dc=example,dc=lan -W -f bjones.ldif   # a part 2 style user, uidNumber 10003
ldapsearch -x -LLL -ZZ -H ldap://ldap2.example.lan -D cn=admin,dc=example,dc=lan -W "(uid=bjones)" dn uidNumber entryCSN
dn: uid=bjones,ou=People,dc=example,dc=lan
uidNumber: 10003
entryCSN: 20261122091323.906761Z#000000#000#000000

ldapdelete on ldap1 removes the entry from ldap2 just as quickly. After each change, both servers show the new contextCSN (20261122091323.906761Z#000000#000#000000 after the add).

Writes to the replica are referred to ldap1

ldapmodify -x -ZZ -H ldap://ldap2.example.lan -D cn=admin,dc=example,dc=lan -W -f change-shell.ldif
ldap_modify: Referral (10)
	referrals:
		ldap://ldap1.example.lan/uid=bjones,ou=People,dc=example,dc=lan

The OpenLDAP 2.6 command-line tools do not follow referrals (the old -C option is gone: ldapmodify: unrecognized option -C), so admins should simply run changes against ldap1. SSSD and most applications only read and bind, which ldap2 handles locally.

The consumer status in cn=Monitor

Part 1 gave cn=admin read access to the monitor database. slapd 2.6 publishes one entry per syncrepl agreement there, which is handy for monitoring scripts:

ldapsearch -x -LLL -ZZ -H ldap://ldap2.example.lan -D cn=admin,dc=example,dc=lan -W \
  -b "cn=Databases,cn=Monitor" "(objectClass=olmSyncReplInstance)" \
  olmSRProviderURIList olmSRSyncPhase olmSRLastConnect olmSRLastCookieRcvd
dn: cn=Consumer 001,cn=Database 2,cn=Databases,cn=Monitor
olmSRProviderURIList: ldap://ldap1.example.lan
olmSRSyncPhase: Persist
olmSRLastConnect: 20261122091653Z
olmSRLastCookieRcvd: rid=001,sid=001,csn=20261122091324.959549Z#000000#000#000000;20261122091653.454903Z#000000#001#000000;20261122091638.554350Z#000000#002#000000

olmSRSyncPhase: Persist means the consumer finished the refresh and is receiving live changes. olmSRLastCookieRcvd is the last contextCSN received from the provider. This output was captured after the multi-provider step, so the cookie carries a server ID and three CSNs; a plain consumer shows a single CSN. olmSRNextConnect shows when the next retry is due during an outage.

Step 8: Test an outage and the catch-up

Stop slapd on ldap2, change something on ldap1, start ldap2 again:

# ldap2
systemctl stop slapd
# ldap1: change bjones' loginShell to /sbin/nologin with ldapmodify
# ldap2
systemctl start slapd
ldapsearch -x -LLL -ZZ -H ldap://ldap2.example.lan -D cn=admin,dc=example,dc=lan -W "(uid=bjones)" loginShell
dn: uid=bjones,ou=People,dc=example,dc=lan
loginShell: /sbin/nologin

The change was there a few seconds after startup. The consumer sent its stored cookie (ldap_sync_search: rid=001 starting refresh (sending cookie=rid=001,...)) and only received the difference. When ldap1 is the one that is down, ldap2 keeps serving reads and binds and logs do_syncrepl: rid=001 rc -1 retrying (4 retries left) until ldap1 is back, then catches up the same way. (In the lab, slapd was stopped and started directly rather than through systemctl; the replication behaviour is the same.)

Step 9: firewalld and SELinux on both servers

Replication is consumer → provider on 389/tcp. Part 1 opened the ldap service on ldap1 for 192.168.1.0/24, which already includes ldap2. On ldap2, open the same services for the clients (and, for multi-provider, for ldap1). See the firewalld cheat sheet for more rule styles:

# ldap2
firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="192.168.1.0/24" service name="ldap" accept'
firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="192.168.1.0/24" service name="ldaps" accept'
firewall-cmd --reload
firewall-cmd --list-rich-rules

# from ldap2: is ldap1 reachable on 389?
openssl s_client -connect ldap1.example.lan:389 -starttls ldap -verify_return_error -CAfile /etc/openldap/certs/ca.crt </dev/null 2>/dev/null | grep -E "^Verify return code"

The last command should print Verify return code: 0 (ok). With SELinux enforcing, slapd runs as slapd_t. The Fedora/RHEL policy source (ldap.te) lets slapd_t connect to any TCP port, so the outgoing replication connection needs no policy change. Only a non-standard listening port needs a label (semanage port -a -t ldap_port_t -p tcp PORT). If anything is denied, check with ausearch -m AVC -ts recent -c slapd. These firewalld and SELinux commands are standard AlmaLinux 10 administration and were not run in the test lab (no firewalld or SELinux there). Check them on your own hosts.

Step 10 (optional): Multi-provider replication

With a single provider, writes stop while ldap1 is down. That includes password changes by users, which go to ldap1 via the referral. Multi-provider replication makes both servers writable and replicates in both directions. It is the right choice when you need writes to keep working through an outage. It is not a load-balancing trick: each write still goes to every server, and two admins changing the same attribute on different servers at the same moment end up with whichever change has the newer CSN (last writer wins). Many sites run multi-provider but point all writes at one server and use the second only for failover.

Multi-provider needs: a unique non-zero olcServerID per server, syncprov on both, an olcSyncrepl on each pointing at the other, and olcMultiProvider: TRUE on both databases. ACLs and limits live in cn=config, which is not replicated here, so ldap2 also needs the step 5 rules.

10.1 Server IDs

# ldap1
cat > /root/ldap/65-serverid.ldif <<'EOF'
dn: cn=config
changetype: modify
add: olcServerID
olcServerID: 1
EOF
ldapmodify -Q -Y EXTERNAL -H ldapi:/// -f /root/ldap/65-serverid.ldif

# ldap2: same file with olcServerID: 2

Set the IDs first. slapd-config(5) requires a non-zero server ID for multi-provider mode, and every CSN a server generates carries its ID. In the 2.6.13 test, slapd did not reject olcMultiProvider while the ID was still 0, so nothing stops you from getting the order wrong. Changes made in that state are stamped #000# and cannot be told apart from changes made by any other server that has no ID.

10.2 syncprov, ACL and limits on ldap2

# ldap2: the same files as on ldap1
ldapmodify -Q -Y EXTERNAL -H ldapi:/// -f /root/ldap/60-syncprov-module.ldif
ldapmodify -Q -Y EXTERNAL -H ldapi:/// -f /root/ldap/61-syncprov-overlay.ldif
ldapmodify -Q -Y EXTERNAL -H ldapi:/// -f /root/ldap/63-replicator-acl.ldif

The cn=replicator entry itself does not need to be created on ldap2. It already arrived through replication.

10.3 Turn ldap2 into a provider

cat > /root/ldap/66-multiprovider-ldap2.ldif <<'EOF'
dn: olcDatabase={2}mdb,cn=config
changetype: modify
delete: olcUpdateRef
-
add: olcMultiProvider
olcMultiProvider: TRUE
EOF
ldapmodify -Q -Y EXTERNAL -H ldapi:/// -f /root/ldap/66-multiprovider-ldap2.ldif

If you run it twice, the second run fails with ldap_modify: No such attribute (16), modify/delete: olcUpdateRef: no such attribute, because the referral is already gone.

10.4 Make ldap1 a consumer of ldap2

cat > /root/ldap/67-multiprovider-ldap1.ldif <<'EOF'
dn: olcDatabase={2}mdb,cn=config
changetype: modify
add: olcSyncrepl
olcSyncrepl: rid=002
  provider=ldap://ldap2.example.lan
  bindmethod=simple
  binddn="cn=replicator,ou=Services,dc=example,dc=lan"
  credentials="Repl#Lab2026"
  searchbase="dc=example,dc=lan"
  scope=sub
  schemachecking=on
  type=refreshAndPersist
  retry="5 5 300 +"
  timeout=1
  starttls=critical
  tls_cacert=/etc/openldap/certs/ca.crt
  tls_reqcert=demand
-
add: olcMultiProvider
olcMultiProvider: TRUE
EOF
chmod 600 /root/ldap/67-multiprovider-ldap1.ldif
ldapmodify -Q -Y EXTERNAL -H ldapi:/// -f /root/ldap/67-multiprovider-ldap1.ldif

The rid only has to be unique on the server that holds it. rid=002 on ldap1 just makes the logs easier to read. The finished configuration on the two servers:

ldap1: olcServerID: 1   olcMultiProvider: TRUE   olcSyncrepl: rid=002 provider=ldap://ldap2.example.lan
ldap2: olcServerID: 2   olcMultiProvider: TRUE   olcSyncrepl: rid=001 provider=ldap://ldap1.example.lan

10.5 Verify both directions

# write on ldap2, read on ldap1
ldapmodify -x -ZZ -H ldap://ldap2.example.lan -D cn=admin,dc=example,dc=lan -W -f asmith-zsh.ldif
ldapsearch -x -LLL -ZZ -H ldap://ldap1.example.lan -D cn=admin,dc=example,dc=lan -W "(uid=asmith)" loginShell entryCSN
dn: uid=asmith,ou=People,dc=example,dc=lan
loginShell: /bin/zsh
entryCSN: 20261122091636.486020Z#000000#002#000000
# write on ldap1, read on ldap2
ldapsearch -x -LLL -ZZ -H ldap://ldap2.example.lan -D cn=admin,dc=example,dc=lan -W "(cn=sysadmins)" memberUid entryCSN
dn: cn=sysadmins,ou=Groups,dc=example,dc=lan
memberUid: jdoe
memberUid: asmith
entryCSN: 20261122091637.509816Z#000000#001#000000

The third field of the CSN now shows which server made the change: #002# for ldap2 and #001# for ldap1. The contextCSN check from step 7 now returns one value per server ID, and the lists must match on both servers:

ldap1.example.lan  20261122091324.959549Z#000000#000#000000 20261122091637.509816Z#000000#001#000000 20261122091636.486020Z#000000#002#000000
ldap2.example.lan  20261122091324.959549Z#000000#000#000000 20261122091637.509816Z#000000#001#000000 20261122091636.486020Z#000000#002#000000

The #000# value is left over from single-provider operation and is harmless. Stopping one server, writing to the other and starting it again worked the same way as in step 8, and so did adding a new user on ldap2. A third read-only consumer can pull from either provider with the step 6 LDIF.

Notes for multi-provider: keep the clocks in sync, never give two servers the same olcServerID, and remember that schema, modules, ACLs, limits and TLS settings live in cn=config and must be changed on both servers. Replicating cn=config itself is possible but outside the scope of this guide.

What syncrepl does not do for you

  • Backups. A replica copies deletes and mistakes within milliseconds. Keep the slapcat backups from part 1 on at least one server.
  • Dynamic attributes. With the part 2 dynlist overlay, memberOf is computed on each server when someone searches, not replicated. The test showed it on ldap2 via its own dynlist overlay, and slapcat on ldap2 showed no stored memberOf. Each server needs the same overlay configuration.
  • Large or busy directories should look at delta-syncrepl (accesslog overlay, syncdata=accesslog), which replicates only the changed attributes instead of whole entries. For a small site directory, plain syncrepl is simpler and enough.

Troubleshooting

Errors from the replication engine show up only in the consumer’s slapd log (journalctl -u slapd on ldap2), never on the command line, because nothing you type gets an error back. The provider log shows the matching bind or search result. Every message below was reproduced on slapd 2.6.13 except the ones marked with an asterisk.

Consumer log message or symptomCauseFix
slap_client_connect: URI=ldap://ldap1.example.lan DN="cn=replicator,ou=services,dc=example,dc=lan" ldap_sasl_bind_s failed (49)Wrong credentials in olcSyncrepl, or the replicator entry or password on the provider differsTest the bind with ldapwhoami -x -ZZ -D cn=replicator,... -W; fix with ldapmodify replace olcSyncrepl on the consumer
ldap_sasl_bind_s failed (13); provider logs confidentiality requiredProvider has olcSecurity: ssf=1 (part 3) and the agreement has no starttlsAdd starttls=critical or use ldaps://
TLS: hostname does not match name in peer certificate. then ldap_start_tls failed (-11)provider= uses an IP or name that is not in ldap1’s SANUse the FQDN from the certificate in provider=
TLS: could not load verify locations (file:`/path/ca.crt',dir:`'), TLS context initialization failed (-1)Wrong tls_cacert path, or the file is not readable by the ldap user / SELinux labelFix the path; runuser -u ldap -- test -r /etc/openldap/certs/ca.crt; restorecon
certificate verify failed *Consumer does not trust the provider’s CA (no tls_cacert and no matching olcTLSCACertificateFile)Set tls_cacert to the part 3 CA
do_syncrepl: rid=001 rc -1 retryingProvider down, wrong port, or firewall blocks consumer → providersystemctl status slapd on the provider; step 9 openssl s_client -starttls ldap test from the consumer
do_syncrep2: rid=001 LDAP_RES_SEARCH_RESULT (4) Size limit exceeded, rc -101 retrying; consumer has only part of the treeNo olcLimits for the replicator; default size limit (500) reachedStep 5 olcLimits on the provider
All entries replicated, but user binds on the replica fail with Invalid credentials (49); (userPassword=*) finds nothing on the consumerReplicator cannot read userPassword (no step 5 ACL)Add the {0} ACL, then reload the consumer (below)
syncrepl_message_to_entry: rid=001 mods check (objectClass: value #0 invalid per syntax), rc 21 retryingThe consumer is missing a schema the provider uses (in the test: no inetorgperson schema on the consumer)Load the same schemas, in the same order, on every server
ldap_modify: Referral (10) on the replicaWrites go to the provider (olcUpdateRef)Write to ldap1, or use multi-provider
ldap_add: ... (80) overlay "syncprov" already in listLDIF 61 applied twiceNothing to fix
contextCSN differs and stays differentConsumer stuck on one of the errors above, or retries exhausted (no + in retry)Read the consumer log; check olmSRSyncPhase in cn=Monitor

Reloading a consumer from scratch after fixing an ACL or schema problem: on ldap2, systemctl stop slapd, move /var/lib/ldap/data.mdb and lock.mdb out of the way, and systemctl start slapd. With an empty database the consumer does a full refresh. Entries that already exist are not re-sent with the newly readable attributes, because their entryCSN has not changed, so a fresh start is the reliable fix. In the lab, restarting the consumer with its old database after the ACL fix left the hashes missing, while a full refresh into an empty database brought all of them across. Do this only on a pure consumer, never on the only server that holds the data.

What is next

The directory now has two servers with the same data, encrypted replication and a monitoring check. Part 5 configures SSSD on client1: ldap_uri = ldap://ldap1.example.lan, ldap://ldap2.example.lan for failover, the sssd-bind account from part 2, the CA from part 3, min_id = 10000 and home directory creation, so that getent passwd jdoe and ssh jdoe@client1 work even when ldap1 is down. Part 6 adds password policies with the ppolicy overlay, which you will load on both servers.

Leave a Reply

Your email address will not be published. Required fields are marked *