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