]> git.sur5r.net Git - openldap/blob - doc/guide/admin/replication.sdf
Moving from Slurpd.
[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
8 H2: Replication Strategies
9
10
11 H3: Working with Firewalls
12
13
14 H3: Replacing Slurpd
15
16
17 H2: Replication Types
18
19
20 H3: syncrepl replication
21
22
23 H3: delta-syncrepl replication
24
25
26 H3: N-Way Multi-Master
27
28
29 H3: MirrorMode
30
31
32 H2: LDAP Sync Replication
33
34 The {{TERM:LDAP Sync}} Replication engine, {{TERM:syncrepl}} for
35 short, is a consumer-side replication engine that enables the
36 consumer {{TERM:LDAP}} server to maintain a shadow copy of a
37 {{TERM:DIT}} fragment. A syncrepl engine resides at the consumer-side
38 as one of the {{slapd}}(8) threads. It creates and maintains a
39 consumer replica by connecting to the replication provider to perform
40 the initial DIT content load followed either by periodic content
41 polling or by timely updates upon content changes.
42
43 Syncrepl uses the LDAP Content Synchronization (or LDAP Sync for
44 short) protocol as the replica synchronization protocol.  It provides
45 a stateful replication which supports both pull-based and push-based
46 synchronization and does not mandate the use of a history store.
47
48 Syncrepl keeps track of the status of the replication content by
49 maintaining and exchanging synchronization cookies. Because the
50 syncrepl consumer and provider maintain their content status, the
51 consumer can poll the provider content to perform incremental
52 synchronization by asking for the entries required to make the
53 consumer replica up-to-date with the provider content. Syncrepl
54 also enables convenient management of replicas by maintaining replica
55 status.  The consumer replica can be constructed from a consumer-side
56 or a provider-side backup at any synchronization status. Syncrepl
57 can automatically resynchronize the consumer replica up-to-date
58 with the current provider content.
59
60 Syncrepl supports both pull-based and push-based synchronization.
61 In its basic refreshOnly synchronization mode, the provider uses
62 pull-based synchronization where the consumer servers need not be
63 tracked and no history information is maintained.  The information
64 required for the provider to process periodic polling requests is
65 contained in the synchronization cookie of the request itself.  To
66 optimize the pull-based synchronization, syncrepl utilizes the
67 present phase of the LDAP Sync protocol as well as its delete phase,
68 instead of falling back on frequent full reloads. To further optimize
69 the pull-based synchronization, the provider can maintain a per-scope
70 session log as a history store. In its refreshAndPersist mode of
71 synchronization, the provider uses a push-based synchronization.
72 The provider keeps track of the consumer servers that have requested
73 a persistent search and sends them necessary updates as the provider
74 replication content gets modified.
75
76 With syncrepl, a consumer server can create a replica without
77 changing the provider's configurations and without restarting the
78 provider server, if the consumer server has appropriate access
79 privileges for the DIT fragment to be replicated. The consumer
80 server can stop the replication also without the need for provider-side
81 changes and restart.
82
83 Syncrepl supports both partial and sparse replications.  The shadow
84 DIT fragment is defined by a general search criteria consisting of
85 base, scope, filter, and attribute list.  The replica content is
86 also subject to the access privileges of the bind identity of the
87 syncrepl replication connection.
88
89
90 H3: The LDAP Content Synchronization Protocol
91
92 The LDAP Sync protocol allows a client to maintain a synchronized
93 copy of a DIT fragment. The LDAP Sync operation is defined as a set
94 of controls and other protocol elements which extend the LDAP search
95 operation. This section introduces the LDAP Content Sync protocol
96 only briefly.  For more information, refer to {{REF:RFC4533}}.
97
98 The LDAP Sync protocol supports both polling and listening for
99 changes by defining two respective synchronization operations:
100 {{refreshOnly}} and {{refreshAndPersist}}.  Polling is implemented
101 by the {{refreshOnly}} operation.  The client copy is synchronized
102 to the server copy at the time of polling.  The server finishes the
103 search operation by returning {{SearchResultDone}} at the end of
104 the search operation as in the normal search.  The listening is
105 implemented by the {{refreshAndPersist}} operation.  Instead of
106 finishing the search after returning all entries currently matching
107 the search criteria, the synchronization search remains persistent
108 in the server. Subsequent updates to the synchronization content
109 in the server cause additional entry updates to be sent to the
110 client.
111
112 The {{refreshOnly}} operation and the refresh stage of the
113 {{refreshAndPersist}} operation can be performed with a present
114 phase or a delete phase.
115
116 In the present phase, the server sends the client the entries updated
117 within the search scope since the last synchronization. The server
118 sends all requested attributes, be it changed or not, of the updated
119 entries.  For each unchanged entry which remains in the scope, the
120 server sends a present message consisting only of the name of the
121 entry and the synchronization control representing state present.
122 The present message does not contain any attributes of the entry.
123 After the client receives all update and present entries, it can
124 reliably determine the new client copy by adding the entries added
125 to the server, by replacing the entries modified at the server, and
126 by deleting entries in the client copy which have not been updated
127 nor specified as being present at the server.
128
129 The transmission of the updated entries in the delete phase is the
130 same as in the present phase. The server sends all the requested
131 attributes of the entries updated within the search scope since the
132 last synchronization to the client. In the delete phase, however,
133 the server sends a delete message for each entry deleted from the
134 search scope, instead of sending present messages.  The delete
135 message consists only of the name of the entry and the synchronization
136 control representing state delete.  The new client copy can be
137 determined by adding, modifying, and removing entries according to
138 the synchronization control attached to the {{SearchResultEntry}}
139 message.
140
141 In the case that the LDAP Sync server maintains a history store and
142 can determine which entries are scoped out of the client copy since
143 the last synchronization time, the server can use the delete phase.
144 If the server does not maintain any history store, cannot determine
145 the scoped-out entries from the history store, or the history store
146 does not cover the outdated synchronization state of the client,
147 the server should use the present phase.  The use of the present
148 phase is much more efficient than a full content reload in terms
149 of the synchronization traffic.  To reduce the synchronization
150 traffic further, the LDAP Sync protocol also provides several
151 optimizations such as the transmission of the normalized {{EX:entryUUID}}s
152 and the transmission of multiple {{EX:entryUUIDs}} in a single
153 {{syncIdSet}} message.
154
155 At the end of the {{refreshOnly}} synchronization, the server sends
156 a synchronization cookie to the client as a state indicator of the
157 client copy after the synchronization is completed.  The client
158 will present the received cookie when it requests the next incremental
159 synchronization to the server.
160
161 When {{refreshAndPersist}} synchronization is used, the server sends
162 a synchronization cookie at the end of the refresh stage by sending
163 a Sync Info message with TRUE refreshDone.  It also sends a
164 synchronization cookie by attaching it to {{SearchResultEntry}}
165 generated in the persist stage of the synchronization search. During
166 the persist stage, the server can also send a Sync Info message
167 containing the synchronization cookie at any time the server wants
168 to update the client-side state indicator.  The server also updates
169 a synchronization indicator of the client at the end of the persist
170 stage.
171
172 In the LDAP Sync protocol, entries are uniquely identified by the
173 {{EX:entryUUID}} attribute value. It can function as a reliable
174 identifier of the entry. The DN of the entry, on the other hand,
175 can be changed over time and hence cannot be considered as the
176 reliable identifier.  The {{EX:entryUUID}} is attached to each
177 {{SearchResultEntry}} or {{SearchResultReference}} as a part of the
178 synchronization control.
179
180
181 H3: Syncrepl Details
182
183 The syncrepl engine utilizes both the {{refreshOnly}} and the
184 {{refreshAndPersist}} operations of the LDAP Sync protocol.  If a
185 syncrepl specification is included in a database definition,
186 {{slapd}}(8) launches a syncrepl engine as a {{slapd}}(8) thread
187 and schedules its execution. If the {{refreshOnly}} operation is
188 specified, the syncrepl engine will be rescheduled at the interval
189 time after a synchronization operation is completed.  If the
190 {{refreshAndPersist}} operation is specified, the engine will remain
191 active and process the persistent synchronization messages from the
192 provider.
193
194 The syncrepl engine utilizes both the present phase and the delete
195 phase of the refresh synchronization. It is possible to configure
196 a per-scope session log in the provider server which stores the
197 {{EX:entryUUID}}s of a finite number of entries deleted from a
198 replication content.  Multiple replicas of single provider content
199 share the same per-scope session log. The syncrepl engine uses the
200 delete phase if the session log is present and the state of the
201 consumer server is recent enough that no session log entries are
202 truncated after the last synchronization of the client.  The syncrepl
203 engine uses the present phase if no session log is configured for
204 the replication content or if the consumer replica is too outdated
205 to be covered by the session log.  The current design of the session
206 log store is memory based, so the information contained in the
207 session log is not persistent over multiple provider invocations.
208 It is not currently supported to access the session log store by
209 using LDAP operations. It is also not currently supported to impose
210 access control to the session log.
211
212 As a further optimization, even in the case the synchronization
213 search is not associated with any session log, no entries will be
214 transmitted to the consumer server when there has been no update
215 in the replication context.
216
217 The syncrepl engine, which is a consumer-side replication engine,
218 can work with any backends. The LDAP Sync provider can be configured
219 as an overlay on any backend, but works best with the {{back-bdb}}
220 or {{back-hdb}} backend.
221
222 The LDAP Sync provider maintains a {{EX:contextCSN}} for each
223 database as the current synchronization state indicator of the
224 provider content.  It is the largest {{EX:entryCSN}} in the provider
225 context such that no transactions for an entry having smaller
226 {{EX:entryCSN}} value remains outstanding.  The {{EX:contextCSN}}
227 could not just be set to the largest issued {{EX:entryCSN}} because
228 {{EX:entryCSN}} is obtained before a transaction starts and
229 transactions are not committed in the issue order.
230
231 The provider stores the {{EX:contextCSN}} of a context in the
232 {{EX:contextCSN}} attribute of the context suffix entry. The attribute
233 is not written to the database after every update operation though;
234 instead it is maintained primarily in memory. At database start
235 time the provider reads the last saved {{EX:contextCSN}} into memory
236 and uses the in-memory copy exclusively thereafter. By default,
237 changes to the {{EX:contextCSN}} as a result of database updates
238 will not be written to the database until the server is cleanly
239 shut down. A checkpoint facility exists to cause the contextCSN to
240 be written out more frequently if desired.
241
242 Note that at startup time, if the provider is unable to read a
243 {{EX:contextCSN}} from the suffix entry, it will scan the entire
244 database to determine the value, and this scan may take quite a
245 long time on a large database. When a {{EX:contextCSN}} value is
246 read, the database will still be scanned for any {{EX:entryCSN}}
247 values greater than it, to make sure the {{EX:contextCSN}} value
248 truly reflects the greatest committed {{EX:entryCSN}} in the database.
249 On databases which support inequality indexing, setting an eq index
250 on the {{EX:entryCSN}} attribute and configuring {{contextCSN}}
251 checkpoints will greatly speed up this scanning step.
252
253 If no {{EX:contextCSN}} can be determined by reading and scanning
254 the database, a new value will be generated. Also, if scanning the
255 database yielded a greater {{EX:entryCSN}} than was previously
256 recorded in the suffix entry's {{EX:contextCSN}} attribute, a
257 checkpoint will be immediately written with the new value.
258
259 The consumer also stores its replica state, which is the provider's
260 {{EX:contextCSN}} received as a synchronization cookie, in the
261 {{EX:contextCSN}} attribute of the suffix entry.  The replica state
262 maintained by a consumer server is used as the synchronization state
263 indicator when it performs subsequent incremental synchronization
264 with the provider server. It is also used as a provider-side
265 synchronization state indicator when it functions as a secondary
266 provider server in a cascading replication configuration.  Since
267 the consumer and provider state information are maintained in the
268 same location within their respective databases, any consumer can
269 be promoted to a provider (and vice versa) without any special
270 actions.
271
272 Because a general search filter can be used in the syncrepl
273 specification, some entries in the context may be omitted from the
274 synchronization content.  The syncrepl engine creates a glue entry
275 to fill in the holes in the replica context if any part of the
276 replica content is subordinate to the holes. The glue entries will
277 not be returned in the search result unless {{ManageDsaIT}} control
278 is provided.
279
280 Also as a consequence of the search filter used in the syncrepl
281 specification, it is possible for a modification to remove an entry
282 from the replication scope even though the entry has not been deleted
283 on the provider. Logically the entry must be deleted on the consumer
284 but in {{refreshOnly}} mode the provider cannot detect and propagate
285 this change without the use of the session log.
286
287
288 H3: Configuring Syncrepl
289
290 Because syncrepl is a consumer-side replication engine, the syncrepl
291 specification is defined in {{slapd.conf}}(5) of the consumer
292 server, not in the provider server's configuration file.  The initial
293 loading of the replica content can be performed either by starting
294 the syncrepl engine with no synchronization cookie or by populating
295 the consumer replica by adding an {{TERM:LDIF}} file dumped as a
296 backup at the provider.
297
298 When loading from a backup, it is not required to perform the initial
299 loading from the up-to-date backup of the provider content. The
300 syncrepl engine will automatically synchronize the initial consumer
301 replica to the current provider content. As a result, it is not
302 required to stop the provider server in order to avoid the replica
303 inconsistency caused by the updates to the provider content during
304 the content backup and loading process.
305
306 When replicating a large scale directory, especially in a bandwidth
307 constrained environment, it is advised to load the consumer replica
308 from a backup instead of performing a full initial load using
309 syncrepl.
310
311
312 H4: Set up the provider slapd
313
314 The provider is implemented as an overlay, so the overlay itself
315 must first be configured in {{slapd.conf}}(5) before it can be
316 used. The provider has only two configuration directives, for setting
317 checkpoints on the {{EX:contextCSN}} and for configuring the session
318 log.  Because the LDAP Sync search is subject to access control,
319 proper access control privileges should be set up for the replicated
320 content.
321
322 The {{EX:contextCSN}} checkpoint is configured by the
323
324 >       syncprov-checkpoint <ops> <minutes>
325
326 directive. Checkpoints are only tested after successful write
327 operations.  If {{<ops>}} operations or more than {{<minutes>}}
328 time has passed since the last checkpoint, a new checkpoint is
329 performed.
330
331 The session log is configured by the
332
333 >       syncprov-sessionlog <size>
334
335 directive, where {{<size>}} is the maximum number of session log
336 entries the session log can record. When a session log is configured,
337 it is automatically used for all LDAP Sync searches within the
338 database.
339
340 Note that using the session log requires searching on the {{entryUUID}}
341 attribute. Setting an eq index on this attribute will greatly benefit
342 the performance of the session log on the provider.
343
344 A more complete example of the {{slapd.conf}}(5) content is thus:
345
346 >       database bdb
347 >       suffix dc=Example,dc=com
348 >       rootdn dc=Example,dc=com
349 >       directory /var/ldap/db
350 >       index objectclass,entryCSN,entryUUID eq
351 >
352 >       overlay syncprov
353 >       syncprov-checkpoint 100 10
354 >       syncprov-sessionlog 100
355
356
357 H4: Set up the consumer slapd
358
359 The syncrepl replication is specified in the database section of
360 {{slapd.conf}}(5) for the replica context.  The syncrepl engine
361 is backend independent and the directive can be defined with any
362 database type.
363
364 >       database hdb
365 >       suffix dc=Example,dc=com
366 >       rootdn dc=Example,dc=com
367 >       directory /var/ldap/db
368 >       index objectclass,entryCSN,entryUUID eq
369 >
370 >       syncrepl rid=123
371 >               provider=ldap://provider.example.com:389
372 >               type=refreshOnly
373 >               interval=01:00:00:00
374 >               searchbase="dc=example,dc=com"
375 >               filter="(objectClass=organizationalPerson)"
376 >               scope=sub
377 >               attrs="cn,sn,ou,telephoneNumber,title,l"
378 >               schemachecking=off
379 >               bindmethod=simple
380 >               binddn="cn=syncuser,dc=example,dc=com"
381 >               credentials=secret
382
383 In this example, the consumer will connect to the provider {{slapd}}(8)
384 at port 389 of {{FILE:ldap://provider.example.com}} to perform a
385 polling ({{refreshOnly}}) mode of synchronization once a day.  It
386 will bind as {{EX:cn=syncuser,dc=example,dc=com}} using simple
387 authentication with password "secret".  Note that the access control
388 privilege of {{EX:cn=syncuser,dc=example,dc=com}} should be set
389 appropriately in the provider to retrieve the desired replication
390 content. Also the search limits must be high enough on the provider
391 to allow the syncuser to retrieve a complete copy of the requested
392 content.  The consumer uses the rootdn to write to its database so
393 it always has full permissions to write all content.
394
395 The synchronization search in the above example will search for the
396 entries whose objectClass is organizationalPerson in the entire
397 subtree rooted at {{EX:dc=example,dc=com}}. The requested attributes
398 are {{EX:cn}}, {{EX:sn}}, {{EX:ou}}, {{EX:telephoneNumber}},
399 {{EX:title}}, and {{EX:l}}. The schema checking is turned off, so
400 that the consumer {{slapd}}(8) will not enforce entry schema
401 checking when it process updates from the provider {{slapd}}(8).
402
403 For more detailed information on the syncrepl directive, see the
404 {{SECT:syncrepl}} section of {{SECT:The slapd Configuration File}}
405 chapter of this admin guide.
406
407
408 H4: Start the provider and the consumer slapd
409
410 The provider {{slapd}}(8) is not required to be restarted.
411 {{contextCSN}} is automatically generated as needed: it might be
412 originally contained in the {{TERM:LDIF}} file, generated by
413 {{slapadd}} (8), generated upon changes in the context, or generated
414 when the first LDAP Sync search arrives at the provider.  If an
415 LDIF file is being loaded which did not previously contain the
416 {{contextCSN}}, the {{-w}} option should be used with {{slapadd}}
417 (8) to cause it to be generated. This will allow the server to
418 startup a little quicker the first time it runs.
419
420 When starting a consumer {{slapd}}(8), it is possible to provide
421 a synchronization cookie as the {{-c cookie}} command line option
422 in order to start the synchronization from a specific state.  The
423 cookie is a comma separated list of name=value pairs. Currently
424 supported syncrepl cookie fields are {{csn=<csn>}} and {{rid=<rid>}}.
425 {{<csn>}} represents the current synchronization state of the
426 consumer replica.  {{<rid>}} identifies a consumer replica locally
427 within the consumer server. It is used to relate the cookie to the
428 syncrepl definition in {{slapd.conf}}(5) which has the matching
429 replica identifier.  The {{<rid>}} must have no more than 3 decimal
430 digits.  The command line cookie overrides the synchronization
431 cookie stored in the consumer replica database.
432
433
434 H2: N-Way Multi-Master
435
436
437 H2: MirrorMode
438
439