]> git.sur5r.net Git - openldap/blob - doc/guide/admin/replication.sdf
Happy new year! (belated)
[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: 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 OpenLDAP 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 replication
153
154 Multi-Master replication is a replication technique using Syncrepl to replicate 
155 data to multiple Master Directory servers. 
156
157 * Advantages of Multi-Master replication:
158
159 - If any master fails, other masters will continue to accept updates
160 - Avoids a single point of failure
161 - Masters can be located in several physical sites i.e. distributed across the 
162 network/globe.
163 - Good for Automatic failover/High Availability
164
165 * Disadvantages of Multi-Master replication:
166
167 - It has {{B:NOTHING}} to do with load balancing
168 - {{URL:http://www.openldap.org/faq/data/cache/1240.html}}
169 - If connectivity with a master is lost because of a network partition, then 
170 "automatic failover" can just compound the problem
171 - Typically, a particular machine cannot distinguish between losing contact
172  with a peer because that peer crashed, or because the network link has failed
173 - If a network is partitioned and multiple clients start writing to each of the 
174 "masters" then reconciliation will be a pain; it may be best to simply deny 
175 writes to the clients that are partitioned from the single master
176 - Masters {{B:must}} propagate writes to {{B:all}} the other servers, which 
177 means the network traffic and write load is constant and spreads across all 
178 of the servers
179
180
181 This is discussed in full in the {{SECT:N-Way Multi-Master}} section below
182
183 H3: MirrorMode replication
184
185 MirrorMode is a hybrid configuration that provides all of the consistency
186 guarantees of single-master replication, while also providing the high
187 availability of multi-master. In MirrorMode two masters are set up to
188 replicate from each other (as a multi-master configuration) but an
189 external frontend is employed to direct all writes to only one of
190 the two servers. The second master will only be used for writes if
191 the first master crashes, at which point the frontend will switch to
192 directing all writes to the second master. When a crashed master is
193 repaired and restarted it will automatically catch up to any changes
194 on the running master and resync.
195
196 This is discussed in full in the {{SECT:MirrorMode}} section below
197
198 H2: LDAP Sync Replication
199
200 The {{TERM:LDAP Sync}} Replication engine, {{TERM:syncrepl}} for
201 short, is a consumer-side replication engine that enables the
202 consumer {{TERM:LDAP}} server to maintain a shadow copy of a
203 {{TERM:DIT}} fragment. A syncrepl engine resides at the consumer-side
204 as one of the {{slapd}}(8) threads. It creates and maintains a
205 consumer replica by connecting to the replication provider to perform
206 the initial DIT content load followed either by periodic content
207 polling or by timely updates upon content changes.
208
209 Syncrepl uses the LDAP Content Synchronization (or LDAP Sync for
210 short) protocol as the replica synchronization protocol.  It provides
211 a stateful replication which supports both pull-based and push-based
212 synchronization and does not mandate the use of a history store.
213
214 Syncrepl keeps track of the status of the replication content by
215 maintaining and exchanging synchronization cookies. Because the
216 syncrepl consumer and provider maintain their content status, the
217 consumer can poll the provider content to perform incremental
218 synchronization by asking for the entries required to make the
219 consumer replica up-to-date with the provider content. Syncrepl
220 also enables convenient management of replicas by maintaining replica
221 status.  The consumer replica can be constructed from a consumer-side
222 or a provider-side backup at any synchronization status. Syncrepl
223 can automatically resynchronize the consumer replica up-to-date
224 with the current provider content.
225
226 Syncrepl supports both pull-based and push-based synchronization.
227 In its basic refreshOnly synchronization mode, the provider uses
228 pull-based synchronization where the consumer servers need not be
229 tracked and no history information is maintained.  The information
230 required for the provider to process periodic polling requests is
231 contained in the synchronization cookie of the request itself.  To
232 optimize the pull-based synchronization, syncrepl utilizes the
233 present phase of the LDAP Sync protocol as well as its delete phase,
234 instead of falling back on frequent full reloads. To further optimize
235 the pull-based synchronization, the provider can maintain a per-scope
236 session log as a history store. In its refreshAndPersist mode of
237 synchronization, the provider uses a push-based synchronization.
238 The provider keeps track of the consumer servers that have requested
239 a persistent search and sends them necessary updates as the provider
240 replication content gets modified.
241
242 With syncrepl, a consumer server can create a replica without
243 changing the provider's configurations and without restarting the
244 provider server, if the consumer server has appropriate access
245 privileges for the DIT fragment to be replicated. The consumer
246 server can stop the replication also without the need for provider-side
247 changes and restart.
248
249 Syncrepl supports both partial and sparse replications.  The shadow
250 DIT fragment is defined by a general search criteria consisting of
251 base, scope, filter, and attribute list.  The replica content is
252 also subject to the access privileges of the bind identity of the
253 syncrepl replication connection.
254
255
256 H3: The LDAP Content Synchronization Protocol
257
258 The LDAP Sync protocol allows a client to maintain a synchronized
259 copy of a DIT fragment. The LDAP Sync operation is defined as a set
260 of controls and other protocol elements which extend the LDAP search
261 operation. This section introduces the LDAP Content Sync protocol
262 only briefly.  For more information, refer to {{REF:RFC4533}}.
263
264 The LDAP Sync protocol supports both polling and listening for
265 changes by defining two respective synchronization operations:
266 {{refreshOnly}} and {{refreshAndPersist}}.  Polling is implemented
267 by the {{refreshOnly}} operation.  The client copy is synchronized
268 to the server copy at the time of polling.  The server finishes the
269 search operation by returning {{SearchResultDone}} at the end of
270 the search operation as in the normal search.  The listening is
271 implemented by the {{refreshAndPersist}} operation.  Instead of
272 finishing the search after returning all entries currently matching
273 the search criteria, the synchronization search remains persistent
274 in the server. Subsequent updates to the synchronization content
275 in the server cause additional entry updates to be sent to the
276 client.
277
278 The {{refreshOnly}} operation and the refresh stage of the
279 {{refreshAndPersist}} operation can be performed with a present
280 phase or a delete phase.
281
282 In the present phase, the server sends the client the entries updated
283 within the search scope since the last synchronization. The server
284 sends all requested attributes, be it changed or not, of the updated
285 entries.  For each unchanged entry which remains in the scope, the
286 server sends a present message consisting only of the name of the
287 entry and the synchronization control representing state present.
288 The present message does not contain any attributes of the entry.
289 After the client receives all update and present entries, it can
290 reliably determine the new client copy by adding the entries added
291 to the server, by replacing the entries modified at the server, and
292 by deleting entries in the client copy which have not been updated
293 nor specified as being present at the server.
294
295 The transmission of the updated entries in the delete phase is the
296 same as in the present phase. The server sends all the requested
297 attributes of the entries updated within the search scope since the
298 last synchronization to the client. In the delete phase, however,
299 the server sends a delete message for each entry deleted from the
300 search scope, instead of sending present messages.  The delete
301 message consists only of the name of the entry and the synchronization
302 control representing state delete.  The new client copy can be
303 determined by adding, modifying, and removing entries according to
304 the synchronization control attached to the {{SearchResultEntry}}
305 message.
306
307 In the case that the LDAP Sync server maintains a history store and
308 can determine which entries are scoped out of the client copy since
309 the last synchronization time, the server can use the delete phase.
310 If the server does not maintain any history store, cannot determine
311 the scoped-out entries from the history store, or the history store
312 does not cover the outdated synchronization state of the client,
313 the server should use the present phase.  The use of the present
314 phase is much more efficient than a full content reload in terms
315 of the synchronization traffic.  To reduce the synchronization
316 traffic further, the LDAP Sync protocol also provides several
317 optimizations such as the transmission of the normalized {{EX:entryUUID}}s
318 and the transmission of multiple {{EX:entryUUIDs}} in a single
319 {{syncIdSet}} message.
320
321 At the end of the {{refreshOnly}} synchronization, the server sends
322 a synchronization cookie to the client as a state indicator of the
323 client copy after the synchronization is completed.  The client
324 will present the received cookie when it requests the next incremental
325 synchronization to the server.
326
327 When {{refreshAndPersist}} synchronization is used, the server sends
328 a synchronization cookie at the end of the refresh stage by sending
329 a Sync Info message with TRUE refreshDone.  It also sends a
330 synchronization cookie by attaching it to {{SearchResultEntry}}
331 generated in the persist stage of the synchronization search. During
332 the persist stage, the server can also send a Sync Info message
333 containing the synchronization cookie at any time the server wants
334 to update the client-side state indicator.  The server also updates
335 a synchronization indicator of the client at the end of the persist
336 stage.
337
338 In the LDAP Sync protocol, entries are uniquely identified by the
339 {{EX:entryUUID}} attribute value. It can function as a reliable
340 identifier of the entry. The DN of the entry, on the other hand,
341 can be changed over time and hence cannot be considered as the
342 reliable identifier.  The {{EX:entryUUID}} is attached to each
343 {{SearchResultEntry}} or {{SearchResultReference}} as a part of the
344 synchronization control.
345
346
347 H3: Syncrepl Details
348
349 The syncrepl engine utilizes both the {{refreshOnly}} and the
350 {{refreshAndPersist}} operations of the LDAP Sync protocol.  If a
351 syncrepl specification is included in a database definition,
352 {{slapd}}(8) launches a syncrepl engine as a {{slapd}}(8) thread
353 and schedules its execution. If the {{refreshOnly}} operation is
354 specified, the syncrepl engine will be rescheduled at the interval
355 time after a synchronization operation is completed.  If the
356 {{refreshAndPersist}} operation is specified, the engine will remain
357 active and process the persistent synchronization messages from the
358 provider.
359
360 The syncrepl engine utilizes both the present phase and the delete
361 phase of the refresh synchronization. It is possible to configure
362 a per-scope session log in the provider server which stores the
363 {{EX:entryUUID}}s of a finite number of entries deleted from a
364 replication content.  Multiple replicas of single provider content
365 share the same per-scope session log. The syncrepl engine uses the
366 delete phase if the session log is present and the state of the
367 consumer server is recent enough that no session log entries are
368 truncated after the last synchronization of the client.  The syncrepl
369 engine uses the present phase if no session log is configured for
370 the replication content or if the consumer replica is too outdated
371 to be covered by the session log.  The current design of the session
372 log store is memory based, so the information contained in the
373 session log is not persistent over multiple provider invocations.
374 It is not currently supported to access the session log store by
375 using LDAP operations. It is also not currently supported to impose
376 access control to the session log.
377
378 As a further optimization, even in the case the synchronization
379 search is not associated with any session log, no entries will be
380 transmitted to the consumer server when there has been no update
381 in the replication context.
382
383 The syncrepl engine, which is a consumer-side replication engine,
384 can work with any backends. The LDAP Sync provider can be configured
385 as an overlay on any backend, but works best with the {{back-bdb}}
386 or {{back-hdb}} backend.
387
388 The LDAP Sync provider maintains a {{EX:contextCSN}} for each
389 database as the current synchronization state indicator of the
390 provider content.  It is the largest {{EX:entryCSN}} in the provider
391 context such that no transactions for an entry having smaller
392 {{EX:entryCSN}} value remains outstanding.  The {{EX:contextCSN}}
393 could not just be set to the largest issued {{EX:entryCSN}} because
394 {{EX:entryCSN}} is obtained before a transaction starts and
395 transactions are not committed in the issue order.
396
397 The provider stores the {{EX:contextCSN}} of a context in the
398 {{EX:contextCSN}} attribute of the context suffix entry. The attribute
399 is not written to the database after every update operation though;
400 instead it is maintained primarily in memory. At database start
401 time the provider reads the last saved {{EX:contextCSN}} into memory
402 and uses the in-memory copy exclusively thereafter. By default,
403 changes to the {{EX:contextCSN}} as a result of database updates
404 will not be written to the database until the server is cleanly
405 shut down. A checkpoint facility exists to cause the contextCSN to
406 be written out more frequently if desired.
407
408 Note that at startup time, if the provider is unable to read a
409 {{EX:contextCSN}} from the suffix entry, it will scan the entire
410 database to determine the value, and this scan may take quite a
411 long time on a large database. When a {{EX:contextCSN}} value is
412 read, the database will still be scanned for any {{EX:entryCSN}}
413 values greater than it, to make sure the {{EX:contextCSN}} value
414 truly reflects the greatest committed {{EX:entryCSN}} in the database.
415 On databases which support inequality indexing, setting an eq index
416 on the {{EX:entryCSN}} attribute and configuring {{contextCSN}}
417 checkpoints will greatly speed up this scanning step.
418
419 If no {{EX:contextCSN}} can be determined by reading and scanning
420 the database, a new value will be generated. Also, if scanning the
421 database yielded a greater {{EX:entryCSN}} than was previously
422 recorded in the suffix entry's {{EX:contextCSN}} attribute, a
423 checkpoint will be immediately written with the new value.
424
425 The consumer also stores its replica state, which is the provider's
426 {{EX:contextCSN}} received as a synchronization cookie, in the
427 {{EX:contextCSN}} attribute of the suffix entry.  The replica state
428 maintained by a consumer server is used as the synchronization state
429 indicator when it performs subsequent incremental synchronization
430 with the provider server. It is also used as a provider-side
431 synchronization state indicator when it functions as a secondary
432 provider server in a cascading replication configuration.  Since
433 the consumer and provider state information are maintained in the
434 same location within their respective databases, any consumer can
435 be promoted to a provider (and vice versa) without any special
436 actions.
437
438 Because a general search filter can be used in the syncrepl
439 specification, some entries in the context may be omitted from the
440 synchronization content.  The syncrepl engine creates a glue entry
441 to fill in the holes in the replica context if any part of the
442 replica content is subordinate to the holes. The glue entries will
443 not be returned in the search result unless {{ManageDsaIT}} control
444 is provided.
445
446 Also as a consequence of the search filter used in the syncrepl
447 specification, it is possible for a modification to remove an entry
448 from the replication scope even though the entry has not been deleted
449 on the provider. Logically the entry must be deleted on the consumer
450 but in {{refreshOnly}} mode the provider cannot detect and propagate
451 this change without the use of the session log.
452
453
454 H3: Configuring Syncrepl
455
456 Because syncrepl is a consumer-side replication engine, the syncrepl
457 specification is defined in {{slapd.conf}}(5) of the consumer
458 server, not in the provider server's configuration file.  The initial
459 loading of the replica content can be performed either by starting
460 the syncrepl engine with no synchronization cookie or by populating
461 the consumer replica by adding an {{TERM:LDIF}} file dumped as a
462 backup at the provider.
463
464 When loading from a backup, it is not required to perform the initial
465 loading from the up-to-date backup of the provider content. The
466 syncrepl engine will automatically synchronize the initial consumer
467 replica to the current provider content. As a result, it is not
468 required to stop the provider server in order to avoid the replica
469 inconsistency caused by the updates to the provider content during
470 the content backup and loading process.
471
472 When replicating a large scale directory, especially in a bandwidth
473 constrained environment, it is advised to load the consumer replica
474 from a backup instead of performing a full initial load using
475 syncrepl.
476
477
478 H4: Set up the provider slapd
479
480 The provider is implemented as an overlay, so the overlay itself
481 must first be configured in {{slapd.conf}}(5) before it can be
482 used. The provider has only two configuration directives, for setting
483 checkpoints on the {{EX:contextCSN}} and for configuring the session
484 log.  Because the LDAP Sync search is subject to access control,
485 proper access control privileges should be set up for the replicated
486 content.
487
488 The {{EX:contextCSN}} checkpoint is configured by the
489
490 >       syncprov-checkpoint <ops> <minutes>
491
492 directive. Checkpoints are only tested after successful write
493 operations.  If {{<ops>}} operations or more than {{<minutes>}}
494 time has passed since the last checkpoint, a new checkpoint is
495 performed.
496
497 The session log is configured by the
498
499 >       syncprov-sessionlog <size>
500
501 directive, where {{<size>}} is the maximum number of session log
502 entries the session log can record. When a session log is configured,
503 it is automatically used for all LDAP Sync searches within the
504 database.
505
506 Note that using the session log requires searching on the {{entryUUID}}
507 attribute. Setting an eq index on this attribute will greatly benefit
508 the performance of the session log on the provider.
509
510 A more complete example of the {{slapd.conf}}(5) content is thus:
511
512 >       database bdb
513 >       suffix dc=Example,dc=com
514 >       rootdn dc=Example,dc=com
515 >       directory /var/ldap/db
516 >       index objectclass,entryCSN,entryUUID eq
517 >
518 >       overlay syncprov
519 >       syncprov-checkpoint 100 10
520 >       syncprov-sessionlog 100
521
522
523 H4: Set up the consumer slapd
524
525 The syncrepl replication is specified in the database section of
526 {{slapd.conf}}(5) for the replica context.  The syncrepl engine
527 is backend independent and the directive can be defined with any
528 database type.
529
530 >       database hdb
531 >       suffix dc=Example,dc=com
532 >       rootdn dc=Example,dc=com
533 >       directory /var/ldap/db
534 >       index objectclass,entryCSN,entryUUID eq
535 >
536 >       syncrepl rid=123
537 >               provider=ldap://provider.example.com:389
538 >               type=refreshOnly
539 >               interval=01:00:00:00
540 >               searchbase="dc=example,dc=com"
541 >               filter="(objectClass=organizationalPerson)"
542 >               scope=sub
543 >               attrs="cn,sn,ou,telephoneNumber,title,l"
544 >               schemachecking=off
545 >               bindmethod=simple
546 >               binddn="cn=syncuser,dc=example,dc=com"
547 >               credentials=secret
548
549 In this example, the consumer will connect to the provider {{slapd}}(8)
550 at port 389 of {{FILE:ldap://provider.example.com}} to perform a
551 polling ({{refreshOnly}}) mode of synchronization once a day.  It
552 will bind as {{EX:cn=syncuser,dc=example,dc=com}} using simple
553 authentication with password "secret".  Note that the access control
554 privilege of {{EX:cn=syncuser,dc=example,dc=com}} should be set
555 appropriately in the provider to retrieve the desired replication
556 content. Also the search limits must be high enough on the provider
557 to allow the syncuser to retrieve a complete copy of the requested
558 content.  The consumer uses the rootdn to write to its database so
559 it always has full permissions to write all content.
560
561 The synchronization search in the above example will search for the
562 entries whose objectClass is organizationalPerson in the entire
563 subtree rooted at {{EX:dc=example,dc=com}}. The requested attributes
564 are {{EX:cn}}, {{EX:sn}}, {{EX:ou}}, {{EX:telephoneNumber}},
565 {{EX:title}}, and {{EX:l}}. The schema checking is turned off, so
566 that the consumer {{slapd}}(8) will not enforce entry schema
567 checking when it process updates from the provider {{slapd}}(8).
568
569 For more detailed information on the syncrepl directive, see the
570 {{SECT:syncrepl}} section of {{SECT:The slapd Configuration File}}
571 chapter of this admin guide.
572
573
574 H4: Start the provider and the consumer slapd
575
576 The provider {{slapd}}(8) is not required to be restarted.
577 {{contextCSN}} is automatically generated as needed: it might be
578 originally contained in the {{TERM:LDIF}} file, generated by
579 {{slapadd}} (8), generated upon changes in the context, or generated
580 when the first LDAP Sync search arrives at the provider.  If an
581 LDIF file is being loaded which did not previously contain the
582 {{contextCSN}}, the {{-w}} option should be used with {{slapadd}}
583 (8) to cause it to be generated. This will allow the server to
584 startup a little quicker the first time it runs.
585
586 When starting a consumer {{slapd}}(8), it is possible to provide
587 a synchronization cookie as the {{-c cookie}} command line option
588 in order to start the synchronization from a specific state.  The
589 cookie is a comma separated list of name=value pairs. Currently
590 supported syncrepl cookie fields are {{csn=<csn>}} and {{rid=<rid>}}.
591 {{<csn>}} represents the current synchronization state of the
592 consumer replica.  {{<rid>}} identifies a consumer replica locally
593 within the consumer server. It is used to relate the cookie to the
594 syncrepl definition in {{slapd.conf}}(5) which has the matching
595 replica identifier.  The {{<rid>}} must have no more than 3 decimal
596 digits.  The command line cookie overrides the synchronization
597 cookie stored in the consumer replica database.
598
599
600 H2: N-Way Multi-Master
601
602 For the following example we will be using 3 Master nodes. Keeping in line with
603 {{B:test050-syncrepl-multimaster}} of the OpenLDAP test suite, we will be configuring
604 {{slapd(8)}} via {{B:cn=config}}
605
606 This sets up the config database:
607
608 >     dn: cn=config
609 >     objectClass: olcGlobal
610 >     cn: config
611 >     olcServerID: 1
612 >     
613 >     dn: olcDatabase={0}config,cn=config
614 >     objectClass: olcDatabaseConfig
615 >     olcDatabase: {0}config
616 >     olcRootPW: secret
617
618 second and third servers will have a different olcServerID obviously:
619
620 >     dn: cn=config
621 >     objectClass: olcGlobal
622 >     cn: config
623 >     olcServerID: 2
624 >     
625 >     dn: olcDatabase={0}config,cn=config
626 >     objectClass: olcDatabaseConfig
627 >     olcDatabase: {0}config
628 >     olcRootPW: secret
629
630 This sets up syncrepl as a provider (since these are all masters):
631
632 >     dn: cn=module,cn=config
633 >     objectClass: olcModuleList
634 >     cn: module
635 >     olcModulePath: /usr/local/libexec/openldap
636 >     olcModuleLoad: syncprov.la
637
638 Now we setup the first Master Node (replace $URI1, $URI2 and $URI3 etc. with your actual ldap urls):
639
640 >     dn: cn=config
641 >     changetype: modify
642 >     replace: olcServerID
643 >     olcServerID: 1 $URI1
644 >     olcServerID: 2 $URI2
645 >     olcServerID: 3 $URI3
646 >     
647 >     dn: olcOverlay=syncprov,olcDatabase={0}config,cn=config
648 >     changetype: add
649 >     objectClass: olcOverlayConfig
650 >     objectClass: olcSyncProvConfig
651 >     olcOverlay: syncprov
652 >     
653 >     dn: olcDatabase={0}config,cn=config
654 >     changetype: modify
655 >     add: olcSyncRepl
656 >     olcSyncRepl: rid=001 provider=$URI1 binddn="cn=config" bindmethod=simple
657 >       credentials=secret searchbase="cn=config" type=refreshAndPersist
658 >       retry="5 5 300 5" timeout=1
659 >     olcSyncRepl: rid=002 provider=$URI2 binddn="cn=config" bindmethod=simple
660 >       credentials=secret searchbase="cn=config" type=refreshAndPersist
661 >       retry="5 5 300 5" timeout=1
662 >     olcSyncRepl: rid=003 provider=$URI3 binddn="cn=config" bindmethod=simple
663 >       credentials=secret searchbase="cn=config" type=refreshAndPersist
664 >       retry="5 5 300 5" timeout=1
665 >     -
666 >     add: olcMirrorMode
667 >     olcMirrorMode: TRUE
668
669 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.
670
671 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:
672
673 >     dn: olcDatabase={1}$BACKEND,cn=config
674 >     objectClass: olcDatabaseConfig
675 >     objectClass: olc${BACKEND}Config
676 >     olcDatabase: {1}$BACKEND
677 >     olcSuffix: $BASEDN
678 >     olcDbDirectory: ./db
679 >     olcRootDN: $MANAGERDN
680 >     olcRootPW: $PASSWD
681 >     olcSyncRepl: rid=004 provider=$URI1 binddn="$MANAGERDN" bindmethod=simple
682 >       credentials=$PASSWD searchbase="$BASEDN" type=refreshOnly
683 >       interval=00:00:00:10 retry="5 5 300 5" timeout=1
684 >     olcSyncRepl: rid=005 provider=$URI2 binddn="$MANAGERDN" bindmethod=simple
685 >       credentials=$PASSWD searchbase="$BASEDN" type=refreshOnly
686 >       interval=00:00:00:10 retry="5 5 300 5" timeout=1
687 >     olcSyncRepl: rid=006 provider=$URI3 binddn="$MANAGERDN" bindmethod=simple
688 >       credentials=$PASSWD searchbase="$BASEDN" type=refreshOnly
689 >       interval=00:00:00:10 retry="5 5 300 5" timeout=1
690 >     olcMirrorMode: TRUE
691 >     
692 >     dn: olcOverlay=syncprov,olcDatabase={1}${BACKEND},cn=config
693 >     changetype: add
694 >     objectClass: olcOverlayConfig
695 >     objectClass: olcSyncProvConfig
696 >     olcOverlay: syncprov
697
698 Note: You must have all your server set to the same time via {{http://www.ntp.org/}}
699
700 H2: MirrorMode
701
702 H3: Arguments for MirrorMode
703
704 * Provides a high-availability (HA) solution for directory writes (replicas handle reads)
705 * As long as one Master is operational, writes can safely be accepted 
706 * Master nodes replicate from each other, so they are always up to date and
707 can be ready to take over (hot standby)
708 * Syncrepl also allows the master nodes to re-synchronize after any downtime
709 * Delta-Syncrepl can be used
710
711
712 H3: Arguments against MirrorMode
713
714 * MirrorMode is not what is termed as a Multi-Master solution. This is because 
715 writes have to go to one of the mirror nodes at a time
716 * MirrorMode can be termed as Active-Active Hot-Standby, therefor an external 
717 server (slapd in proxy mode) or device (hardware load balancer) to manage which 
718 master is currently active
719 * While syncrepl can recover from a completely empty database, slapadd is much 
720 faster
721 * Does not provide faster or more scalable write performance (neither could 
722   any Multi-Master solution)
723 * Backups are managed slightly differently
724 - If backing up the Berkeley database itself and periodically backing up the 
725 transaction log files, then the same member of the mirror pair needs to be 
726 used to collect logfiles until the next database backup is taken 
727 - To ensure that both databases are consistent, each database might have to be 
728 put in read-only mode while performing a slapcat. 
729 - When using slapcat, the generated LDIF files can be rather large. This can 
730 happen with a non-MirrorMode deployment also.
731
732 H3: MirrorMode Configuration
733
734 MirrorMode configuration is actually very easy. If you have ever setup a normal
735 slapd syncrepl provider, then the only change is the following two directives:
736
737 >       mirrormode  on
738 >       serverID    1
739
740 Note: You need to make sure that the {{serverID}} of each mirror node pair is 
741 different.
742
743 H4: Mirror Node Configuration
744
745 This is the same as the {{SECT:Set up the provider slapd}} section, reference
746 {{SECT:delta-syncrepl replication}} if using {{delta-syncrepl}}.
747
748 Here's a specific cut down example using {{SECT:LDAP Sync Replication}} in
749 {{refreshAndPersist}} mode ({{delta-syncrepl}} can be used also):
750
751 MirrorMode node 1:
752
753 >       # syncrepl directives    \r
754 >       syncrepl      rid=001\r
755 >                     provider=ldap://ldap-ridr1.example.com\r
756 >                     bindmethod=simple\r
757 >                     binddn="cn=mirrormode,dc=example,dc=com"\r
758 >                     credentials=mirrormode\r
759 >                     searchbase="dc=example,dc=com"\r
760 >                     schemachecking=on\r
761 >                     type=refreshAndPersist\r
762 >                     retry="60 +"\r
763 >
764 >       syncrepl      rid=002\r
765 >                     provider=ldap://ldap-rid2.example.com\r
766 >                     bindmethod=simple\r
767 >                     binddn="cn=mirrormode,dc=example,dc=com"\r
768 >                     credentials=mirrormode\r
769 >                     searchbase="dc=example,dc=com"\r
770 >                     schemachecking=on\r
771 >                     type=refreshAndPersist\r
772 >                     retry="60 +"\r
773 >       \r
774 >       mirrormode on
775 >       serverID    1
776
777 MirrorMode node 2:
778
779 >       # syncrepl directives\r
780 >       syncrepl      rid=001\r
781 >                     provider=ldap://ldap-ridr1.example.com\r
782 >                     bindmethod=simple\r
783 >                     binddn="cn=mirrormode,dc=example,dc=com"\r
784 >                     credentials=mirrormode\r
785 >                     searchbase="dc=example,dc=com"\r
786 >                     schemachecking=on\r
787 >                     type=refreshAndPersist\r
788 >                     retry="60 +"\r
789 >
790 >       syncrepl      rid=002\r
791 >                     provider=ldap://ldap-rid2.example.com\r
792 >                     bindmethod=simple\r
793 >                     binddn="cn=mirrormode,dc=example,dc=com"\r
794 >                     credentials=mirrormode\r
795 >                     searchbase="dc=example,dc=com"\r
796 >                     schemachecking=on\r
797 >                     type=refreshAndPersist\r
798 >                     retry="60 +"\r
799 >       \r
800 >       mirrormode on
801 >       serverID    2
802
803 It's simple really; each MirrorMode node is setup {{B:exactly}} the same, except
804 that the {{serverID}} is unique.
805
806 H4: Failover Configuration
807
808 There are generally 2 choices for this; 1.  Hardware proxies/load-balancing or 
809 dedicated proxy software, 2. using a Back-LDAP proxy as a syncrepl provider
810
811 A typical enterprise example might be:
812
813 !import "dual_dc.png"; align="center"; title="MirrorMode Enterprise Configuration"
814 FT[align="Center"] Figure X.Y: MirrorMode in a Dual Data Center Configuration
815
816 H4: Normal Consumer Configuration
817
818 This is exactly the same as the {{SECT:Set up the consumer slapd}} section. It
819 can either setup in normal {{SECT:syncrepl replication}} mode, or in 
820 {{SECT:delta-syncrepl replication}} mode.
821
822 H3: MirrorMode Summary
823
824 Hopefully you will now have a directory architecture that provides all of the 
825 consistency guarantees of single-master replication, whilst also providing the 
826 high availability of multi-master replication.
827
828