1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
|
=encoding utf-8
=head1 NAME
ngx_stream_zone_sync_module - Module ngx_stream_zone_sync_module
=head1
The C<ngx_stream_zone_sync_module> module (1.13.8)
provides the necessary support for synchronizing contents of
L<shared memory zones|ngx_stream_upstream_module>
between nodes of a cluster.
To enable synchronization for a particular zone, a corresponding module
must support this feature.
Currently, it is possible to synchronize HTTP
L<sticky|ngx_http_upstream_module>
sessions, information about
L<excessive HTTP requests|ngx_http_limit_req_module>,
and key-value pairs both in
L<http|ngx_http_keyval_module>
and L<stream|ngx_stream_keyval_module>.
B<NOTE>
This module is available as part of our
commercial subscription.
=head1 Example Configuration
Minimal configuration:
http {
...
upstream backend {
server backend1.example.com:8080;
server backend2.example.com:8081;
sticky learn
create=$upstream_cookie_examplecookie
lookup=$cookie_examplecookie
zone=client_sessions:1m <emphasis>sync</emphasis>;
}
...
}
stream {
...
server {
zone_sync;
listen 127.0.0.1:12345;
# cluster of 2 nodes
zone_sync_server a.example.com:12345;
zone_sync_server b.example.com:12345;
}
A more complex configuration with SSL enabled
and with cluster members defined by DNS:
...
stream {
...
resolver 127.0.0.1 valid=10s;
server {
zone_sync;
# the name resolves to multiple addresses that correspond to cluster nodes
zone_sync_server cluster.example.com:12345 resolve;
listen 127.0.0.1:4433 ssl;
ssl_certificate localhost.crt;
ssl_certificate_key localhost.key;
zone_sync_ssl on;
zone_sync_ssl_certificate localhost.crt;
zone_sync_ssl_certificate_key localhost.key;
}
}
=head1 Directives
=head2 zone_sync
B<syntax:> zone_sync I<>
B<default:> I<>
B<context:> I<server>
Enables the synchronization of shared memory zones between cluster nodes.
Cluster nodes are defined using L</zone_sync_server> directives.
=head2 zone_sync_buffers
B<syntax:> zone_sync_buffers I<I<C<number>> I<C<size>>>
B<default:> I<8 4kE<verbar>8k>
B<context:> I<stream>
B<context:> I<server>
Sets the I<C<number>> and I<C<size>> of the
per-zone buffers used for pushing zone contents.
By default, the buffer size is equal to one memory page.
This is either 4K or 8K, depending on a platform.
B<NOTE>
A single buffer must be large enough to hold any entry of each zone being
synchronized.
=head2 zone_sync_connect_retry_interval
B<syntax:> zone_sync_connect_retry_interval I<I<C<time>>>
B<default:> I<1s>
B<context:> I<stream>
B<context:> I<server>
Defines an interval between connection attempts to another cluster node.
=head2 zone_sync_connect_timeout
B<syntax:> zone_sync_connect_timeout I<I<C<time>>>
B<default:> I<5s>
B<context:> I<stream>
B<context:> I<server>
Defines a timeout for establishing a connection with another cluster node.
=head2 zone_sync_interval
B<syntax:> zone_sync_interval I<I<C<time>>>
B<default:> I<1s>
B<context:> I<stream>
B<context:> I<server>
Defines an interval for polling updates in a shared memory zone.
=head2 zone_sync_recv_buffer_size
B<syntax:> zone_sync_recv_buffer_size I<I<C<size>>>
B<default:> I<4kE<verbar>8k>
B<context:> I<stream>
B<context:> I<server>
Sets I<C<size>> of a per-connection receive buffer used to parse
incoming stream of synchronization messages.
The buffer size must be equal or greater than one of the
L</zone_sync_buffers>.
By default, the buffer size is equal to
zone_sync_buffers I<C<size>>
multiplied by I<C<number>>.
=head2 zone_sync_server
B<syntax:> zone_sync_server I<I<C<address>> [C<resolve>]>
B<default:> I<>
B<context:> I<server>
Defines the I<C<address>> of a cluster node.
The address can be specified as a domain name or IP address
with a mandatory port, or as a UNIX-domain socket path
specified after the “C<unix:>” prefix.
A domain name that resolves to several IP addresses defines
multiple nodes at once.
The C<resolve> parameter instructs nginx to monitor
changes of the IP addresses that correspond to a domain name of the node
and automatically modify the configuration
without the need of restarting nginx.
Cluster nodes are specified either dynamically as a single
C<zone_sync_server> directive with
the C<resolve> parameter, or statically as a series of several
directives without the parameter.
B<NOTE>
Each cluster node should be specified only once.
B<NOTE>
All cluster nodes should use the same configuration.
In order for the C<resolve> parameter to work,
the L<ngx_stream_core_module> directive
must be specified in the
L<ngx_stream_core_module> block.
Example:
stream {
resolver 10.0.0.1;
server {
zone_sync;
zone_sync_server cluster.example.com:12345 resolve;
...
}
}
=head2 zone_sync_ssl
B<syntax:> zone_sync_ssl I<C<on> E<verbar> C<off>>
B<default:> I<off>
B<context:> I<stream>
B<context:> I<server>
Enables the SSLE<sol>TLS protocol for connections to another cluster server.
=head2 zone_sync_ssl_certificate
B<syntax:> zone_sync_ssl_certificate I<I<C<file>>>
B<context:> I<stream>
B<context:> I<server>
Specifies a I<C<file>> with the certificate in the PEM format
used for authentication to another cluster server.
=head2 zone_sync_ssl_certificate_key
B<syntax:> zone_sync_ssl_certificate_key I<I<C<file>>>
B<context:> I<stream>
B<context:> I<server>
Specifies a I<C<file>> with the secret key in the PEM format
used for authentication to another cluster server.
=head2 zone_sync_ssl_ciphers
B<syntax:> zone_sync_ssl_ciphers I<I<C<ciphers>>>
B<default:> I<DEFAULT>
B<context:> I<stream>
B<context:> I<server>
Specifies the enabled ciphers for connections to another cluster server.
The ciphers are specified in the format understood by the OpenSSL library.
The full list can be viewed using the
“C<openssl ciphers>” command.
=head2 zone_sync_ssl_conf_command
B<syntax:> zone_sync_ssl_conf_command I<I<C<name>> I<C<value>>>
B<context:> I<stream>
B<context:> I<server>
This directive appeared in version 1.19.4.
Sets arbitrary OpenSSL configuration
L<commands|https://www.openssl.org/docs/man1.1.1/man3/SSL_CONF_cmd.html>
when establishing a connection with another cluster server.
B<NOTE>
The directive is supported when using OpenSSL 1.0.2 or higher.
Several C<zone_sync_ssl_conf_command> directives
can be specified on the same level.
These directives are inherited from the previous configuration level
if and only if there are
no C<zone_sync_ssl_conf_command> directives
defined on the current level.
B<NOTE>
Note that configuring OpenSSL directly
might result in unexpected behavior.
=head2 zone_sync_ssl_crl
B<syntax:> zone_sync_ssl_crl I<I<C<file>>>
B<context:> I<stream>
B<context:> I<server>
Specifies a I<C<file>> with revoked certificates (CRL)
in the PEM format used to verify
the certificate of another cluster server.
=head2 zone_sync_ssl_name
B<syntax:> zone_sync_ssl_name I<I<C<name>>>
B<default:> I<host from zone_sync_server>
B<context:> I<stream>
B<context:> I<server>
This directive appeared in version 1.15.7.
Allows overriding the server name used to
verify
the certificate of a cluster server and to be
passed through SNI
when establishing a connection with the cluster server.
By default, the host part of the L</zone_sync_server> address is used,
or resolved IP address if the L</resolve> parameter is specified.
=head2 zone_sync_ssl_password_file
B<syntax:> zone_sync_ssl_password_file I<I<C<file>>>
B<context:> I<stream>
B<context:> I<server>
Specifies a I<C<file>> with passphrases for
secret keys
where each passphrase is specified on a separate line.
Passphrases are tried in turn when loading the key.
=head2 zone_sync_ssl_protocols
B<syntax:> zone_sync_ssl_protocols I<
[C<SSLv2>]
[C<SSLv3>]
[C<TLSv1>]
[C<TLSv1.1>]
[C<TLSv1.2>]
[C<TLSv1.3>]>
B<default:> I<TLSv1.2 TLSv1.3>
B<context:> I<stream>
B<context:> I<server>
Enables the specified protocols for connections to another cluster server.
=head2 zone_sync_ssl_server_name
B<syntax:> zone_sync_ssl_server_name I<C<on> E<verbar> C<off>>
B<default:> I<off>
B<context:> I<stream>
B<context:> I<server>
This directive appeared in version 1.15.7.
Enables or disables passing of the server name through
L<TLS
Server Name Indication extension|http://en.wikipedia.org/wiki/Server_Name_Indication> (SNI, RFC 6066)
when establishing a connection with another cluster server.
=head2 zone_sync_ssl_trusted_certificate
B<syntax:> zone_sync_ssl_trusted_certificate I<I<C<file>>>
B<context:> I<stream>
B<context:> I<server>
Specifies a I<C<file>> with trusted CA certificates in the PEM format
used to verify
the certificate of another cluster server.
=head2 zone_sync_ssl_verify
B<syntax:> zone_sync_ssl_verify I<C<on> E<verbar> C<off>>
B<default:> I<off>
B<context:> I<stream>
B<context:> I<server>
Enables or disables verification of another cluster server certificate.
=head2 zone_sync_ssl_verify_depth
B<syntax:> zone_sync_ssl_verify_depth I<I<C<number>>>
B<default:> I<1>
B<context:> I<stream>
B<context:> I<server>
Sets the verification depth in another cluster server certificates chain.
=head2 zone_sync_timeout
B<syntax:> zone_sync_timeout I<I<C<timeout>>>
B<default:> I<5s>
B<context:> I<stream>
B<context:> I<server>
Sets the I<C<timeout>> between two successive
read or write operations on connection to another cluster node.
If no data is transmitted within this time, the connection is closed.
=head1 API endpoints
The synchronization status of a node is available via the
L<E<sol>streamE<sol>zone_syncE<sol>|ngx_http_api_module>
endpoint of the API which returns the
L<following|ngx_http_api_module>
metrics.
=head1 Starting, stopping, removing a cluster node
To start a new node, update a DNS record of a cluster hostname
with the IP address of the new node and start an instance.
The new node will discover other nodes from DNS or static configuration
and will start sending updates to them.
Other nodes will eventually discover the new node using DNS and
start pushing updates to it.
In case of static configuration,
other nodes need to be reloaded in order to send updates to the new node.
To stop a node, send the C<QUIT> signal to the instance.
The node will finish zone synchronization
and gracefully close open connections.
To remove a node, update a DNS record of a cluster hostname
and remove the IP address of the node.
All other nodes will eventually discover that the node is removed,
close connections to the node, and will no longer try to connect to it.
After the node is removed, it can be stopped as described above.
In case of static configuration, other nodes need to be reloaded
in order to stop sending updates to the removed node.
|