]> git.sur5r.net Git - openldap/blob - doc/guide/admin/replication.sdf
More additions.
[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 mechanisim 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-synchronising; you can start with a database in any 
45    state from totally empty to fully sync'd and it will automatically do 
46    the right thing to achieve and maintain synchronisation
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/s directory and setup Syncrepl to point to your Master database.
54
55 REFERENCE test045/048 for better explaination 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 >       # whithout 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 EXPLAINATION 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
162 H2: LDAP Sync Replication
163
164 The {{TERM:LDAP Sync}} Replication engine, {{TERM:syncrepl}} for
165 short, is a consumer-side replication engine that enables the
166 consumer {{TERM:LDAP}} server to maintain a shadow copy of a
167 {{TERM:DIT}} fragment. A syncrepl engine resides at the consumer-side
168 as one of the {{slapd}}(8) threads. It creates and maintains a
169 consumer replica by connecting to the replication provider to perform
170 the initial DIT content load followed either by periodic content
171 polling or by timely updates upon content changes.
172
173 Syncrepl uses the LDAP Content Synchronization (or LDAP Sync for
174 short) protocol as the replica synchronization protocol.  It provides
175 a stateful replication which supports both pull-based and push-based
176 synchronization and does not mandate the use of a history store.
177
178 Syncrepl keeps track of the status of the replication content by
179 maintaining and exchanging synchronization cookies. Because the
180 syncrepl consumer and provider maintain their content status, the
181 consumer can poll the provider content to perform incremental
182 synchronization by asking for the entries required to make the
183 consumer replica up-to-date with the provider content. Syncrepl
184 also enables convenient management of replicas by maintaining replica
185 status.  The consumer replica can be constructed from a consumer-side
186 or a provider-side backup at any synchronization status. Syncrepl
187 can automatically resynchronize the consumer replica up-to-date
188 with the current provider content.
189
190 Syncrepl supports both pull-based and push-based synchronization.
191 In its basic refreshOnly synchronization mode, the provider uses
192 pull-based synchronization where the consumer servers need not be
193 tracked and no history information is maintained.  The information
194 required for the provider to process periodic polling requests is
195 contained in the synchronization cookie of the request itself.  To
196 optimize the pull-based synchronization, syncrepl utilizes the
197 present phase of the LDAP Sync protocol as well as its delete phase,
198 instead of falling back on frequent full reloads. To further optimize
199 the pull-based synchronization, the provider can maintain a per-scope
200 session log as a history store. In its refreshAndPersist mode of
201 synchronization, the provider uses a push-based synchronization.
202 The provider keeps track of the consumer servers that have requested
203 a persistent search and sends them necessary updates as the provider
204 replication content gets modified.
205
206 With syncrepl, a consumer server can create a replica without
207 changing the provider's configurations and without restarting the
208 provider server, if the consumer server has appropriate access
209 privileges for the DIT fragment to be replicated. The consumer
210 server can stop the replication also without the need for provider-side
211 changes and restart.
212
213 Syncrepl supports both partial and sparse replications.  The shadow
214 DIT fragment is defined by a general search criteria consisting of
215 base, scope, filter, and attribute list.  The replica content is
216 also subject to the access privileges of the bind identity of the
217 syncrepl replication connection.
218
219
220 H3: The LDAP Content Synchronization Protocol
221
222 The LDAP Sync protocol allows a client to maintain a synchronized
223 copy of a DIT fragment. The LDAP Sync operation is defined as a set
224 of controls and other protocol elements which extend the LDAP search
225 operation. This section introduces the LDAP Content Sync protocol
226 only briefly.  For more information, refer to {{REF:RFC4533}}.
227
228 The LDAP Sync protocol supports both polling and listening for
229 changes by defining two respective synchronization operations:
230 {{refreshOnly}} and {{refreshAndPersist}}.  Polling is implemented
231 by the {{refreshOnly}} operation.  The client copy is synchronized
232 to the server copy at the time of polling.  The server finishes the
233 search operation by returning {{SearchResultDone}} at the end of
234 the search operation as in the normal search.  The listening is
235 implemented by the {{refreshAndPersist}} operation.  Instead of
236 finishing the search after returning all entries currently matching
237 the search criteria, the synchronization search remains persistent
238 in the server. Subsequent updates to the synchronization content
239 in the server cause additional entry updates to be sent to the
240 client.
241
242 The {{refreshOnly}} operation and the refresh stage of the
243 {{refreshAndPersist}} operation can be performed with a present
244 phase or a delete phase.
245
246 In the present phase, the server sends the client the entries updated
247 within the search scope since the last synchronization. The server
248 sends all requested attributes, be it changed or not, of the updated
249 entries.  For each unchanged entry which remains in the scope, the
250 server sends a present message consisting only of the name of the
251 entry and the synchronization control representing state present.
252 The present message does not contain any attributes of the entry.
253 After the client receives all update and present entries, it can
254 reliably determine the new client copy by adding the entries added
255 to the server, by replacing the entries modified at the server, and
256 by deleting entries in the client copy which have not been updated
257 nor specified as being present at the server.
258
259 The transmission of the updated entries in the delete phase is the
260 same as in the present phase. The server sends all the requested
261 attributes of the entries updated within the search scope since the
262 last synchronization to the client. In the delete phase, however,
263 the server sends a delete message for each entry deleted from the
264 search scope, instead of sending present messages.  The delete
265 message consists only of the name of the entry and the synchronization
266 control representing state delete.  The new client copy can be
267 determined by adding, modifying, and removing entries according to
268 the synchronization control attached to the {{SearchResultEntry}}
269 message.
270
271 In the case that the LDAP Sync server maintains a history store and
272 can determine which entries are scoped out of the client copy since
273 the last synchronization time, the server can use the delete phase.
274 If the server does not maintain any history store, cannot determine
275 the scoped-out entries from the history store, or the history store
276 does not cover the outdated synchronization state of the client,
277 the server should use the present phase.  The use of the present
278 phase is much more efficient than a full content reload in terms
279 of the synchronization traffic.  To reduce the synchronization
280 traffic further, the LDAP Sync protocol also provides several
281 optimizations such as the transmission of the normalized {{EX:entryUUID}}s
282 and the transmission of multiple {{EX:entryUUIDs}} in a single
283 {{syncIdSet}} message.
284
285 At the end of the {{refreshOnly}} synchronization, the server sends
286 a synchronization cookie to the client as a state indicator of the
287 client copy after the synchronization is completed.  The client
288 will present the received cookie when it requests the next incremental
289 synchronization to the server.
290
291 When {{refreshAndPersist}} synchronization is used, the server sends
292 a synchronization cookie at the end of the refresh stage by sending
293 a Sync Info message with TRUE refreshDone.  It also sends a
294 synchronization cookie by attaching it to {{SearchResultEntry}}
295 generated in the persist stage of the synchronization search. During
296 the persist stage, the server can also send a Sync Info message
297 containing the synchronization cookie at any time the server wants
298 to update the client-side state indicator.  The server also updates
299 a synchronization indicator of the client at the end of the persist
300 stage.
301
302 In the LDAP Sync protocol, entries are uniquely identified by the
303 {{EX:entryUUID}} attribute value. It can function as a reliable
304 identifier of the entry. The DN of the entry, on the other hand,
305 can be changed over time and hence cannot be considered as the
306 reliable identifier.  The {{EX:entryUUID}} is attached to each
307 {{SearchResultEntry}} or {{SearchResultReference}} as a part of the
308 synchronization control.
309
310
311 H3: Syncrepl Details
312
313 The syncrepl engine utilizes both the {{refreshOnly}} and the
314 {{refreshAndPersist}} operations of the LDAP Sync protocol.  If a
315 syncrepl specification is included in a database definition,
316 {{slapd}}(8) launches a syncrepl engine as a {{slapd}}(8) thread
317 and schedules its execution. If the {{refreshOnly}} operation is
318 specified, the syncrepl engine will be rescheduled at the interval
319 time after a synchronization operation is completed.  If the
320 {{refreshAndPersist}} operation is specified, the engine will remain
321 active and process the persistent synchronization messages from the
322 provider.
323
324 The syncrepl engine utilizes both the present phase and the delete
325 phase of the refresh synchronization. It is possible to configure
326 a per-scope session log in the provider server which stores the
327 {{EX:entryUUID}}s of a finite number of entries deleted from a
328 replication content.  Multiple replicas of single provider content
329 share the same per-scope session log. The syncrepl engine uses the
330 delete phase if the session log is present and the state of the
331 consumer server is recent enough that no session log entries are
332 truncated after the last synchronization of the client.  The syncrepl
333 engine uses the present phase if no session log is configured for
334 the replication content or if the consumer replica is too outdated
335 to be covered by the session log.  The current design of the session
336 log store is memory based, so the information contained in the
337 session log is not persistent over multiple provider invocations.
338 It is not currently supported to access the session log store by
339 using LDAP operations. It is also not currently supported to impose
340 access control to the session log.
341
342 As a further optimization, even in the case the synchronization
343 search is not associated with any session log, no entries will be
344 transmitted to the consumer server when there has been no update
345 in the replication context.
346
347 The syncrepl engine, which is a consumer-side replication engine,
348 can work with any backends. The LDAP Sync provider can be configured
349 as an overlay on any backend, but works best with the {{back-bdb}}
350 or {{back-hdb}} backend.
351
352 The LDAP Sync provider maintains a {{EX:contextCSN}} for each
353 database as the current synchronization state indicator of the
354 provider content.  It is the largest {{EX:entryCSN}} in the provider
355 context such that no transactions for an entry having smaller
356 {{EX:entryCSN}} value remains outstanding.  The {{EX:contextCSN}}
357 could not just be set to the largest issued {{EX:entryCSN}} because
358 {{EX:entryCSN}} is obtained before a transaction starts and
359 transactions are not committed in the issue order.
360
361 The provider stores the {{EX:contextCSN}} of a context in the
362 {{EX:contextCSN}} attribute of the context suffix entry. The attribute
363 is not written to the database after every update operation though;
364 instead it is maintained primarily in memory. At database start
365 time the provider reads the last saved {{EX:contextCSN}} into memory
366 and uses the in-memory copy exclusively thereafter. By default,
367 changes to the {{EX:contextCSN}} as a result of database updates
368 will not be written to the database until the server is cleanly
369 shut down. A checkpoint facility exists to cause the contextCSN to
370 be written out more frequently if desired.
371
372 Note that at startup time, if the provider is unable to read a
373 {{EX:contextCSN}} from the suffix entry, it will scan the entire
374 database to determine the value, and this scan may take quite a
375 long time on a large database. When a {{EX:contextCSN}} value is
376 read, the database will still be scanned for any {{EX:entryCSN}}
377 values greater than it, to make sure the {{EX:contextCSN}} value
378 truly reflects the greatest committed {{EX:entryCSN}} in the database.
379 On databases which support inequality indexing, setting an eq index
380 on the {{EX:entryCSN}} attribute and configuring {{contextCSN}}
381 checkpoints will greatly speed up this scanning step.
382
383 If no {{EX:contextCSN}} can be determined by reading and scanning
384 the database, a new value will be generated. Also, if scanning the
385 database yielded a greater {{EX:entryCSN}} than was previously
386 recorded in the suffix entry's {{EX:contextCSN}} attribute, a
387 checkpoint will be immediately written with the new value.
388
389 The consumer also stores its replica state, which is the provider's
390 {{EX:contextCSN}} received as a synchronization cookie, in the
391 {{EX:contextCSN}} attribute of the suffix entry.  The replica state
392 maintained by a consumer server is used as the synchronization state
393 indicator when it performs subsequent incremental synchronization
394 with the provider server. It is also used as a provider-side
395 synchronization state indicator when it functions as a secondary
396 provider server in a cascading replication configuration.  Since
397 the consumer and provider state information are maintained in the
398 same location within their respective databases, any consumer can
399 be promoted to a provider (and vice versa) without any special
400 actions.
401
402 Because a general search filter can be used in the syncrepl
403 specification, some entries in the context may be omitted from the
404 synchronization content.  The syncrepl engine creates a glue entry
405 to fill in the holes in the replica context if any part of the
406 replica content is subordinate to the holes. The glue entries will
407 not be returned in the search result unless {{ManageDsaIT}} control
408 is provided.
409
410 Also as a consequence of the search filter used in the syncrepl
411 specification, it is possible for a modification to remove an entry
412 from the replication scope even though the entry has not been deleted
413 on the provider. Logically the entry must be deleted on the consumer
414 but in {{refreshOnly}} mode the provider cannot detect and propagate
415 this change without the use of the session log.
416
417
418 H3: Configuring Syncrepl
419
420 Because syncrepl is a consumer-side replication engine, the syncrepl
421 specification is defined in {{slapd.conf}}(5) of the consumer
422 server, not in the provider server's configuration file.  The initial
423 loading of the replica content can be performed either by starting
424 the syncrepl engine with no synchronization cookie or by populating
425 the consumer replica by adding an {{TERM:LDIF}} file dumped as a
426 backup at the provider.
427
428 When loading from a backup, it is not required to perform the initial
429 loading from the up-to-date backup of the provider content. The
430 syncrepl engine will automatically synchronize the initial consumer
431 replica to the current provider content. As a result, it is not
432 required to stop the provider server in order to avoid the replica
433 inconsistency caused by the updates to the provider content during
434 the content backup and loading process.
435
436 When replicating a large scale directory, especially in a bandwidth
437 constrained environment, it is advised to load the consumer replica
438 from a backup instead of performing a full initial load using
439 syncrepl.
440
441
442 H4: Set up the provider slapd
443
444 The provider is implemented as an overlay, so the overlay itself
445 must first be configured in {{slapd.conf}}(5) before it can be
446 used. The provider has only two configuration directives, for setting
447 checkpoints on the {{EX:contextCSN}} and for configuring the session
448 log.  Because the LDAP Sync search is subject to access control,
449 proper access control privileges should be set up for the replicated
450 content.
451
452 The {{EX:contextCSN}} checkpoint is configured by the
453
454 >       syncprov-checkpoint <ops> <minutes>
455
456 directive. Checkpoints are only tested after successful write
457 operations.  If {{<ops>}} operations or more than {{<minutes>}}
458 time has passed since the last checkpoint, a new checkpoint is
459 performed.
460
461 The session log is configured by the
462
463 >       syncprov-sessionlog <size>
464
465 directive, where {{<size>}} is the maximum number of session log
466 entries the session log can record. When a session log is configured,
467 it is automatically used for all LDAP Sync searches within the
468 database.
469
470 Note that using the session log requires searching on the {{entryUUID}}
471 attribute. Setting an eq index on this attribute will greatly benefit
472 the performance of the session log on the provider.
473
474 A more complete example of the {{slapd.conf}}(5) content is thus:
475
476 >       database bdb
477 >       suffix dc=Example,dc=com
478 >       rootdn dc=Example,dc=com
479 >       directory /var/ldap/db
480 >       index objectclass,entryCSN,entryUUID eq
481 >
482 >       overlay syncprov
483 >       syncprov-checkpoint 100 10
484 >       syncprov-sessionlog 100
485
486
487 H4: Set up the consumer slapd
488
489 The syncrepl replication is specified in the database section of
490 {{slapd.conf}}(5) for the replica context.  The syncrepl engine
491 is backend independent and the directive can be defined with any
492 database type.
493
494 >       database hdb
495 >       suffix dc=Example,dc=com
496 >       rootdn dc=Example,dc=com
497 >       directory /var/ldap/db
498 >       index objectclass,entryCSN,entryUUID eq
499 >
500 >       syncrepl rid=123
501 >               provider=ldap://provider.example.com:389
502 >               type=refreshOnly
503 >               interval=01:00:00:00
504 >               searchbase="dc=example,dc=com"
505 >               filter="(objectClass=organizationalPerson)"
506 >               scope=sub
507 >               attrs="cn,sn,ou,telephoneNumber,title,l"
508 >               schemachecking=off
509 >               bindmethod=simple
510 >               binddn="cn=syncuser,dc=example,dc=com"
511 >               credentials=secret
512
513 In this example, the consumer will connect to the provider {{slapd}}(8)
514 at port 389 of {{FILE:ldap://provider.example.com}} to perform a
515 polling ({{refreshOnly}}) mode of synchronization once a day.  It
516 will bind as {{EX:cn=syncuser,dc=example,dc=com}} using simple
517 authentication with password "secret".  Note that the access control
518 privilege of {{EX:cn=syncuser,dc=example,dc=com}} should be set
519 appropriately in the provider to retrieve the desired replication
520 content. Also the search limits must be high enough on the provider
521 to allow the syncuser to retrieve a complete copy of the requested
522 content.  The consumer uses the rootdn to write to its database so
523 it always has full permissions to write all content.
524
525 The synchronization search in the above example will search for the
526 entries whose objectClass is organizationalPerson in the entire
527 subtree rooted at {{EX:dc=example,dc=com}}. The requested attributes
528 are {{EX:cn}}, {{EX:sn}}, {{EX:ou}}, {{EX:telephoneNumber}},
529 {{EX:title}}, and {{EX:l}}. The schema checking is turned off, so
530 that the consumer {{slapd}}(8) will not enforce entry schema
531 checking when it process updates from the provider {{slapd}}(8).
532
533 For more detailed information on the syncrepl directive, see the
534 {{SECT:syncrepl}} section of {{SECT:The slapd Configuration File}}
535 chapter of this admin guide.
536
537
538 H4: Start the provider and the consumer slapd
539
540 The provider {{slapd}}(8) is not required to be restarted.
541 {{contextCSN}} is automatically generated as needed: it might be
542 originally contained in the {{TERM:LDIF}} file, generated by
543 {{slapadd}} (8), generated upon changes in the context, or generated
544 when the first LDAP Sync search arrives at the provider.  If an
545 LDIF file is being loaded which did not previously contain the
546 {{contextCSN}}, the {{-w}} option should be used with {{slapadd}}
547 (8) to cause it to be generated. This will allow the server to
548 startup a little quicker the first time it runs.
549
550 When starting a consumer {{slapd}}(8), it is possible to provide
551 a synchronization cookie as the {{-c cookie}} command line option
552 in order to start the synchronization from a specific state.  The
553 cookie is a comma separated list of name=value pairs. Currently
554 supported syncrepl cookie fields are {{csn=<csn>}} and {{rid=<rid>}}.
555 {{<csn>}} represents the current synchronization state of the
556 consumer replica.  {{<rid>}} identifies a consumer replica locally
557 within the consumer server. It is used to relate the cookie to the
558 syncrepl definition in {{slapd.conf}}(5) which has the matching
559 replica identifier.  The {{<rid>}} must have no more than 3 decimal
560 digits.  The command line cookie overrides the synchronization
561 cookie stored in the consumer replica database.
562
563
564 H2: N-Way Multi-Master
565
566
567 H2: MirrorMode
568
569