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