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