1# $OpenLDAP$ 2# Copyright 1999-2021 The OpenLDAP Foundation, All Rights Reserved. 3# COPYING RESTRICTIONS APPLY, see COPYRIGHT. 4 5H1: Replication 6 7Replicated directories are a fundamental requirement for delivering a 8resilient enterprise deployment. 9 10{{PRD:OpenLDAP}} has various configuration options for creating a replicated 11directory. In previous releases, replication was discussed in terms of 12a {{master}} server and some number of {{slave}} servers. A master 13accepted directory updates from other clients, and a slave only 14accepted updates from a (single) master. The replication structure 15was rigidly defined and any particular database could only fulfill 16a single role, either master or slave. Another historic term introduced 17with OpenLDAP 2.4 was multimaster. 18 19As OpenLDAP now supports a wide variety of replication topologies, these 20terms have been deprecated in favor of {{provider}}/{{multi-provider}} and 21{{consumer}}: A provider can accept external write operations and make them 22available for retrieval by consumers; consumers request replication updates from 23providers. Unlike the rigidly defined master/slave relationships, 24provider/consumer roles are quite fluid: replication updates received in a 25consumer can be further propagated by that consumer to other servers, so a 26consumer can also act simultaneously as a provider. Also, a consumer need not 27be an actual LDAP server; it may be just an LDAP client. 28 29The following sections will describe the replication technology and 30discuss the various replication options that are available. 31 32H2: Replication Technology 33 34H3: LDAP Sync Replication 35 36The {{TERM:LDAP Sync}} Replication engine, {{TERM:syncrepl}} for 37short, is a consumer-side replication engine that enables the 38consumer {{TERM:LDAP}} server to maintain a shadow copy of a 39{{TERM:DIT}} fragment. A syncrepl engine resides at the consumer 40and executes as one of the {{slapd}}(8) threads. It creates and maintains a 41replica by connecting to the replication provider to perform 42the initial DIT content load followed either by periodic content 43polling or by timely updates upon content changes. 44 45Syncrepl uses the LDAP Content Synchronization protocol (or LDAP Sync for 46short) as the consumer synchronization protocol. LDAP Sync provides 47a stateful replication which supports both pull-based and push-based 48synchronization and does not mandate the use of a history store. 49In pull-based replication the consumer periodically 50polls the provider for updates. In push-based replication the consumer 51listens for updates that are sent by the provider in realtime. Since the 52protocol does not require a history store, the provider does not need to 53maintain any log of updates it has received (Note 54that the syncrepl engine is extensible and additional replication 55protocols may be supported in the future.). 56 57Syncrepl keeps track of the status of the replication content by 58maintaining and exchanging synchronization cookies. Because the 59syncrepl consumer and provider maintain their content status, the 60consumer can poll the provider content to perform incremental 61synchronization by asking for the entries required to make the 62consumer up-to-date with the provider content. Syncrepl 63also enables convenient management of consumers by maintaining replication 64status. The consumer database can be constructed from a consumer-side 65or a provider-side backup at any synchronization status. Syncrepl 66can automatically resynchronize the consumer database to be up-to-date 67with the current provider content. 68 69Syncrepl supports both pull-based and push-based synchronization. 70In its basic refreshOnly synchronization mode, the provider uses 71pull-based synchronization where the consumer servers need not be 72tracked and no history information is maintained. The information 73required for the provider to process periodic polling requests is 74contained in the synchronization cookie of the request itself. To 75optimize the pull-based synchronization, syncrepl utilizes the 76present phase of the LDAP Sync protocol as well as its delete phase, 77instead of falling back on frequent full reloads. To further optimize 78the pull-based synchronization, the provider can maintain a per-scope 79session log as a history store. In its refreshAndPersist mode of 80synchronization, the provider uses a push-based synchronization. 81The provider keeps track of the consumer servers that have requested 82a persistent search and sends them necessary updates as the provider 83replication content gets modified. 84 85With syncrepl, a consumer can create a replication agreement without 86changing the provider's configurations and without restarting the 87provider server, if the consumer server has appropriate access 88privileges for the DIT fragment to be replicated. The consumer 89server can stop the replication also without the need for provider-side 90changes and restart. 91 92Syncrepl supports partial, sparse, and fractional replications. The shadow 93DIT fragment is defined by a general search criteria consisting of 94base, scope, filter, and attribute list. The consumer content is 95also subject to the access privileges of the bind identity of the 96syncrepl replication connection. 97 98 99H4: The LDAP Content Synchronization Protocol 100 101The LDAP Sync protocol allows a client to maintain a synchronized 102copy of a DIT fragment. The LDAP Sync operation is defined as a set 103of controls and other protocol elements which extend the LDAP search 104operation. This section introduces the LDAP Content Sync protocol 105only briefly. For more information, refer to {{REF:RFC4533}}. 106 107The LDAP Sync protocol supports both polling and listening for changes 108by defining two respective synchronization operations: 109{{refreshOnly}} and {{refreshAndPersist}}. Polling is implemented 110by the {{refreshOnly}} operation. The consumer 111polls the provider using an LDAP Search request with an LDAP Sync 112control attached. The consumer copy is synchronized 113to the provider copy at the time of polling using the information 114returned in the search. The provider finishes the 115search operation by returning {{SearchResultDone}} at the end of 116the search operation as in the normal search. Listening is 117implemented by the {{refreshAndPersist}} operation. As the name 118implies, it begins with a search, like refreshOnly. Instead of 119finishing the search after returning all entries currently matching 120the search criteria, the synchronization search remains persistent 121in the provider. Subsequent updates to the synchronization content 122in the provider cause additional entry updates to be sent to the 123consumer. 124 125The {{refreshOnly}} operation and the refresh stage of the 126{{refreshAndPersist}} operation can be performed with a present 127phase or a delete phase. 128 129In the present phase, the provider sends the consumer the entries updated 130within the search scope since the last synchronization. The provider 131sends all requested attributes, be they changed or not, of the updated 132entries. For each unchanged entry which remains in the scope, the 133provider sends a present message consisting only of the name of the 134entry and the synchronization control representing state present. 135The present message does not contain any attributes of the entry. 136After the consumer receives all update and present entries, it can 137reliably determine the new consumer copy by adding the entries added 138to the provider, by replacing the entries modified at the provider, and 139by deleting entries in the consumer copy which have not been updated 140nor specified as being present at the provider. 141 142The transmission of the updated entries in the delete phase is the 143same as in the present phase. The provider sends all the requested 144attributes of the entries updated within the search scope since the 145last synchronization to the consumer. In the delete phase, however, 146the provider sends a delete message for each entry deleted from the 147search scope, instead of sending present messages. The delete 148message consists only of the name of the entry and the synchronization 149control representing state delete. The new consumer copy can be 150determined by adding, modifying, and removing entries according to 151the synchronization control attached to the {{SearchResultEntry}} 152message. 153 154In the case that the LDAP Sync provider maintains a history store and 155can determine which entries are scoped out of the consumer copy since 156the last synchronization time, the provider can use the delete phase. 157If the provider does not maintain any history store, cannot determine 158the scoped-out entries from the history store, or the history store 159does not cover the outdated synchronization state of the consumer, 160the provider should use the present phase. The use of the present 161phase is much more efficient than a full content reload in terms 162of the synchronization traffic. To reduce the synchronization 163traffic further, the LDAP Sync protocol also provides several 164optimizations such as the transmission of the normalized {{EX:entryUUID}}s 165and the transmission of multiple {{EX:entryUUIDs}} in a single 166{{syncIdSet}} message. 167 168At the end of the {{refreshOnly}} synchronization, the provider sends 169a synchronization cookie to the consumer as a state indicator of the 170consumer copy after the synchronization is completed. The consumer 171will present the received cookie when it requests the next incremental 172synchronization to the provider. 173 174When {{refreshAndPersist}} synchronization is used, the provider sends 175a synchronization cookie at the end of the refresh stage by sending 176a Sync Info message with refreshDone=TRUE. It also sends a 177synchronization cookie by attaching it to {{SearchResultEntry}} 178messages generated in the persist stage of the synchronization search. During 179the persist stage, the provider can also send a Sync Info message 180containing the synchronization cookie at any time the provider wants 181to update the consumer-side state indicator. 182 183In the LDAP Sync protocol, entries are uniquely identified by the 184{{EX:entryUUID}} attribute value. It can function as a reliable 185identifier of the entry. The DN of the entry, on the other hand, 186can be changed over time and hence cannot be considered as the 187reliable identifier. The {{EX:entryUUID}} is attached to each 188{{SearchResultEntry}} or {{SearchResultReference}} as a part of the 189synchronization control. 190 191H4: Syncrepl Details 192 193The syncrepl engine utilizes both the {{refreshOnly}} and the 194{{refreshAndPersist}} operations of the LDAP Sync protocol. If a 195syncrepl specification is included in a database definition, 196{{slapd}}(8) launches a syncrepl engine as a {{slapd}}(8) thread 197and schedules its execution. If the {{refreshOnly}} operation is 198specified, the syncrepl engine will be rescheduled at the interval 199time after a synchronization operation is completed. If the 200{{refreshAndPersist}} operation is specified, the engine will remain 201active and process the persistent synchronization messages from the 202provider. 203 204The syncrepl engine utilizes both the present phase and the delete 205phase of the refresh synchronization. It is possible to configure 206a session log in the provider which stores the 207{{EX:entryUUID}}s of a finite number of entries deleted from a 208database. Multiple consumers share the same session log. The syncrepl 209engine uses the delete phase if the session log is present and the state 210of the consumer server is recent enough that no session log entries are 211truncated after the last synchronization of the client. The syncrepl 212engine uses the present phase if no session log is configured for 213the replication content or if the consumer is too outdated 214to be covered by the session log. The current design of the session 215log store is memory based, so the information contained in the 216session log is not persistent over multiple provider invocations. 217It is not currently supported to access the session log store by 218using LDAP operations. It is also not currently supported to impose 219access control to the session log. 220 221As a further optimization, even in the case the synchronization 222search is not associated with any session log, no entries will be 223transmitted to the consumer server when there has been no update 224in the replication context. 225 226The syncrepl engine, which is a consumer-side replication engine, 227can work with any backends. The LDAP Sync provider can be configured 228as an overlay on any backend, but works best with the {{back-mdb}} 229backend. 230 231The LDAP Sync provider maintains a {{EX:contextCSN}} for each 232database as the current synchronization state indicator of the 233provider content. It is the largest {{EX:entryCSN}} in the provider 234context such that no transactions for an entry having smaller 235{{EX:entryCSN}} value remains outstanding. The {{EX:contextCSN}} 236could not just be set to the largest issued {{EX:entryCSN}} because 237{{EX:entryCSN}} is obtained before a transaction starts and 238transactions are not committed in the issue order. 239 240The provider stores the {{EX:contextCSN}} of a context in the 241{{EX:contextCSN}} attribute of the context suffix entry. The attribute 242is not written to the database after every update operation though; 243instead it is maintained primarily in memory. At database start 244time the provider reads the last saved {{EX:contextCSN}} into memory 245and uses the in-memory copy exclusively thereafter. By default, 246changes to the {{EX:contextCSN}} as a result of database updates 247will not be written to the database until the server is cleanly 248shut down. A checkpoint facility exists to cause the {{EX:contextCSN}} to 249be written out more frequently if desired. 250 251Note that at startup time, if the provider is unable to read a 252{{EX:contextCSN}} from the suffix entry, it will scan the entire 253database to determine the value, and this scan may take quite a 254long time on a large database. When a {{EX:contextCSN}} value is 255read, the database will still be scanned for any {{EX:entryCSN}} 256values greater than it, to make sure the {{EX:contextCSN}} value 257truly reflects the greatest committed {{EX:entryCSN}} in the database. 258On databases which support inequality indexing, setting an eq index 259on the {{EX:entryCSN}} attribute and configuring {{contextCSN}} 260checkpoints will greatly speed up this scanning step. 261 262If no {{EX:contextCSN}} can be determined by reading and scanning 263the database, a new value will be generated. Also, if scanning the 264database yielded a greater {{EX:entryCSN}} than was previously 265recorded in the suffix entry's {{EX:contextCSN}} attribute, a 266checkpoint will be immediately written with the new value. 267 268The consumer also stores its replication state, which is the provider's 269{{EX:contextCSN}} received as a synchronization cookie, in the 270{{EX:contextCSN}} attribute of the suffix entry. The replication state 271maintained by a consumer server is used as the synchronization state 272indicator when it performs subsequent incremental synchronization 273with the provider server. It is also used as a provider-side 274synchronization state indicator when it functions as a secondary 275provider server in a cascading replication configuration. Since 276the consumer and provider state information are maintained in the 277same location within their respective databases, any consumer can 278be promoted to a provider (and vice versa) without any special 279actions. 280 281Because a general search filter can be used in the syncrepl 282specification, some entries in the context may be omitted from the 283synchronization content. The syncrepl engine creates a glue entry 284to fill in the holes in the consumer context if any part of the 285consumer content is subordinate to the holes. The glue entries will 286not be returned in the search result unless {{ManageDsaIT}} control 287is provided. 288 289Also as a consequence of the search filter used in the syncrepl 290specification, it is possible for a modification to remove an entry 291from the replication scope even though the entry has not been deleted 292on the provider. Logically the entry must be deleted on the consumer 293but in {{refreshOnly}} mode the provider cannot detect and propagate 294this change without the use of the session log on the provider. 295 296For configuration, please see the {{SECT:Syncrepl}} section. 297 298 299H2: Deployment Alternatives 300 301While the LDAP Sync specification only defines a narrow scope for replication, 302the OpenLDAP implementation is extremely flexible and supports a variety of 303operating modes to handle other scenarios not explicitly addressed in the spec. 304 305 306H3: Delta-syncrepl replication 307 308* Disadvantages of LDAP Sync replication: 309 310LDAP Sync replication is an object-based replication mechanism. 311When any attribute value in a replicated object is changed on the provider, 312each consumer fetches and processes the complete changed object, including 313{{B:both the changed and unchanged attribute values}} during replication. 314One advantage of this approach is that when multiple changes occur to 315a single object, the precise sequence of those changes need not be preserved; 316only the final state of the entry is significant. But this approach 317may have drawbacks when the usage pattern involves single changes to 318multiple objects. 319 320For example, suppose you have a database consisting of 102,400 objects of 1 KB 321each. Further, suppose you routinely run a batch job to change the value of 322a single two-byte attribute value that appears in each of the 102,400 objects 323on the provider. Not counting LDAP and TCP/IP protocol overhead, each time you 324run this job each consumer will transfer and process {{B:100 MB}} of data to 325process {{B:200KB of changes!}} 326 32799.98% of the data that is transmitted and processed in a case like this will 328be redundant, since it represents values that did not change. This is a waste 329of valuable transmission and processing bandwidth and can cause an unacceptable 330replication backlog to develop. While this situation is extreme, it serves to 331demonstrate a very real problem that is encountered in some LDAP deployments. 332 333 334* Where Delta-syncrepl comes in: 335 336Delta-syncrepl, a changelog-based variant of syncrepl, is designed to address 337situations like the one described above. Delta-syncrepl works by maintaining a 338changelog of a selectable depth in a separate database on the provider. The replication consumer 339checks the changelog for the changes it needs and, as long as 340the changelog contains the needed changes, the consumer fetches the changes 341from the changelog and applies them to its database. If, however, a consumer 342is too far out of sync (or completely empty), conventional syncrepl is used to 343bring it up to date and replication then switches back to the delta-syncrepl 344mode. 345 346Note: since the database state is stored in both the changelog DB and the 347main DB on the provider, it is important to backup/restore both the changelog 348DB and the main DB using slapcat/slapadd when restoring a DB or copying 349it to another machine. 350 351For configuration, please see the {{SECT:Delta-syncrepl}} section. 352 353 354H3: N-Way Multi-Provider Replication 355 356Multi-Provider replication is a replication technique using Syncrepl to replicate 357data to multiple provider ("Provider") Directory servers. 358 359H4: Valid Arguments for Multi-Provider replication 360 361* If any provider fails, other providers will continue to accept updates 362* Avoids a single point of failure 363* Providers can be located in several physical sites i.e. distributed across 364the network/globe. 365* Good for Automatic failover/High Availability 366 367H4: Invalid Arguments for Multi-Provider replication 368 369(These are often claimed to be advantages of Multi-Provider replication but 370those claims are false): 371 372* It has {{B:NOTHING}} to do with load balancing 373* Providers {{B:must}} propagate writes to {{B:all}} the other servers, which 374means the network traffic and write load spreads across all 375of the servers the same as for single-provider. 376* Server utilization and performance are at best identical for 377Multi-Provider and Single-Provider replication; at worst Single-Provider is 378superior because indexing can be tuned differently to optimize for the 379different usage patterns between the provider and the consumers. 380 381H4: Arguments against Multi-Provider replication 382 383* Breaks the data consistency guarantees of the directory model 384* {{URL:http://www.openldap.org/faq/data/cache/1240.html}} 385* If connectivity with a provider is lost because of a network partition, then 386"automatic failover" can just compound the problem 387* Typically, a particular machine cannot distinguish between losing contact 388 with a peer because that peer crashed, or because the network link has failed 389* If a network is partitioned and multiple clients start writing to each of the 390"providers" then reconciliation will be a pain; it may be best to simply deny 391writes to the clients that are partitioned from the single provider 392 393 394For configuration, please see the {{SECT:N-Way Multi-Provider}} section below 395 396H3: Mirror mode replication 397 398Mirror mode is a hybrid configuration that provides all of the consistency 399guarantees of single-provider replication, while also providing the high 400availability of multi-provider. In Mirror mode two providers are set up to 401replicate from each other (as a multi-provider configuration), but an 402external frontend is employed to direct all writes to only one of 403the two servers. The second provider will only be used for writes if 404the first provider crashes, at which point the frontend will switch to 405directing all writes to the second provider. When a crashed provider is 406repaired and restarted it will automatically catch up to any changes 407on the running provider and resync. 408 409H4: Arguments for Mirror mode 410 411* Provides a high-availability (HA) solution for directory writes (replicas handle reads) 412* As long as one provider is operational, writes can safely be accepted 413* Provider nodes replicate from each other, so they are always up to date and 414can be ready to take over (hot standby) 415* Syncrepl also allows the provider nodes to re-synchronize after any downtime 416 417 418H4: Arguments against Mirror mode 419 420* Mirror mode is not what is termed as a Multi-Provider solution. This is because 421writes have to go to just one of the mirror nodes at a time 422* Mirror mode can be termed as Active-Active Hot-Standby, therefore an external 423server (slapd in proxy mode) or device (hardware load balancer) 424is needed to manage which provider is currently active 425* Backups are managed slightly differently 426 427For configuration, please see the {{SECT:Mirror mode}} section below 428 429 430H3: Syncrepl Proxy Mode 431 432While the LDAP Sync protocol supports both pull- and push-based replication, 433the push mode (refreshAndPersist) must still be initiated from the consumer 434before the provider can begin pushing changes. In some network configurations, 435particularly where firewalls restrict the direction in which connections 436can be made, a provider-initiated push mode may be needed. 437 438This mode can be configured with the aid of the LDAP Backend 439({{SECT: Backends}} and {{slapd-ldap(8)}}). Instead of running the 440syncrepl engine on the actual consumer, a slapd-ldap proxy is set up 441near (or collocated with) the provider that points to the consumer, 442and the syncrepl engine runs on the proxy. 443 444For configuration, please see the {{SECT:Syncrepl Proxy}} section. 445 446H2: Configuring the different replication types 447 448H3: Syncrepl 449 450H4: Syncrepl configuration 451 452Because syncrepl is a consumer-side replication engine, the syncrepl 453specification is defined in {{slapd.conf}}(5) of the consumer 454server, not in the provider server's configuration file. The initial 455loading of the consumer content can be performed either by starting 456the syncrepl engine with no synchronization cookie or by populating 457the consumer by loading an {{TERM:LDIF}} file dumped as a 458backup at the provider. 459 460When loading from a backup, it is not required to perform the initial 461loading from the up-to-date backup of the provider content. The 462syncrepl engine will automatically synchronize the initial consumer 463to the current provider content. As a result, it is not 464required to stop the provider server in order to avoid the replication 465inconsistency caused by the updates to the provider content during 466the content backup and loading process. 467 468When replicating a large scale directory, especially in a bandwidth 469constrained environment, it is advised to load the consumer 470from a backup instead of performing a full initial load using 471syncrepl. 472 473 474H4: Set up the provider slapd 475 476The provider is implemented as an overlay, so the overlay itself 477must first be configured in {{slapd.conf}}(5) before it can be 478used. The provider has two primary configuration directives and 479two secondary directives for when delta-syncrepl is being used. 480Because the LDAP Sync search is subject to access control, proper 481access control privileges should be set up for the replicated 482content. 483 484The two primary options to configure are the checkpoint and 485sessionlog behaviors. 486 487The {{EX:contextCSN}} checkpoint is configured by the 488 489> syncprov-checkpoint <ops> <minutes> 490 491directive. Checkpoints are only tested after successful write 492operations. If {{<ops>}} operations or more than {{<minutes>}} 493time has passed since the last checkpoint, a new checkpoint is 494performed. Checkpointing is disabled by default. 495 496The session log is configured by the 497 498> syncprov-sessionlog <ops> 499 500directive, where {{<ops>}} is the maximum number of session log 501entries the session log can record. All write operations (except Adds) 502are recorded in the log. 503 504Note that using the session log requires searching on the {{entryUUID}} 505attribute. Setting an eq index on this attribute will greatly benefit 506the performance of the session log on the provider. 507 508The reloadhint option is configured by the 509 510> syncprov-reloadhint <TRUE|FALSE> 511 512directive. It must be set TRUE when using the accesslog overlay for 513delta-based syncrepl replication support. The default is FALSE. 514 515The nonpresent option should only be configured if the overlay is 516being placed on top of a log database, such as when used with 517delta-syncrepl. 518 519The nonpresent option is configured by the 520 521> syncprov-nopresent <TRUE|FALSE> 522 523directive. This value should only be set TRUE for a syncprov instance 524on top of a log database (such as one managed by the accesslog overlay). 525The default is FALSE. 526 527A more complete example of the {{slapd.conf}}(5) content is thus: 528 529> database mdb 530> maxsize 1073741824 531> suffix dc=Example,dc=com 532> rootdn dc=Example,dc=com 533> directory /var/ldap/db 534> index objectclass,entryCSN,entryUUID eq 535> 536> overlay syncprov 537> syncprov-checkpoint 100 10 538> syncprov-sessionlog 100 539 540 541H4: Set up the consumer slapd 542 543The syncrepl directive is specified in the database section of 544{{slapd.conf}}(5) for the consumer context. The syncrepl engine 545is backend independent and the directive can be defined with any 546database type. 547 548> database mdb 549> maxsize 1073741824 550> suffix dc=Example,dc=com 551> rootdn dc=Example,dc=com 552> directory /var/ldap/db 553> index objectclass,entryCSN,entryUUID eq 554> 555> syncrepl rid=123 556> provider=ldap://provider.example.com:389 557> type=refreshOnly 558> interval=01:00:00:00 559> searchbase="dc=example,dc=com" 560> filter="(objectClass=organizationalPerson)" 561> scope=sub 562> attrs="cn,sn,ou,telephoneNumber,title,l" 563> schemachecking=off 564> bindmethod=simple 565> binddn="cn=syncuser,dc=example,dc=com" 566> credentials=secret 567 568In this example, the consumer will connect to the provider {{slapd}}(8) 569at port 389 of {{FILE:ldap://provider.example.com}} to perform a 570polling ({{refreshOnly}}) mode of synchronization once a day. It 571will bind as {{EX:cn=syncuser,dc=example,dc=com}} using simple 572authentication with password "secret". Note that the access control 573privilege of {{EX:cn=syncuser,dc=example,dc=com}} should be set 574appropriately in the provider to retrieve the desired replication 575content. Also the search limits must be high enough on the provider 576to allow the syncuser to retrieve a complete copy of the requested 577content. The consumer uses the rootdn to write to its database so 578it always has full permissions to write all content. 579 580The synchronization search in the above example will search for the 581entries whose objectClass is organizationalPerson in the entire 582subtree rooted at {{EX:dc=example,dc=com}}. The requested attributes 583are {{EX:cn}}, {{EX:sn}}, {{EX:ou}}, {{EX:telephoneNumber}}, 584{{EX:title}}, and {{EX:l}}. The schema checking is turned off, so 585that the consumer {{slapd}}(8) will not enforce entry schema 586checking when it processes updates from the provider {{slapd}}(8). 587 588For more detailed information on the syncrepl directive, see the 589{{SECT:syncrepl}} section of {{SECT:The slapd Configuration File}} 590chapter of this admin guide. 591 592 593H4: Start the provider and the consumer slapd 594 595The provider {{slapd}}(8) is not required to be restarted. 596{{contextCSN}} is automatically generated as needed: it might be 597originally contained in the {{TERM:LDIF}} file, generated by 598{{slapadd}} (8), generated upon changes in the context, or generated 599when the first LDAP Sync search arrives at the provider. If an 600LDIF file is being loaded which did not previously contain the 601{{contextCSN}}, the {{-w}} option should be used with {{slapadd}} 602(8) to cause it to be generated. This will allow the server to 603startup a little quicker the first time it runs. 604 605When starting a consumer {{slapd}}(8), it is possible to provide 606a synchronization cookie as the {{-c cookie}} command line option 607in order to start the synchronization from a specific state. The 608cookie is a comma separated list of name=value pairs. Currently 609supported syncrepl cookie fields are {{csn=<csn>}} and {{rid=<rid>}}. 610{{<csn>}} represents the current synchronization state of the 611consumer. {{<rid>}} identifies a consumer locally 612within the consumer server. It is used to relate the cookie to the 613syncrepl definition in {{slapd.conf}}(5) which has the matching 614{{<rid>}}. The {{<rid>}} must have no more than 3 decimal 615digits. The command line cookie overrides the synchronization 616cookie stored in the consumer database. 617 618 619H3: Delta-syncrepl 620 621H4: Delta-syncrepl Provider configuration 622 623Setting up delta-syncrepl requires configuration changes on both the provider and 624replica servers: 625 626> # Give the replicator DN unlimited read access. This ACL needs to be 627> # merged with other ACL statements, and/or moved within the scope 628> # of a database. The "by * break" portion causes evaluation of 629> # subsequent rules. See slapd.access(5) for details. 630> access to * 631> by dn.base="cn=replicator,dc=example,dc=com" read 632> by * break 633> 634> # Set the module path location 635> modulepath /opt/symas/lib/openldap 636> 637> # Load the mdb backend 638> moduleload back_mdb.la 639> 640> # Load the accesslog overlay 641> moduleload accesslog.la 642> 643> #Load the syncprov overlay 644> moduleload syncprov.la 645> 646> # Accesslog database definitions 647> database mdb 648> suffix cn=accesslog 649> directory /db/accesslog 650> rootdn cn=accesslog 651> index default eq 652> index entryCSN,objectClass,reqEnd,reqResult,reqStart,reqDN 653> 654> overlay syncprov 655> syncprov-nopresent TRUE 656> syncprov-reloadhint TRUE 657> 658> # Let the replicator DN have limitless searches 659> limits dn.exact="cn=replicator,dc=example,dc=com" time.soft=unlimited time.hard=unlimited size.soft=unlimited size.hard=unlimited 660> 661> # Primary database definitions 662> database mdb 663> suffix "dc=symas,dc=com" 664> rootdn "cn=manager,dc=symas,dc=com" 665> 666> ## Whatever other configuration options are desired 667> 668> # syncprov specific indexing 669> index entryCSN eq 670> index entryUUID eq 671> 672> # syncrepl Provider for primary db 673> overlay syncprov 674> syncprov-checkpoint 1000 60 675> 676> # accesslog overlay definitions for primary db 677> overlay accesslog 678> logdb cn=accesslog 679> logops writes 680> logsuccess TRUE 681> # scan the accesslog DB every day, and purge entries older than 7 days 682> logpurge 07+00:00 01+00:00 683> 684> # Let the replicator DN have limitless searches 685> limits dn.exact="cn=replicator,dc=example,dc=com" time.soft=unlimited time.hard=unlimited size.soft=unlimited size.hard=unlimited 686 687For more information, always consult the relevant man pages ({{slapo-accesslog}}(5) and {{slapd.conf}}(5)) 688 689 690H4: Delta-syncrepl Consumer configuration 691 692> # Replica database configuration 693> database mdb 694> suffix "dc=symas,dc=com" 695> rootdn "cn=manager,dc=symas,dc=com" 696> 697> ## Whatever other configuration bits for the replica, like indexing 698> ## that you want 699> 700> # syncrepl specific indices 701> index entryUUID eq 702> 703> # syncrepl directives 704> syncrepl rid=0 705> provider=ldap://ldapprovider.example.com:389 706> bindmethod=simple 707> binddn="cn=replicator,dc=example,dc=com" 708> credentials=secret 709> searchbase="dc=example,dc=com" 710> logbase="cn=accesslog" 711> logfilter="(&(objectClass=auditWriteObject)(reqResult=0))" 712> schemachecking=on 713> type=refreshAndPersist 714> retry="60 +" 715> syncdata=accesslog 716> 717> # Refer updates to the provider 718> updateref ldap://ldapprovider.example.com 719 720 721The above configuration assumes that you have a replicator identity defined 722in your database that can be used to bind to the provider. 723 724Note: An accesslog database is unique to a given provider. It should 725never be replicated. 726 727H3: N-Way Multi-Provider 728 729For the following example we will be using 3 Provider nodes. Keeping in line with 730{{B:test050-syncrepl-multiprovider}} of the OpenLDAP test suite, we will be configuring 731{{slapd(8)}} via {{B:cn=config}} 732 733This sets up the config database: 734 735> dn: cn=config 736> objectClass: olcGlobal 737> cn: config 738> olcServerID: 1 739> 740> dn: olcDatabase={0}config,cn=config 741> objectClass: olcDatabaseConfig 742> olcDatabase: {0}config 743> olcRootPW: secret 744 745Each server must have a unique server ID ({{EX:SID}}), so 746second and third servers will have a different {{EX:olcServerID}} obviously: 747 748> dn: cn=config 749> objectClass: olcGlobal 750> cn: config 751> olcServerID: 2 752> 753> dn: olcDatabase={0}config,cn=config 754> objectClass: olcDatabaseConfig 755> olcDatabase: {0}config 756> olcRootPW: secret 757 758This sets up syncrepl as a provider (since these are all providers): 759 760> dn: cn=module,cn=config 761> objectClass: olcModuleList 762> cn: module 763> olcModulePath: /usr/local/libexec/openldap 764> olcModuleLoad: syncprov.la 765 766Now we setup the first Provider Node (replace $URI1, $URI2 and $URI3 etc. with your actual ldap urls): 767 768> dn: cn=config 769> changetype: modify 770> replace: olcServerID 771> olcServerID: 1 $URI1 772> olcServerID: 2 $URI2 773> olcServerID: 3 $URI3 774> 775> dn: olcOverlay=syncprov,olcDatabase={0}config,cn=config 776> changetype: add 777> objectClass: olcOverlayConfig 778> objectClass: olcSyncProvConfig 779> olcOverlay: syncprov 780> 781> dn: olcDatabase={0}config,cn=config 782> changetype: modify 783> add: olcSyncRepl 784> olcSyncRepl: rid=001 provider=$URI1 binddn="cn=config" bindmethod=simple 785> credentials=secret searchbase="cn=config" type=refreshAndPersist 786> retry="5 5 300 5" timeout=1 787> olcSyncRepl: rid=002 provider=$URI2 binddn="cn=config" bindmethod=simple 788> credentials=secret searchbase="cn=config" type=refreshAndPersist 789> retry="5 5 300 5" timeout=1 790> olcSyncRepl: rid=003 provider=$URI3 binddn="cn=config" bindmethod=simple 791> credentials=secret searchbase="cn=config" type=refreshAndPersist 792> retry="5 5 300 5" timeout=1 793> - 794> add: olcMultiProvider 795> olcMultiProvider: TRUE 796 797Now start up the provider and a consumer/s, also add the above LDIF to the first consumer, second consumer etc. It will then replicate {{B:cn=config}}. You now have N-Way Multi-Provider on the config database. 798 799We still have to replicate the actual data, not just the config, so add to the provider (all active and configured consumers/providers will pull down this config, as they are all syncing). Also, replace all {{${}}} variables with whatever is applicable to your setup: 800 801> dn: olcDatabase={1}$BACKEND,cn=config 802> objectClass: olcDatabaseConfig 803> objectClass: olc${BACKEND}Config 804> olcDatabase: {1}$BACKEND 805> olcSuffix: $BASEDN 806> olcDbDirectory: ./db 807> olcRootDN: $MANAGERDN 808> olcRootPW: $PASSWD 809> olcLimits: dn.exact="$MANAGERDN" time.soft=unlimited time.hard=unlimited 810> size.soft=unlimited size.hard=unlimited 811> olcSyncRepl: rid=004 provider=$URI1 binddn="$MANAGERDN" bindmethod=simple 812> credentials=$PASSWD searchbase="$BASEDN" type=refreshOnly 813> interval=00:00:00:10 retry="5 5 300 5" timeout=1 814> olcSyncRepl: rid=005 provider=$URI2 binddn="$MANAGERDN" bindmethod=simple 815> credentials=$PASSWD searchbase="$BASEDN" type=refreshOnly 816> interval=00:00:00:10 retry="5 5 300 5" timeout=1 817> olcSyncRepl: rid=006 provider=$URI3 binddn="$MANAGERDN" bindmethod=simple 818> credentials=$PASSWD searchbase="$BASEDN" type=refreshOnly 819> interval=00:00:00:10 retry="5 5 300 5" timeout=1 820> olcMultiProvider: TRUE 821> 822> dn: olcOverlay=syncprov,olcDatabase={1}${BACKEND},cn=config 823> changetype: add 824> objectClass: olcOverlayConfig 825> objectClass: olcSyncProvConfig 826> olcOverlay: syncprov 827 828Note: All of your servers' clocks must be tightly synchronized using 829e.g. NTP {{http://www.ntp.org/}}, atomic clock, or some other reliable 830time reference. 831 832Note: As stated in {{slapd-config}}(5), URLs specified in {{olcSyncRepl}} 833directives are the URLs of the servers from which to replicate. These 834must exactly match the URLs {{slapd}} listens on ({{-h}} in {{SECT:Command-Line Options}}). 835Otherwise slapd may attempt to replicate from itself, causing a loop. 836 837Note: The {{entryCSN}} and {{contextCSN}} attributes are used 838to track changes to an entry and naming context, respectively. The 839{{EX:SID}} which must be unique for each replication provider is a 840component of these CSNs. If you're using {{slapadd}} to load a 841database and there are no entryCSNs already present in the input 842LDIF, {{slapadd}} will generate them with a {{SID}} of {{EX:000}}. This 843is not a valid {{SID}} for multi-provider replication, and you 844should use the {{EX:-S}} option of {{slapadd}} (8) to specify 845a valid {{SID}} for these generated CSNs. If there are existing 846entryCSNs in the input LDIF, {{slapadd}} will not change them. 847 848H3: Mirror mode 849 850Mirror mode configuration is actually very easy. If you have ever setup a normal 851slapd syncrepl provider, then the only change is the following two directives: 852 853> multiprovider on 854> serverID 1 855 856Note: You need to make sure that the {{serverID}} of each provider node is 857different and add it as a global configuration option. 858 859H4: Mirror Node Configuration 860 861The first step is to configure the syncrepl provider the same as in the 862{{SECT:Set up the provider slapd}} section. 863 864Here's a specific cut down example using {{SECT:LDAP Sync Replication}} in 865{{refreshAndPersist}} mode: 866 867Mirror mode node 1: 868 869> # Global section 870> serverID 1 871> # database section 872> 873> # syncrepl directive 874> syncrepl rid=001 875> provider=ldap://ldap-sid2.example.com 876> bindmethod=simple 877> binddn="cn=mirrormode,dc=example,dc=com" 878> credentials=mirrormode 879> searchbase="dc=example,dc=com" 880> schemachecking=on 881> type=refreshAndPersist 882> retry="60 +" 883> 884> multiprovider on 885 886Mirror mode node 2: 887 888> # Global section 889> serverID 2 890> # database section 891> 892> # syncrepl directive 893> syncrepl rid=001 894> provider=ldap://ldap-sid1.example.com 895> bindmethod=simple 896> binddn="cn=mirrormode,dc=example,dc=com" 897> credentials=mirrormode 898> searchbase="dc=example,dc=com" 899> schemachecking=on 900> type=refreshAndPersist 901> retry="60 +" 902> 903> multiprovider on 904 905It's simple really; each Mirror mode node is setup {{B:exactly}} the same, except 906that the {{serverID}} is unique, and each consumer is pointed to 907the other server. 908 909H5: Failover Configuration 910 911There are generally 2 choices for this; 1. Hardware proxies/load-balancing or 912dedicated proxy software, 2. using a Back-LDAP proxy as a syncrepl provider 913 914A typical enterprise example might be: 915 916!import "dual_dc.png"; align="center"; title="Mirror mode Enterprise Configuration" 917FT[align="Center"] Figure X.Y: Mirror mode in a Dual Data Center Configuration 918 919H5: Normal Consumer Configuration 920 921This is exactly the same as the {{SECT:Set up the consumer slapd}} section. It 922can either setup in normal {{SECT:syncrepl replication}} mode, or in 923{{SECT:delta-syncrepl replication}} mode. 924 925H4: Mirror mode Summary 926 927You will now have a directory architecture that provides all of the 928consistency guarantees of single-provider replication, while also providing the 929high availability of multi-provider replication. 930 931 932H3: Syncrepl Proxy 933 934!import "push-based-complete.png"; align="center"; title="Syncrepl Proxy Mode" 935FT[align="Center"] Figure X.Y: Replacing slurpd 936 937The following example is for a self-contained push-based replication solution: 938 939> ####################################################################### 940> # Standard OpenLDAP Provider 941> ####################################################################### 942> 943> include /usr/local/etc/openldap/schema/core.schema 944> include /usr/local/etc/openldap/schema/cosine.schema 945> include /usr/local/etc/openldap/schema/nis.schema 946> include /usr/local/etc/openldap/schema/inetorgperson.schema 947> 948> include /usr/local/etc/openldap/slapd.acl 949> 950> modulepath /usr/local/libexec/openldap 951> moduleload back_mdb.la 952> moduleload syncprov.la 953> moduleload back_ldap.la 954> 955> pidfile /usr/local/var/slapd.pid 956> argsfile /usr/local/var/slapd.args 957> 958> loglevel sync stats 959> 960> database mdb 961> suffix "dc=suretecsystems,dc=com" 962> directory /usr/local/var/openldap-data 963> 964> checkpoint 1024 5 965> 966> index objectClass eq 967> # rest of indexes 968> index default sub 969> 970> rootdn "cn=admin,dc=suretecsystems,dc=com" 971> rootpw testing 972> 973> # syncprov specific indexing 974> index entryCSN eq 975> index entryUUID eq 976> 977> # syncrepl Provider for primary db 978> overlay syncprov 979> syncprov-checkpoint 1000 60 980> 981> # Let the replicator DN have limitless searches 982> limits dn.exact="cn=replicator,dc=suretecsystems,dc=com" time.soft=unlimited time.hard=unlimited size.soft=unlimited size.hard=unlimited 983> 984> database monitor 985> 986> database config 987> rootpw testing 988> 989> ############################################################################## 990> # Consumer Proxy that pulls in data via Syncrepl and pushes out via slapd-ldap 991> ############################################################################## 992> 993> database ldap 994> # ignore conflicts with other databases, as we need to push out to same suffix 995> hidden on 996> suffix "dc=suretecsystems,dc=com" 997> rootdn "cn=slapd-ldap" 998> uri ldap://localhost:9012/ 999> 1000> lastmod on 1001> 1002> # We don't need any access to this DSA 1003> restrict all 1004> 1005> acl-bind bindmethod=simple 1006> binddn="cn=replicator,dc=suretecsystems,dc=com" 1007> credentials=testing 1008> 1009> syncrepl rid=001 1010> provider=ldap://localhost:9011/ 1011> binddn="cn=replicator,dc=suretecsystems,dc=com" 1012> bindmethod=simple 1013> credentials=testing 1014> searchbase="dc=suretecsystems,dc=com" 1015> type=refreshAndPersist 1016> retry="5 5 300 5" 1017> 1018> overlay syncprov 1019 1020A replica configuration for this type of setup could be: 1021 1022> ####################################################################### 1023> # Standard OpenLDAP Replica without Syncrepl 1024> ####################################################################### 1025> 1026> include /usr/local/etc/openldap/schema/core.schema 1027> include /usr/local/etc/openldap/schema/cosine.schema 1028> include /usr/local/etc/openldap/schema/nis.schema 1029> include /usr/local/etc/openldap/schema/inetorgperson.schema 1030> 1031> include /usr/local/etc/openldap/slapd.acl 1032> 1033> modulepath /usr/local/libexec/openldap 1034> moduleload back_mdb.la 1035> moduleload syncprov.la 1036> moduleload back_ldap.la 1037> 1038> pidfile /usr/local/var/slapd.pid 1039> argsfile /usr/local/var/slapd.args 1040> 1041> loglevel sync stats 1042> 1043> database mdb 1044> suffix "dc=suretecsystems,dc=com" 1045> directory /usr/local/var/openldap-consumer/data 1046> 1047> maxsize 85899345920 1048> checkpoint 1024 5 1049> 1050> index objectClass eq 1051> # rest of indexes 1052> index default sub 1053> 1054> rootdn "cn=admin,dc=suretecsystems,dc=com" 1055> rootpw testing 1056> 1057> # Let the replicator DN have limitless searches 1058> limits dn.exact="cn=replicator,dc=suretecsystems,dc=com" time.soft=unlimited time.hard=unlimited size.soft=unlimited size.hard=unlimited 1059> 1060> updatedn "cn=replicator,dc=suretecsystems,dc=com" 1061> 1062> # Refer updates to the provider 1063> updateref ldap://localhost:9011 1064> 1065> database monitor 1066> 1067> database config 1068> rootpw testing 1069 1070You can see we use the {{updatedn}} directive here and example ACLs ({{F:usr/local/etc/openldap/slapd.acl}}) for this could be: 1071 1072> # Give the replicator DN unlimited read access. This ACL may need to be 1073> # merged with other ACL statements. 1074> 1075> access to * 1076> by dn.base="cn=replicator,dc=suretecsystems,dc=com" write 1077> by * break 1078> 1079> access to dn.base="" 1080> by * read 1081> 1082> access to dn.base="cn=Subschema" 1083> by * read 1084> 1085> access to dn.subtree="cn=Monitor" 1086> by dn.exact="uid=admin,dc=suretecsystems,dc=com" write 1087> by users read 1088> by * none 1089> 1090> access to * 1091> by self write 1092> by * read 1093 1094In order to support more replicas, just add more {{database ldap}} sections and 1095increment the {{syncrepl rid}} number accordingly. 1096 1097Note: You must populate the Provider and Replica directories with the same data, 1098unlike when using normal Syncrepl 1099 1100If you do not have access to modify the provider directory configuration you can 1101configure a standalone ldap proxy, which might look like: 1102 1103!import "push-based-standalone.png"; align="center"; title="Syncrepl Standalone Proxy Mode" 1104FT[align="Center"] Figure X.Y: Replacing slurpd with a standalone version 1105 1106The following configuration is an example of a standalone LDAP Proxy: 1107 1108> include /usr/local/etc/openldap/schema/core.schema 1109> include /usr/local/etc/openldap/schema/cosine.schema 1110> include /usr/local/etc/openldap/schema/nis.schema 1111> include /usr/local/etc/openldap/schema/inetorgperson.schema 1112> 1113> include /usr/local/etc/openldap/slapd.acl 1114> 1115> modulepath /usr/local/libexec/openldap 1116> moduleload syncprov.la 1117> moduleload back_ldap.la 1118> 1119> ############################################################################## 1120> # Consumer Proxy that pulls in data via Syncrepl and pushes out via slapd-ldap 1121> ############################################################################## 1122> 1123> database ldap 1124> # ignore conflicts with other databases, as we need to push out to same suffix 1125> hidden on 1126> suffix "dc=suretecsystems,dc=com" 1127> rootdn "cn=slapd-ldap" 1128> uri ldap://localhost:9012/ 1129> 1130> lastmod on 1131> 1132> # We don't need any access to this DSA 1133> restrict all 1134> 1135> acl-bind bindmethod=simple 1136> binddn="cn=replicator,dc=suretecsystems,dc=com" 1137> credentials=testing 1138> 1139> syncrepl rid=001 1140> provider=ldap://localhost:9011/ 1141> binddn="cn=replicator,dc=suretecsystems,dc=com" 1142> bindmethod=simple 1143> credentials=testing 1144> searchbase="dc=suretecsystems,dc=com" 1145> type=refreshAndPersist 1146> retry="5 5 300 5" 1147> 1148> overlay syncprov 1149 1150As you can see, you can let your imagination go wild using Syncrepl and 1151{{slapd-ldap(8)}} tailoring your replication to fit your specific network 1152topology. 1153