]> git.sur5r.net Git - openldap/blob - doc/guide/admin/replication.sdf
fix indent
[openldap] / doc / guide / admin / replication.sdf
1 # $OpenLDAP$
2 # Copyright 1999-2007 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 OpenLDAP has various configuration options for creating a replicated 
11 directory. The following sections will discuss these.
12
13 H2: Replication Strategies
14
15
16 H3: Push Based
17
18
19 H5: Replacing Slurpd
20
21 Slurpd replication has been deprecated in favor of Syncrepl replication and 
22 has been completely removed from 2.4.
23
24 {{Why was it replaced?}}
25
26 The slurpd daemon was the original replication mechanism inherited from 
27 UMich's LDAP and operates in push mode: the master pushes changes to the 
28 slaves. It has been replaced for many reasons, in brief:
29
30  * It is not reliable
31  * It is extremely sensitive to the ordering of records in the replog
32  * It can easily go out of sync, at which point manual intervention is 
33    required to resync the slave database with the master directory
34  * It isn't very tolerant of unavailable servers. If a slave goes down 
35    for a long time, the replog may grow to a size that's too large for 
36    slurpd to process
37
38 {{What was it replaced with?}}
39
40 Syncrepl.
41
42 {{Why is Syncrepl better?}}
43
44  * Syncrepl is self-synchronizing; you can start with a database in any 
45    state from totally empty to fully synced and it will automatically do 
46    the right thing to achieve and maintain synchronization
47  * Syncrepl can operate in either direction
48  * Data updates can be minimal or maximal
49
50 {{How do I implement a pushed based replication system using Syncrepl?}}
51
52 The easiest way is to point an LDAP backend ({{SECT: Backends}} and {{slapd-ldap(8)}}) 
53 to your slave directory and setup Syncrepl to point to your Master database.
54
55 REFERENCE test045/048 for better explanation of above.
56
57 If you imagine Syncrepl pulling down changes from the Master server, and then
58 pushing those changes out to your slave servers via {{slapd-ldap(8)}}. This is 
59 called proxy mode (elaborate/confirm?).
60
61 DIAGRAM HERE
62
63 BETTER EXAMPLE here from test045/048 for different push/multiproxy examples.
64
65 Here's an example:
66
67
68 >       include         ./schema/core.schema
69 >       include         ./schema/cosine.schema
70 >       include         ./schema/inetorgperson.schema
71 >       include         ./schema/openldap.schema
72 >       include         ./schema/nis.schema
73 >       
74 >       pidfile         /home/ghenry/openldap/ldap/tests/testrun/slapd.3.pid
75 >       argsfile        /home/ghenry/openldap/ldap/tests/testrun/slapd.3.args
76 >       
77 >       modulepath      ../servers/slapd/back-bdb/
78 >       moduleload      back_bdb.la
79 >       modulepath  ../servers/slapd/back-monitor/
80 >       moduleload  back_monitor.la
81 >       modulepath  ../servers/slapd/overlays/
82 >       moduleload  syncprov.la
83 >       modulepath  ../servers/slapd/back-ldap/
84 >       moduleload  back_ldap.la
85 >       
86 >       # We don't need any access to this DSA
87 >       restrict        all
88 >       
89 >       #######################################################################
90 >       # consumer proxy database definitions
91 >       #######################################################################
92 >       
93 >       database        ldap
94 >       suffix          "dc=example,dc=com"
95 >       rootdn          "cn=Whoever"
96 >       uri             ldap://localhost:9012/
97 >       
98 >       lastmod         on
99 >       
100 >       # HACK: use the RootDN of the monitor database as UpdateDN so ACLs apply
101 >       # without the need to write the UpdateDN before starting replication
102 >       acl-bind        bindmethod=simple
103 >                       binddn="cn=Monitor"
104 >                       credentials=monitor
105 >       
106 >       # HACK: use the RootDN of the monitor database as UpdateDN so ACLs apply
107 >       # without the need to write the UpdateDN before starting replication
108 >       syncrepl        rid=1
109 >                       provider=ldap://localhost:9011/
110 >                       binddn="cn=Manager,dc=example,dc=com"
111 >                       bindmethod=simple
112 >                       credentials=secret
113 >                       searchbase="dc=example,dc=com"
114 >                       filter="(objectClass=*)"
115 >                       attrs="*,structuralObjectClass,entryUUID,entryCSN,creatorsName,createTimestamp,modifiersName,modifyTimestamp"
116 >                       schemachecking=off
117 >                       scope=sub
118 >                       type=refreshAndPersist
119 >                       retry="5 5 300 5"
120 >       
121 >       overlay         syncprov
122 >       
123 >       database        monitor
124
125 DETAILED EXPLANATION OF ABOVE LIKE IN OTHER SECTIONS (line numbers?)
126
127
128 ANOTHER DIAGRAM HERE
129
130 As you can see, you can let your imagination go wild using Syncrepl and 
131 {{slapd-ldap(8)}} tailoring your replication to fit your specific network 
132 topology.
133
134 H3: Pull Based
135
136
137 H4: syncrepl replication
138
139
140 H4: delta-syncrepl replication
141
142
143 H2: Replication Types
144
145
146 H3: syncrepl replication
147
148
149 H3: delta-syncrepl replication
150
151
152 H3: N-Way Multi-Master
153
154 http://www.connexitor.com/blog/pivot/entry.php?id=105#body
155 http://www.openldap.org/lists/openldap-software/200702/msg00006.html
156 http://www.openldap.org/lists/openldap-software/200602/msg00064.html
157
158
159 H3: MirrorMode
160
161 MirrorMode is a hybrid configuration that provides all of the consistency
162 guarantees of single-master replication while also providing the high
163 availability of multi-master. In MirrorMode two masters are set up to
164 replicate from each other (as a multi-master configuration) but an
165 external frontend is employed to direct all writes to only one of
166 the two servers. The second master will only be used for writes if
167 the first master crashes, at which point the frontend will switch to
168 directing all writes to the second master. When a crashed master is
169 repaired and restarted it will automatically catch up to any changes
170 on the running master and resync.
171
172 H2: LDAP Sync Replication
173
174 The {{TERM:LDAP Sync}} Replication engine, {{TERM:syncrepl}} for
175 short, is a consumer-side replication engine that enables the
176 consumer {{TERM:LDAP}} server to maintain a shadow copy of a
177 {{TERM:DIT}} fragment. A syncrepl engine resides at the consumer-side
178 as one of the {{slapd}}(8) threads. It creates and maintains a
179 consumer replica by connecting to the replication provider to perform
180 the initial DIT content load followed either by periodic content
181 polling or by timely updates upon content changes.
182
183 Syncrepl uses the LDAP Content Synchronization (or LDAP Sync for
184 short) protocol as the replica synchronization protocol.  It provides
185 a stateful replication which supports both pull-based and push-based
186 synchronization and does not mandate the use of a history store.
187
188 Syncrepl keeps track of the status of the replication content by
189 maintaining and exchanging synchronization cookies. Because the
190 syncrepl consumer and provider maintain their content status, the
191 consumer can poll the provider content to perform incremental
192 synchronization by asking for the entries required to make the
193 consumer replica up-to-date with the provider content. Syncrepl
194 also enables convenient management of replicas by maintaining replica
195 status.  The consumer replica can be constructed from a consumer-side
196 or a provider-side backup at any synchronization status. Syncrepl
197 can automatically resynchronize the consumer replica up-to-date
198 with the current provider content.
199
200 Syncrepl supports both pull-based and push-based synchronization.
201 In its basic refreshOnly synchronization mode, the provider uses
202 pull-based synchronization where the consumer servers need not be
203 tracked and no history information is maintained.  The information
204 required for the provider to process periodic polling requests is
205 contained in the synchronization cookie of the request itself.  To
206 optimize the pull-based synchronization, syncrepl utilizes the
207 present phase of the LDAP Sync protocol as well as its delete phase,
208 instead of falling back on frequent full reloads. To further optimize
209 the pull-based synchronization, the provider can maintain a per-scope
210 session log as a history store. In its refreshAndPersist mode of
211 synchronization, the provider uses a push-based synchronization.
212 The provider keeps track of the consumer servers that have requested
213 a persistent search and sends them necessary updates as the provider
214 replication content gets modified.
215
216 With syncrepl, a consumer server can create a replica without
217 changing the provider's configurations and without restarting the
218 provider server, if the consumer server has appropriate access
219 privileges for the DIT fragment to be replicated. The consumer
220 server can stop the replication also without the need for provider-side
221 changes and restart.
222
223 Syncrepl supports both partial and sparse replications.  The shadow
224 DIT fragment is defined by a general search criteria consisting of
225 base, scope, filter, and attribute list.  The replica content is
226 also subject to the access privileges of the bind identity of the
227 syncrepl replication connection.
228
229
230 H3: The LDAP Content Synchronization Protocol
231
232 The LDAP Sync protocol allows a client to maintain a synchronized
233 copy of a DIT fragment. The LDAP Sync operation is defined as a set
234 of controls and other protocol elements which extend the LDAP search
235 operation. This section introduces the LDAP Content Sync protocol
236 only briefly.  For more information, refer to {{REF:RFC4533}}.
237
238 The LDAP Sync protocol supports both polling and listening for
239 changes by defining two respective synchronization operations:
240 {{refreshOnly}} and {{refreshAndPersist}}.  Polling is implemented
241 by the {{refreshOnly}} operation.  The client copy is synchronized
242 to the server copy at the time of polling.  The server finishes the
243 search operation by returning {{SearchResultDone}} at the end of
244 the search operation as in the normal search.  The listening is
245 implemented by the {{refreshAndPersist}} operation.  Instead of
246 finishing the search after returning all entries currently matching
247 the search criteria, the synchronization search remains persistent
248 in the server. Subsequent updates to the synchronization content
249 in the server cause additional entry updates to be sent to the
250 client.
251
252 The {{refreshOnly}} operation and the refresh stage of the
253 {{refreshAndPersist}} operation can be performed with a present
254 phase or a delete phase.
255
256 In the present phase, the server sends the client the entries updated
257 within the search scope since the last synchronization. The server
258 sends all requested attributes, be it changed or not, of the updated
259 entries.  For each unchanged entry which remains in the scope, the
260 server sends a present message consisting only of the name of the
261 entry and the synchronization control representing state present.
262 The present message does not contain any attributes of the entry.
263 After the client receives all update and present entries, it can
264 reliably determine the new client copy by adding the entries added
265 to the server, by replacing the entries modified at the server, and
266 by deleting entries in the client copy which have not been updated
267 nor specified as being present at the server.
268
269 The transmission of the updated entries in the delete phase is the
270 same as in the present phase. The server sends all the requested
271 attributes of the entries updated within the search scope since the
272 last synchronization to the client. In the delete phase, however,
273 the server sends a delete message for each entry deleted from the
274 search scope, instead of sending present messages.  The delete
275 message consists only of the name of the entry and the synchronization
276 control representing state delete.  The new client copy can be
277 determined by adding, modifying, and removing entries according to
278 the synchronization control attached to the {{SearchResultEntry}}
279 message.
280
281 In the case that the LDAP Sync server maintains a history store and
282 can determine which entries are scoped out of the client copy since
283 the last synchronization time, the server can use the delete phase.
284 If the server does not maintain any history store, cannot determine
285 the scoped-out entries from the history store, or the history store
286 does not cover the outdated synchronization state of the client,
287 the server should use the present phase.  The use of the present
288 phase is much more efficient than a full content reload in terms
289 of the synchronization traffic.  To reduce the synchronization
290 traffic further, the LDAP Sync protocol also provides several
291 optimizations such as the transmission of the normalized {{EX:entryUUID}}s
292 and the transmission of multiple {{EX:entryUUIDs}} in a single
293 {{syncIdSet}} message.
294
295 At the end of the {{refreshOnly}} synchronization, the server sends
296 a synchronization cookie to the client as a state indicator of the
297 client copy after the synchronization is completed.  The client
298 will present the received cookie when it requests the next incremental
299 synchronization to the server.
300
301 When {{refreshAndPersist}} synchronization is used, the server sends
302 a synchronization cookie at the end of the refresh stage by sending
303 a Sync Info message with TRUE refreshDone.  It also sends a
304 synchronization cookie by attaching it to {{SearchResultEntry}}
305 generated in the persist stage of the synchronization search. During
306 the persist stage, the server can also send a Sync Info message
307 containing the synchronization cookie at any time the server wants
308 to update the client-side state indicator.  The server also updates
309 a synchronization indicator of the client at the end of the persist
310 stage.
311
312 In the LDAP Sync protocol, entries are uniquely identified by the
313 {{EX:entryUUID}} attribute value. It can function as a reliable
314 identifier of the entry. The DN of the entry, on the other hand,
315 can be changed over time and hence cannot be considered as the
316 reliable identifier.  The {{EX:entryUUID}} is attached to each
317 {{SearchResultEntry}} or {{SearchResultReference}} as a part of the
318 synchronization control.
319
320
321 H3: Syncrepl Details
322
323 The syncrepl engine utilizes both the {{refreshOnly}} and the
324 {{refreshAndPersist}} operations of the LDAP Sync protocol.  If a
325 syncrepl specification is included in a database definition,
326 {{slapd}}(8) launches a syncrepl engine as a {{slapd}}(8) thread
327 and schedules its execution. If the {{refreshOnly}} operation is
328 specified, the syncrepl engine will be rescheduled at the interval
329 time after a synchronization operation is completed.  If the
330 {{refreshAndPersist}} operation is specified, the engine will remain
331 active and process the persistent synchronization messages from the
332 provider.
333
334 The syncrepl engine utilizes both the present phase and the delete
335 phase of the refresh synchronization. It is possible to configure
336 a per-scope session log in the provider server which stores the
337 {{EX:entryUUID}}s of a finite number of entries deleted from a
338 replication content.  Multiple replicas of single provider content
339 share the same per-scope session log. The syncrepl engine uses the
340 delete phase if the session log is present and the state of the
341 consumer server is recent enough that no session log entries are
342 truncated after the last synchronization of the client.  The syncrepl
343 engine uses the present phase if no session log is configured for
344 the replication content or if the consumer replica is too outdated
345 to be covered by the session log.  The current design of the session
346 log store is memory based, so the information contained in the
347 session log is not persistent over multiple provider invocations.
348 It is not currently supported to access the session log store by
349 using LDAP operations. It is also not currently supported to impose
350 access control to the session log.
351
352 As a further optimization, even in the case the synchronization
353 search is not associated with any session log, no entries will be
354 transmitted to the consumer server when there has been no update
355 in the replication context.
356
357 The syncrepl engine, which is a consumer-side replication engine,
358 can work with any backends. The LDAP Sync provider can be configured
359 as an overlay on any backend, but works best with the {{back-bdb}}
360 or {{back-hdb}} backend.
361
362 The LDAP Sync provider maintains a {{EX:contextCSN}} for each
363 database as the current synchronization state indicator of the
364 provider content.  It is the largest {{EX:entryCSN}} in the provider
365 context such that no transactions for an entry having smaller
366 {{EX:entryCSN}} value remains outstanding.  The {{EX:contextCSN}}
367 could not just be set to the largest issued {{EX:entryCSN}} because
368 {{EX:entryCSN}} is obtained before a transaction starts and
369 transactions are not committed in the issue order.
370
371 The provider stores the {{EX:contextCSN}} of a context in the
372 {{EX:contextCSN}} attribute of the context suffix entry. The attribute
373 is not written to the database after every update operation though;
374 instead it is maintained primarily in memory. At database start
375 time the provider reads the last saved {{EX:contextCSN}} into memory
376 and uses the in-memory copy exclusively thereafter. By default,
377 changes to the {{EX:contextCSN}} as a result of database updates
378 will not be written to the database until the server is cleanly
379 shut down. A checkpoint facility exists to cause the contextCSN to
380 be written out more frequently if desired.
381
382 Note that at startup time, if the provider is unable to read a
383 {{EX:contextCSN}} from the suffix entry, it will scan the entire
384 database to determine the value, and this scan may take quite a
385 long time on a large database. When a {{EX:contextCSN}} value is
386 read, the database will still be scanned for any {{EX:entryCSN}}
387 values greater than it, to make sure the {{EX:contextCSN}} value
388 truly reflects the greatest committed {{EX:entryCSN}} in the database.
389 On databases which support inequality indexing, setting an eq index
390 on the {{EX:entryCSN}} attribute and configuring {{contextCSN}}
391 checkpoints will greatly speed up this scanning step.
392
393 If no {{EX:contextCSN}} can be determined by reading and scanning
394 the database, a new value will be generated. Also, if scanning the
395 database yielded a greater {{EX:entryCSN}} than was previously
396 recorded in the suffix entry's {{EX:contextCSN}} attribute, a
397 checkpoint will be immediately written with the new value.
398
399 The consumer also stores its replica state, which is the provider's
400 {{EX:contextCSN}} received as a synchronization cookie, in the
401 {{EX:contextCSN}} attribute of the suffix entry.  The replica state
402 maintained by a consumer server is used as the synchronization state
403 indicator when it performs subsequent incremental synchronization
404 with the provider server. It is also used as a provider-side
405 synchronization state indicator when it functions as a secondary
406 provider server in a cascading replication configuration.  Since
407 the consumer and provider state information are maintained in the
408 same location within their respective databases, any consumer can
409 be promoted to a provider (and vice versa) without any special
410 actions.
411
412 Because a general search filter can be used in the syncrepl
413 specification, some entries in the context may be omitted from the
414 synchronization content.  The syncrepl engine creates a glue entry
415 to fill in the holes in the replica context if any part of the
416 replica content is subordinate to the holes. The glue entries will
417 not be returned in the search result unless {{ManageDsaIT}} control
418 is provided.
419
420 Also as a consequence of the search filter used in the syncrepl
421 specification, it is possible for a modification to remove an entry
422 from the replication scope even though the entry has not been deleted
423 on the provider. Logically the entry must be deleted on the consumer
424 but in {{refreshOnly}} mode the provider cannot detect and propagate
425 this change without the use of the session log.
426
427
428 H3: Configuring Syncrepl
429
430 Because syncrepl is a consumer-side replication engine, the syncrepl
431 specification is defined in {{slapd.conf}}(5) of the consumer
432 server, not in the provider server's configuration file.  The initial
433 loading of the replica content can be performed either by starting
434 the syncrepl engine with no synchronization cookie or by populating
435 the consumer replica by adding an {{TERM:LDIF}} file dumped as a
436 backup at the provider.
437
438 When loading from a backup, it is not required to perform the initial
439 loading from the up-to-date backup of the provider content. The
440 syncrepl engine will automatically synchronize the initial consumer
441 replica to the current provider content. As a result, it is not
442 required to stop the provider server in order to avoid the replica
443 inconsistency caused by the updates to the provider content during
444 the content backup and loading process.
445
446 When replicating a large scale directory, especially in a bandwidth
447 constrained environment, it is advised to load the consumer replica
448 from a backup instead of performing a full initial load using
449 syncrepl.
450
451
452 H4: Set up the provider slapd
453
454 The provider is implemented as an overlay, so the overlay itself
455 must first be configured in {{slapd.conf}}(5) before it can be
456 used. The provider has only two configuration directives, for setting
457 checkpoints on the {{EX:contextCSN}} and for configuring the session
458 log.  Because the LDAP Sync search is subject to access control,
459 proper access control privileges should be set up for the replicated
460 content.
461
462 The {{EX:contextCSN}} checkpoint is configured by the
463
464 >       syncprov-checkpoint <ops> <minutes>
465
466 directive. Checkpoints are only tested after successful write
467 operations.  If {{<ops>}} operations or more than {{<minutes>}}
468 time has passed since the last checkpoint, a new checkpoint is
469 performed.
470
471 The session log is configured by the
472
473 >       syncprov-sessionlog <size>
474
475 directive, where {{<size>}} is the maximum number of session log
476 entries the session log can record. When a session log is configured,
477 it is automatically used for all LDAP Sync searches within the
478 database.
479
480 Note that using the session log requires searching on the {{entryUUID}}
481 attribute. Setting an eq index on this attribute will greatly benefit
482 the performance of the session log on the provider.
483
484 A more complete example of the {{slapd.conf}}(5) content is thus:
485
486 >       database bdb
487 >       suffix dc=Example,dc=com
488 >       rootdn dc=Example,dc=com
489 >       directory /var/ldap/db
490 >       index objectclass,entryCSN,entryUUID eq
491 >
492 >       overlay syncprov
493 >       syncprov-checkpoint 100 10
494 >       syncprov-sessionlog 100
495
496
497 H4: Set up the consumer slapd
498
499 The syncrepl replication is specified in the database section of
500 {{slapd.conf}}(5) for the replica context.  The syncrepl engine
501 is backend independent and the directive can be defined with any
502 database type.
503
504 >       database hdb
505 >       suffix dc=Example,dc=com
506 >       rootdn dc=Example,dc=com
507 >       directory /var/ldap/db
508 >       index objectclass,entryCSN,entryUUID eq
509 >
510 >       syncrepl rid=123
511 >               provider=ldap://provider.example.com:389
512 >               type=refreshOnly
513 >               interval=01:00:00:00
514 >               searchbase="dc=example,dc=com"
515 >               filter="(objectClass=organizationalPerson)"
516 >               scope=sub
517 >               attrs="cn,sn,ou,telephoneNumber,title,l"
518 >               schemachecking=off
519 >               bindmethod=simple
520 >               binddn="cn=syncuser,dc=example,dc=com"
521 >               credentials=secret
522
523 In this example, the consumer will connect to the provider {{slapd}}(8)
524 at port 389 of {{FILE:ldap://provider.example.com}} to perform a
525 polling ({{refreshOnly}}) mode of synchronization once a day.  It
526 will bind as {{EX:cn=syncuser,dc=example,dc=com}} using simple
527 authentication with password "secret".  Note that the access control
528 privilege of {{EX:cn=syncuser,dc=example,dc=com}} should be set
529 appropriately in the provider to retrieve the desired replication
530 content. Also the search limits must be high enough on the provider
531 to allow the syncuser to retrieve a complete copy of the requested
532 content.  The consumer uses the rootdn to write to its database so
533 it always has full permissions to write all content.
534
535 The synchronization search in the above example will search for the
536 entries whose objectClass is organizationalPerson in the entire
537 subtree rooted at {{EX:dc=example,dc=com}}. The requested attributes
538 are {{EX:cn}}, {{EX:sn}}, {{EX:ou}}, {{EX:telephoneNumber}},
539 {{EX:title}}, and {{EX:l}}. The schema checking is turned off, so
540 that the consumer {{slapd}}(8) will not enforce entry schema
541 checking when it process updates from the provider {{slapd}}(8).
542
543 For more detailed information on the syncrepl directive, see the
544 {{SECT:syncrepl}} section of {{SECT:The slapd Configuration File}}
545 chapter of this admin guide.
546
547
548 H4: Start the provider and the consumer slapd
549
550 The provider {{slapd}}(8) is not required to be restarted.
551 {{contextCSN}} is automatically generated as needed: it might be
552 originally contained in the {{TERM:LDIF}} file, generated by
553 {{slapadd}} (8), generated upon changes in the context, or generated
554 when the first LDAP Sync search arrives at the provider.  If an
555 LDIF file is being loaded which did not previously contain the
556 {{contextCSN}}, the {{-w}} option should be used with {{slapadd}}
557 (8) to cause it to be generated. This will allow the server to
558 startup a little quicker the first time it runs.
559
560 When starting a consumer {{slapd}}(8), it is possible to provide
561 a synchronization cookie as the {{-c cookie}} command line option
562 in order to start the synchronization from a specific state.  The
563 cookie is a comma separated list of name=value pairs. Currently
564 supported syncrepl cookie fields are {{csn=<csn>}} and {{rid=<rid>}}.
565 {{<csn>}} represents the current synchronization state of the
566 consumer replica.  {{<rid>}} identifies a consumer replica locally
567 within the consumer server. It is used to relate the cookie to the
568 syncrepl definition in {{slapd.conf}}(5) which has the matching
569 replica identifier.  The {{<rid>}} must have no more than 3 decimal
570 digits.  The command line cookie overrides the synchronization
571 cookie stored in the consumer replica database.
572
573
574 H2: N-Way Multi-Master
575
576
577 H2: MirrorMode
578
579