-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathdeploy-elastic.sh-fleet-notoken
executable file
·1909 lines (1671 loc) · 60.5 KB
/
deploy-elastic.sh-fleet-notoken
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
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env bash
# justin lim <[email protected]>
# version 6.1 - added additional functions and cleaned up
# version 5.0 - added fleet
# version 4.0 - added apm-server & enterprise search(still needs some work on es but its functional)
# version 3.0 - added minio & snapshots
# version 2.0 - added monitoring option
# version 1.0 - 3 node deployment with kibana
# $ curl -fsSL https://raw.githubusercontent.com/jlim0930/scripts/master/deploy-elastic.sh -o deploy-elastic.sh
# es01 is exposed on 9200 with SSL
# kibana is exposed on 5601 with SSL
# enterprise-search is exposed on 3002 without SSL
# fleet is exposed on 8220
###############################################################################################################
# configurable vars
HEAP="512m"
###############################################################################################################
# set WORKDIR
WORKDIR="${HOME}/elasticstack"
# colors
red=`tput setaf 1`
green=`tput setaf 2`
blue=`tput setaf 4`
reset=`tput sgr0`
###############################################################################################################
help() {
echo "This script currently works on all 7.x and 6.x versions of elasticsearch"
echo ""
echo "${green}Usage:${reset} ./`basename $0` command version"
echo "${blue}COMMANDS${reset}"
echo " build|start|stack VERSION - Starts a basic deployment of ES & Kibana. Must give the full version"
echo " ${green}EXAMPLE:${reset} ./`basename $0` build 7.15.0"
echo " ${blue}monitor${reset} - Starts the stack with metricbeat & filebeat monitoring. ${red}Only for version 6.5+${reset}"
echo " ${green}EXAMPLE:${reset} ./`basename $0` monitor 7.10.2"
echo " ${blue}snapshot${reset} - Starts the stack with minio and configure for snapshots. For 7.4+ it will also setup SLM."
echo " ${green}EXAMPLE:${reset} ./`basename $0` snapshot 7.10.2"
echo " ${blue}full${reset} - Starts the stack with monitoring & snapshots"
echo " ${green}EXAMPLE:${reset} ./`basename $0` full 7.10.2"
echo ""
echo " ${blue}apm${reset} - Starts the stack with apm-server"
echo " ${green}EXAMPLE:${reset} ./`basename $0` apm 7.10.2"
echo " ${blue}fullapm${reset} - Starts the stack with monitoring, snapshots, & apm-server. ${red}Only for version 6.5+${reset}"
echo " ${green}EXAMPLE:${reset} ./`basename $0` fullapm 7.10.2"
echo ""
echo " ${blue}entsearch${reset} - Starts the stack with enterprise search. ${red}Enterprise Search is only available on 7.7+${reset}"
echo " ${green}EXAMPLE:${reset} ./`basename $0` entsearch 7.10.2"
echo " ${blue}fullentsearch${reset} - Starts the stack wtih monitoring, snapshots, & Enterprise Search"
echo " ${green}EXAMPLE:${reset} ./`basename $0` fullentsearch 7.10.2"
echo ""
echo " ${blue}fleet${reset} - Starts deployment with fleet server ${red}Fleet Server is only available on 7.10+${reset}"
echo " ${green}EXAMPLE:${reset} ./`basename $0` fleet 7.14.1"
echo " ${blue}fullfleet${reset} - Starts the stack wtih monitoring, snapshots, & fleet server"
echo " ${green}EXAMPLE:${reset} ./`basename $0` fullfleet 7.14.1"
echo ""
echo " ${blue}all${reset} - Starts deployment with everything! ${red}Enterprise Search is only available on 7.7+${reset}"
echo " ${green}EXAMPLE:${reset} ./`basename $0` all 7.10.2"
echo ""
echo " ${blue}cleanup${reset} - cleans up all the containers and directories"
}
###############################################################################################################
# check for version and make sure its [6..8].x.x and assign MAJOR MINOR BUGFIX number
version() {
if [ -z ${1} ]; then
help
else
re="^[6-8]{1}[.][0-9]{1,2}[.][0-9]{1,2}$"
if [[ ${1} =~ ${re} ]]; then
MAJOR="$(echo ${1} | awk -F. '{ print $1 }')"
MINOR="$(echo ${1} | awk -F. '{ print $2 }')"
BUGFIX="$(echo ${1} | awk -F. '{ print $3 }')"
else
help
fi
fi
}
# function used for version checking
checkversion() {
echo "$@" | awk -F. '{ printf("%d%03d%03d%03d\n", $1,$2,$3,$4); }'
}
# check vm.max_map_count on linux and ask user to set it if not set properly
checkmaxmapcount() {
if [ "`uname -s`" != "Darwin" ]; then
COUNT=`sysctl vm.max_map_count | awk {' print $3 '}`
if [ ${COUNT} -le "262144" ]; then
echo "${green}[DEBUG]${reset} Ensuring vm.max_map_count is ${COUNT}... proceeding"
else
echo "${red}[DEBUG]${reset} vm.max_map_count needs to be set to 262144. Please run sudo sysctl -w vm.max_map_count=262144"
exit;
fi
fi
}
# check to ensure docker is running and you can run docker commands
checkdocker() {
docker info >/dev/null 2>&1
if [ $? -ne 0 ]; then
echo "${red}[DEBUG]${reset} Docker is not running or you are not part of the docker group"
exit
fi
# check to ensure docker-compose is installed
docker-compose version >/dev/null 2>&1
if [ $? -ne 0 ]; then
echo "${red}[DEBUG]${reset} docker-compose is not installed. Please install docker-compose and try again"
exit
fi
}
# check to see if containers/networks/volumes exists
checkcontainer() {
for name in es01 es02 es03 kibana
do
if [ $(docker ps -a --format '{{.Names}}' | grep -c ${name}) -ge 1 ]; then
echo "${red}[DEBUG]${reset} Container ${green}${name}${reset} exists. Please remove and try again"
exit
fi
done
for name in es_default
do
if [ $(docker network ls --format '{{.Name}}' | grep -c ${name}) -ge 1 ]; then
echo "${red}[DEBUG]${reset} Network ${green}${name}${reset} exists. Please remove and try again"
exit
fi
done
for name in es_data01 es_data02 es_data03 es_certs
do
if [ $(docker volume ls --format '{{.Name}}' | grep -c ${name}) -ge 1 ]; then
echo "${red}[DEBUG]${reset} Volume ${green}${name}${reset} exists. Please remove and try again"
exit
fi
done
}
# check to make sure that the deployment is in GREEN status
checkhealth() {
if [ $(checkversion $VERSION) -ge $(checkversion "7.2.0") ]; then
while true
do
if [ `docker run --rm -v es_certs:/certs --network=es_default docker.elastic.co/elasticsearch/elasticsearch:${VERSION} curl -s --cacert /certs/ca/ca.crt -u elastic:${PASSWD} https://es01:9200/_cluster/health | grep -c green` = 1 ]; then
sleep 2
break
else
echo "${red}[DEBUG]${reset} elasticsearch is unhealthy. Checking again in 2 seconds.. if this doesnt finish in ~ 30 seconds something is wrong ctrl-c please."
sleep 2
fi
done
else
while true
do
if [ `curl --cacert certs/ca/ca.crt -s -u elastic:${PASSWD} https://localhost:9200/_cluster/health | grep -c green` = 1 ]; then
sleep 2
break
else
echo "${red}[DEBUG]${reset} elasticsearch is unhealthy. Checking again in 2 seconds... if this doesnt finish in ~ 30 seconds something is wrong ctrl-c please."
sleep 2
fi
done
fi
echo "${green}[DEBUG]${reset} elasticsearch health is ${green}GREEN${reset} moving forward."
}
# grab the elastic password
grabpasswd() {
PASSWD=`cat notes | grep "PASSWORD elastic" | awk {' print $4 '}`
if [ -z ${PASSWD} ]; then
echo "${red}[DEBUG]${reset} unable to find elastic users password"
exit
else
echo "${green}[DEBUG]${reset} elastic user's password found ${PASSWD}"
fi
}
# checking for the image and pull it
pullimage() {
docker image inspect "${1}" > /dev/null 2>&1
if [ $? -ne 0 ]; then
echo "${green}[DEBUG]${reset} Pulling "${1}" image... might take a while"
docker pull "${1}"
if [ $? -ne 0 ]; then
echo "${red}[DEBUG]${reset} Unable to pull "${1}". "
exit
fi
else
echo "${green}[DEBUG]${reset} "${1}" docker image already exists.. moving forward.."
fi
}
# cleanup deployment
cleanup() {
echo "${green}********** Cleaning up "${VERSION}" **********${reset}"
# check to see if the directory exists should not since this is the start
STRING="-f stack-compose.yml"
LIST="es01 es02 es03 kibana es_wait_until_ready_1"
if [ -z ${WORKDIR} ]; then
cd ${WORKDIR}
if [ -f monitor-compose.yml ]; then
STRING="${STRING} -f monitor-compose.yml"
LIST="${LIST} metricbeat filebeat"
fi
if [ -f snapshot-compose.yml ]; then
STRING="${STRING} -f snapshot-compose.yml"
LIST="${LIST} minio01 es_mc_1"
fi
if [ -f apm-compose.yml ]; then
STRING="${STRING} -f apm-compose.yml"
LIST="${LIST} apm"
fi
if [ -f entsearch-compose.yml ]; then
STRING="${STRING} -f entsearch-compose.yml"
LIST="${LIST} entsearch"
fi
if [ -f fleet.yml ]; then
STRING="${STRING} -f fleet.yml"
LIST="${LIST} fleet"
fi
docker-compose ${STRING} down >/dev/null 2>&1
echo "${green}[DEBUG]${reset} Performed docker-compose down"
fi
docker stop es01 es02 es03 kibana metricbeat filebeat apm entsearch minio01 fleet es_mc_1 es_wait_until_ready_1 apm >/dev/null 2>&1
docker rm es01 es02 es03 kibana metricbeat filebeat apm entsearch minio01 fleet es_mc_1 es_wait_until_ready_1 apm >/dev/null 2>&1
docker network rm es_default >/dev/null 2>&1
docker volume rm es_data01 >/dev/null 2>&1
docker volume rm es_data02 >/dev/null 2>&1
docker volume rm es_data03 >/dev/null 2>&1
docker volume rm es_fleet >/dev/null 2>&1
docker volume rm es_certs >/dev/null 2>&1
echo "${green}[DEBUG]${reset} Removed volumes and networks"
rm -rf ${WORKDIR} >/dev/null 2>&1
echo "${green}[DEBUG]${reset} All cleanedup"
}
###############################################################################################################
# building the stack
stack() {
echo "${green}********** Deploying elasticsearch & kibana "${VERSION}" **********${reset}"
# some checks first
checkmaxmapcount
checkdocker
checkcontainer
# check to see if the directory exists should not since this is the start
if [ -d ${WORKDIR} ]; then
echo "${red}[DEBUG]${reset} Looks like ${WORKDIR} already exists. Please run cleanup to delete the old deployment"
echo ""
help
exit
fi
# pull stack images
pullimage "docker.elastic.co/elasticsearch/elasticsearch:${VERSION}"
pullimage "docker.elastic.co/kibana/kibana:${VERSION}"
# create directorys and files
mkdir -p ${WORKDIR}
cd ${WORKDIR}
mkdir temp
echo ${VERSION} > VERSION
# create elasticsearch.yml
cat > elasticsearch.yml<<EOF
network.host: 0.0.0.0
EOF
chown 1000 elasticsearch.yml >/dev/null 2>&1
echo "${green}[DEBUG]${reset} Created elasticsearch.yml"
# generate temp elastic password
PASSWD=`openssl rand -base64 29 | tr -d "=+/" | cut -c1-25`
echo "${green}[DEBUG]${reset} Setting temp password for elastic as ${PASSWD}"
# create temp kibana.yml
cat > kibana.yml<<EOF
elasticsearch.username: "elstic"
elasticsearch.password: "${PASSWD}"
EOF
echo "${green}[DEBUG]${reset} Created kibana.yml"
# create env file
cat > .env<<EOF
COMPOSE_PROJECT_NAME=es
CERTS_DIR=/usr/share/elasticsearch/config/certificates
KIBANA_CERTS_DIR=/usr/share/kibana/config/certificates
ELASTIC_PASSWORD=${PASSWD}
COMPOSE_HTTP_TIMEOUT=600
EOF
echo "${green}[DEBUG]${reset} Created .env file"
# create instances file
cat > instances.yml<<EOF
instances:
- name: es01
dns:
- es01
- localhost
ip:
- 127.0.0.1
- name: es02
dns:
- es02
- localhost
ip:
- 127.0.0.1
- name: es03
dns:
- es03
- localhost
ip:
- 127.0.0.1
- name: kibana
dns:
- kibana
- localhost
ip:
- 127.0.0.1
- name: apm
dns:
- apm
- localhost
ip:
- 127.0.0.1
- name: entsearch
dns:
- entsearch
- localhost
ip:
- 127.0.0.1
- name: minio
dns:
- minio01
- localhost
ip:
- 127.0.0.1
- name: fleet
dns:
- fleet
- localhost
ip:
- 127.0.0.1
EOF
echo "${green}[DEBUG]${reset} Created instances.yml"
# start creating create-certs.yml
createcertscurrent="version: '2.2'
services:
create_certs:
container_name: create_certs
image: docker.elastic.co/elasticsearch/elasticsearch:${VERSION}
command: >
bash -c '
yum install -y -q -e 0 unzip;
if [[ ! -f /certs/bundle.zip ]]; then
bin/elasticsearch-certutil cert --silent --pem --in config/certificates/instances.yml -out /certs/bundle.zip;
unzip /certs/bundle.zip -d /certs;
fi;
chown -R 1000:0 /certs
'
user: \"0\"
working_dir: /usr/share/elasticsearch
volumes: ['certs:/certs', '.:/usr/share/elasticsearch/config/certificates']
volumes: {"certs"}
"
createcerts71="version: '2.2'
services:
create_certs:
container_name: create_certs
image: docker.elastic.co/elasticsearch/elasticsearch:${VERSION}
command: >
bash -c '
if [[ ! -d config/certificates/certs ]]; then
mkdir config/certificates/certs;
fi;
if [[ ! -f /local/certs/bundle.zip ]]; then
bin/elasticsearch-certgen --silent --in config/certificates/instances.yml --out config/certificates/certs/bundle.zip;
unzip config/certificates/certs/bundle.zip -d config/certificates/certs;
fi;
chgrp -R 0 config/certificates/certs
'
user: \${UID:-1000}
working_dir: /usr/share/elasticsearch
volumes: ['.:/usr/share/elasticsearch/config/certificates']
"
createcerts6="version: '2.2'
services:
create_certs:
container_name: create_certs
image: docker.elastic.co/elasticsearch/elasticsearch:${VERSION}
command: >
bash -c '
if [[ ! -d config/certificates/certs ]]; then
mkdir config/certificates/certs;
fi;
if [[ ! -f /local/certs/bundle.zip ]]; then
bin/elasticsearch-certgen --silent --in config/certificates/instances.yml --out config/certificates/certs/bundle.zip;
unzip config/certificates/certs/bundle.zip -d config/certificates/certs;
fi;
chgrp -R 0 config/certificates/certs
'
user: \${UID:-1000}
working_dir: /usr/share/elasticsearch
volumes: ['.:/usr/share/elasticsearch/config/certificates']
"
if [ $(checkversion $VERSION) -ge $(checkversion "7.2.0") ]; then
echo "${createcertscurrent}" > create-certs.yml
else
echo "${createcerts6}" > create-certs.yml
fi
echo "${green}[DEBUG]${reset} Created create-certs.yml for ${VERSION}"
# create stack-compose.yml
stackcomposecurrent="version: '2.2'
services:
es01:
container_name: es01
image: docker.elastic.co/elasticsearch/elasticsearch:${VERSION}
environment:
- node.name=es01
- node.attr.data=hot
- node.attr.data2=hot
- node.attr.zone=zone1
- node.attr.zone2=zone1
- discovery.seed_hosts=es01,es02,es03
- cluster.initial_master_nodes=es01,es02,es03
- ELASTIC_PASSWORD=${PASSWD}
- \"ES_JAVA_OPTS=-Xms${HEAP} -Xmx${HEAP}\"
- xpack.license.self_generated.type=trial
- xpack.security.enabled=true
- xpack.security.http.ssl.enabled=true
- xpack.security.http.ssl.key=\$CERTS_DIR/es01/es01.key
- xpack.security.http.ssl.certificate_authorities=\$CERTS_DIR/ca/ca.crt
- xpack.security.http.ssl.certificate=\$CERTS_DIR/es01/es01.crt
- xpack.security.transport.ssl.enabled=true
- xpack.security.transport.ssl.verification_mode=certificate
- xpack.security.transport.ssl.certificate_authorities=\$CERTS_DIR/ca/ca.crt
- xpack.security.transport.ssl.certificate=\$CERTS_DIR/es01/es01.crt
- xpack.security.transport.ssl.key=\$CERTS_DIR/es01/es01.key
labels:
co.elastic.logs/module: elasticsearch
volumes: ['data01:/usr/share/elasticsearch/data', 'certs:\$CERTS_DIR', './elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml', './temp:/temp']
restart: on-failure
ports:
- 9200:9200
healthcheck:
test: curl --cacert \$CERTS_DIR/ca/ca.crt -s https://localhost:9200 >/dev/null; if [[ \$\$? == 52 ]]; then echo 0; else echo 1; fi
interval: 30s
timeout: 10s
retries: 5
es02:
container_name: es02
image: docker.elastic.co/elasticsearch/elasticsearch:${VERSION}
environment:
- node.name=es02
- node.attr.data=hot
- node.attr.data2=warm
- node.attr.zone=zone1
- node.attr.zone2=zone2
- discovery.seed_hosts=es01,es02,es03
- cluster.initial_master_nodes=es01,es02,es03
- ELASTIC_PASSWORD=${PASSWD}
- \"ES_JAVA_OPTS=-Xms${HEAP} -Xmx${HEAP}\"
- xpack.license.self_generated.type=trial
- xpack.security.enabled=true
- xpack.security.http.ssl.enabled=true
- xpack.security.http.ssl.key=\$CERTS_DIR/es02/es02.key
- xpack.security.http.ssl.certificate_authorities=\$CERTS_DIR/ca/ca.crt
- xpack.security.http.ssl.certificate=\$CERTS_DIR/es02/es02.crt
- xpack.security.transport.ssl.enabled=true
- xpack.security.transport.ssl.verification_mode=certificate
- xpack.security.transport.ssl.certificate_authorities=\$CERTS_DIR/ca/ca.crt
- xpack.security.transport.ssl.certificate=\$CERTS_DIR/es02/es02.crt
- xpack.security.transport.ssl.key=\$CERTS_DIR/es02/es02.key
labels:
co.elastic.logs/module: elasticsearch
volumes: ['data02:/usr/share/elasticsearch/data', 'certs:\$CERTS_DIR', './elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml', './temp:/temp']
restart: on-failure
es03:
container_name: es03
image: docker.elastic.co/elasticsearch/elasticsearch:${VERSION}
environment:
- node.name=es03
- node.attr.data=warm
- node.attr.data2=cold
- node.attr.zone=zone2
- node.attr.zone2=zone3
- discovery.seed_hosts=es01,es02,es03
- cluster.initial_master_nodes=es01,es02,es03
- ELASTIC_PASSWORD=${PASSWD}
- \"ES_JAVA_OPTS=-Xms${HEAP} -Xmx${HEAP}\"
- xpack.license.self_generated.type=trial
- xpack.security.enabled=true
- xpack.security.http.ssl.enabled=true
- xpack.security.http.ssl.key=\$CERTS_DIR/es03/es03.key
- xpack.security.http.ssl.certificate_authorities=\$CERTS_DIR/ca/ca.crt
- xpack.security.http.ssl.certificate=\$CERTS_DIR/es03/es03.crt
- xpack.security.transport.ssl.enabled=true
- xpack.security.transport.ssl.verification_mode=certificate
- xpack.security.transport.ssl.certificate_authorities=\$CERTS_DIR/ca/ca.crt
- xpack.security.transport.ssl.certificate=\$CERTS_DIR/es03/es03.crt
- xpack.security.transport.ssl.key=\$CERTS_DIR/es03/es03.key
labels:
co.elastic.logs/module: elasticsearch
volumes: ['data03:/usr/share/elasticsearch/data', 'certs:\$CERTS_DIR', './elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml', './temp:/temp']
restart: on-failure
kibana:
container_name: kibana
image: docker.elastic.co/kibana/kibana:${VERSION}
environment:
- SERVER_NAME=kibana
- SERVER_HOST=\"0\"
- ELASTICSEARCH_HOSTS=[\"https://es01:9200\",\"https://es02:9200\",\"https://es03:9200\"]
- ELASTICSEARCH_SSL_CERTIFICATEAUTHORITIES=\$KIBANA_CERTS_DIR/ca/ca.crt
- ELASTICSEARCH_SSL_VERIFICATIONMODE=certificate
- SERVER_SSL_CERTIFICATE=\$KIBANA_CERTS_DIR/kibana/kibana.crt
- SERVER_SSL_KEY=\$KIBANA_CERTS_DIR/kibana/kibana.key
- SERVER_SSL_ENABLED=true
labels:
co.elastic.logs/module: kibana
volumes: ['./kibana.yml:/usr/share/kibana/config/kibana.yml', 'certs:\$KIBANA_CERTS_DIR', './temp:/temp']
ports:
- 5601:5601
restart: on-failure
wait_until_ready:
image: docker.elastic.co/elasticsearch/elasticsearch:${VERSION}
command: /usr/bin/true
depends_on: {\"es01\": {\"condition\": \"service_healthy\"}}
volumes: {\"data01\", \"data02\", \"data03\", \"certs\"}
"
stackcompose71="version: '2.2'
services:
es01:
container_name: es01
image: docker.elastic.co/elasticsearch/elasticsearch:${VERSION}
environment:
- node.name=es01
- node.attr.data=hot
- node.attr.data2=hot
- node.attr.zone=zone1
- node.attr.zone2=zone1
- discovery.seed_hosts=es01,es02,es03
- cluster.initial_master_nodes=es01,es02,es03
- ELASTIC_PASSWORD=${PASSWD}
- \"ES_JAVA_OPTS=-Xms${HEAP} -Xmx${HEAP}\"
- xpack.license.self_generated.type=trial
- xpack.security.enabled=true
- xpack.security.http.ssl.enabled=true
- xpack.security.http.ssl.key=\$CERTS_DIR/es01/es01.key
- xpack.security.http.ssl.certificate_authorities=\$CERTS_DIR/ca/ca.crt
- xpack.security.http.ssl.certificate=\$CERTS_DIR/es01/es01.crt
- xpack.security.transport.ssl.enabled=true
- xpack.security.transport.ssl.verification_mode=certificate
- xpack.security.transport.ssl.certificate_authorities=\$CERTS_DIR/ca/ca.crt
- xpack.security.transport.ssl.certificate=\$CERTS_DIR/es01/es01.crt
- xpack.security.transport.ssl.key=\$CERTS_DIR/es01/es01.key
labels:
co.elastic.logs/module: elasticsearch
volumes: ['data01:/usr/share/elasticsearch/data', './certs:\$CERTS_DIR', './elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml', './temp:/temp']
restart: on-failure
ports:
- 9200:9200
healthcheck:
test: curl --cacert \$CERTS_DIR/ca/ca.crt -s https://localhost:9200 >/dev/null; if [[ \$\$? == 52 ]]; then echo 0; else echo 1; fi
interval: 30s
timeout: 10s
retries: 5
es02:
container_name: es02
image: docker.elastic.co/elasticsearch/elasticsearch:${VERSION}
environment:
- node.name=es02
- node.attr.data=hot
- node.attr.data2=warm
- node.attr.zone=zone1
- node.attr.zone2=zone2
- discovery.seed_hosts=es01,es02,es03
- cluster.initial_master_nodes=es01,es02,es03
- ELASTIC_PASSWORD=${PASSWD}
- \"ES_JAVA_OPTS=-Xms${HEAP} -Xmx${HEAP}\"
- xpack.license.self_generated.type=trial
- xpack.security.enabled=true
- xpack.security.http.ssl.enabled=true
- xpack.security.http.ssl.key=\$CERTS_DIR/es02/es02.key
- xpack.security.http.ssl.certificate_authorities=\$CERTS_DIR/ca/ca.crt
- xpack.security.http.ssl.certificate=\$CERTS_DIR/es02/es02.crt
- xpack.security.transport.ssl.enabled=true
- xpack.security.transport.ssl.verification_mode=certificate
- xpack.security.transport.ssl.certificate_authorities=\$CERTS_DIR/ca/ca.crt
- xpack.security.transport.ssl.certificate=\$CERTS_DIR/es02/es02.crt
- xpack.security.transport.ssl.key=\$CERTS_DIR/es02/es02.key
labels:
co.elastic.logs/module: elasticsearch
volumes: ['data02:/usr/share/elasticsearch/data', './certs:\$CERTS_DIR', './elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml', './temp:/temp']
restart: on-failure
es03:
container_name: es03
image: docker.elastic.co/elasticsearch/elasticsearch:${VERSION}
environment:
- node.name=es03
- node.attr.data=warm
- node.attr.data2=cold
- node.attr.zone=zone2
- node.attr.zone=zone3
- discovery.seed_hosts=es01,es02,es03
- cluster.initial_master_nodes=es01,es02,es03
- ELASTIC_PASSWORD=${PASSWD}
- \"ES_JAVA_OPTS=-Xms${HEAP} -Xmx${HEAP}\"
- xpack.license.self_generated.type=trial
- xpack.security.enabled=true
- xpack.security.http.ssl.enabled=true
- xpack.security.http.ssl.key=\$CERTS_DIR/es03/es03.key
- xpack.security.http.ssl.certificate_authorities=\$CERTS_DIR/ca/ca.crt
- xpack.security.http.ssl.certificate=\$CERTS_DIR/es03/es03.crt
- xpack.security.transport.ssl.enabled=true
- xpack.security.transport.ssl.verification_mode=certificate
- xpack.security.transport.ssl.certificate_authorities=\$CERTS_DIR/ca/ca.crt
- xpack.security.transport.ssl.certificate=\$CERTS_DIR/es03/es03.crt
- xpack.security.transport.ssl.key=\$CERTS_DIR/es03/es03.key
labels:
co.elastic.logs/module: elasticsearch
volumes: ['data03:/usr/share/elasticsearch/data', './certs:\$CERTS_DIR', './elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml', './temp:/temp']
restart: on-failure
kibana:
container_name: kibana
image: docker.elastic.co/kibana/kibana:${VERSION}
environment:
- SERVER_NAME=kibana
- SERVER_HOST=\"0\"
- ELASTICSEARCH_HOSTS=[\"https://es01:9200\",\"https://es02:9200\",\"https://es03:9200\"]
- ELASTICSEARCH_SSL_CERTIFICATEAUTHORITIES=\$KIBANA_CERTS_DIR/ca/ca.crt
- ELASTICSEARCH_SSL_VERIFICATIONMODE=certificate
- SERVER_SSL_CERTIFICATE=\$KIBANA_CERTS_DIR/kibana/kibana.crt
- SERVER_SSL_KEY=\$KIBANA_CERTS_DIR/kibana/kibana.key
- SERVER_SSL_ENABLED=true
labels:
co.elastic.logs/module: kibana
volumes: ['./kibana.yml:/usr/share/kibana/config/kibana.yml', './certs:\$KIBANA_CERTS_DIR', './temp:/temp']
ports:
- 5601:5601
restart: on-failure
wait_until_ready:
image: docker.elastic.co/elasticsearch/elasticsearch:${VERSION}
command: /usr/bin/true
depends_on: {\"es01\": {\"condition\": \"service_healthy\"}}
volumes: {\"data01\", \"data02\", \"data03\", \"certs\"}
"
stackcompose6="version: '2.2'
services:
es01:
container_name: es01
image: docker.elastic.co/elasticsearch/elasticsearch:${VERSION}
environment:
- node.name=es01
- node.attr.data=hot
- node.attr.data2=hot
- node.attr.zone=zone1
- node.attr.zone2=zone1
- cluster.name=docker-cluster
- discovery.zen.minimum_master_nodes=2
- discovery.zen.ping.unicast.hosts=es01,es02,es03
- ELASTIC_PASSWORD=${PASSWD}
- \"ES_JAVA_OPTS=-Xms${HEAP} -Xmx${HEAP}\"
- xpack.license.self_generated.type=trial
- xpack.security.enabled=true
- xpack.security.http.ssl.enabled=true
- xpack.security.transport.ssl.enabled=true
- xpack.security.transport.ssl.verification_mode=certificate
- xpack.ssl.certificate_authorities=\$CERTS_DIR/ca/ca.crt
- xpack.ssl.certificate=\$CERTS_DIR/es01/es01.crt
- xpack.ssl.key=\$CERTS_DIR/es01/es01.key
labels:
co.elastic.logs/module: elasticsearch
volumes: ['data01:/usr/share/elasticsearch/data', './certs:\$CERTS_DIR', './elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml', './temp:/temp']
ports:
- 9200:9200
restart: on-failure
healthcheck:
test: curl --cacert \$CERTS_DIR/ca/ca.crt -s https://localhost:9200 >/dev/null; if [[ \$\$? == 52 ]]; then echo 0; else echo 1; fi
interval: 30s
timeout: 10s
retries: 25
es02:
container_name: es02
image: docker.elastic.co/elasticsearch/elasticsearch:${VERSION}
environment:
- node.name=es02
- node.attr.data=hot
- node.attr.data2=warm
- node.attr.zone=zone1
- node.attr.zone2=zone2
- cluster.name=docker-cluster
- discovery.zen.minimum_master_nodes=2
- ELASTIC_PASSWORD=${PASSWD}
- discovery.zen.ping.unicast.hosts=es01,es02,es03
- \"ES_JAVA_OPTS=-Xms${HEAP} -Xmx${HEAP}\"
- xpack.license.self_generated.type=trial
- xpack.security.enabled=true
- xpack.security.http.ssl.enabled=true
- xpack.security.transport.ssl.enabled=true
- xpack.security.transport.ssl.verification_mode=certificate
- xpack.ssl.certificate_authorities=\$CERTS_DIR/ca/ca.crt
- xpack.ssl.certificate=\$CERTS_DIR/es02/es02.crt
- xpack.ssl.key=\$CERTS_DIR/es02/es02.key
labels:
co.elastic.logs/module: elasticsearch
volumes: ['data02:/usr/share/elasticsearch/data', './certs:\$CERTS_DIR', './elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml', './temp:/temp']
restart: on-failure
es03:
container_name: es03
image: docker.elastic.co/elasticsearch/elasticsearch:${VERSION}
environment:
- node.name=es03
- node.attr.data=warm
- node.attr.data2=cold
- node.attr.zone=zone2
- node.attr.zone2=zone3
- cluster.name=docker-cluster
- discovery.zen.minimum_master_nodes=2
- ELASTIC_PASSWORD=${PASSWD}
- discovery.zen.ping.unicast.hosts=es01,es02,es03
- \"ES_JAVA_OPTS=-Xms${HEAP} -Xmx${HEAP}\"
- xpack.license.self_generated.type=trial
- xpack.security.enabled=true
- xpack.security.http.ssl.enabled=true
- xpack.security.transport.ssl.enabled=true
- xpack.security.transport.ssl.verification_mode=certificate
- xpack.ssl.certificate_authorities=\$CERTS_DIR/ca/ca.crt
- xpack.ssl.certificate=\$CERTS_DIR/es03/es03.crt
- xpack.ssl.key=\$CERTS_DIR/es03/es03.key
labels:
co.elastic.logs/module: elasticsearch
volumes: ['data03:/usr/share/elasticsearch/data', './certs:\$CERTS_DIR', './elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml', './temp:/temp']
restart: on-failure
wait_until_ready:
image: docker.elastic.co/elasticsearch/elasticsearch:${VERSION}
command: /usr/bin/true
depends_on: {\"es01\": {\"condition\": \"service_healthy\"}}
kibana:
container_name: kibana
image: docker.elastic.co/kibana/kibana:${VERSION}
environment:
- SERVER_NAME=kibana
- SERVER_HOST=\"0\"
- ELASTICSEARCH_HOSTS=[\"https://es01:9200\",\"https://es02:9200\",\"https://es03:9200\"]
- ELASTICSEARCH_SSL_CERTIFICATEAUTHORITIES=\$KIBANA_CERTS_DIR/ca/ca.crt
- ELASTICSEARCH_SSL_VERIFICATIONMODE=certificate
- SERVER_SSL_CERTIFICATE=\$KIBANA_CERTS_DIR/kibana/kibana.crt
- SERVER_SSL_KEY=\$KIBANA_CERTS_DIR/kibana/kibana.key
- SERVER_SSL_ENABLED=true
labels:
co.elastic.logs/module: kibana
volumes: ['./kibana.yml:/usr/share/kibana/config/kibana.yml', './certs:\$KIBANA_CERTS_DIR', './temp:/temp']
ports:
- 5601:5601
restart: on-failure
volumes: {\"data01\", \"data02\", \"data03\" , \"certs\"}
"
if [ ${MAJOR} = "7" ] && [ ${MINOR} -ge "2" ]; then
echo "${stackcomposecurrent}" > stack-compose.yml
elif [ ${MAJOR} = "7" ] && [ ${MINOR} -le "1" ]; then
echo "${stackcompose71}" > stack-compose.yml
else
echo "${stackcompose6}" > stack-compose.yml
if [ ${MAJOR} = "6" ] && [ ${MINOR} -le "5" ]; then
if [ "`uname -s`" != "Darwin" ]; then
sed -i 's/ELASTICSEARCH_HOSTS.*/ELASTICSEARCH_URL=https:\/\/es01:9200/g' stack-compose.yml
else
sed -i '' -E 's/ELASTICSEARCH_HOST.*/ELASTICSEARCH_URL=https:\/\/es01:9200/g' stack-compose.yml
fi
fi
fi
echo "${green}[DEBUG]${reset} Created stack-compose.yml for ${VERSION}"
# create certificates
echo "${green}[DEBUG]${reset} Create certificates"
docker-compose -f create-certs.yml run --rm create_certs
# start cluster
echo "${green}[DEBUG]${reset} Starting our deployment"
docker-compose -f stack-compose.yml up -d
# wait for cluster to be healthy
checkhealth
# setup passwords
echo "${green}[DEBUG]${reset} Setting passwords and storing it in ${PWD}/notes"
if [ ${MAJOR} = "7" ]; then
if [ ${MINOR} -ge "6" ]; then
docker exec es01 /bin/bash -c "bin/elasticsearch-setup-passwords auto --batch \
--url https://localhost:9200" | tee -a notes
else
docker exec es01 /bin/bash -c "bin/elasticsearch-setup-passwords auto --batch \
-Expack.security.http.ssl.certificate=certificates/es01/es01.crt \
-Expack.security.http.ssl.certificate_authorities=certificates/ca/ca.crt \
-Expack.security.http.ssl.key=certificates/es01/es01.key \
--url https://localhost:9200" | tee -a notes
fi
elif [ ${MAJOR} = "6" ]; then
docker exec es01 /bin/bash -c "bin/elasticsearch-setup-passwords auto --batch \
-Expack.security.http.ssl.certificate_authorities=certificates/ca/ca.crt \
--url https://localhost:9200" | tee -a notes
fi
# Add patch stuff here for specific versions and restart es* containers
##
# if [ $(checkversion $VERSION) -ge $(checkversion "7.2.0") ]; then
#
# docker restart es01 es02 es03
# fi
# grab the new elastic password
grabpasswd
# generate kibana encryption key
ENCRYPTION_KEY=`openssl rand -base64 40 | tr -d "=+/" | cut -c1-32`
# create kibana.yml
if [ $(checkversion $VERSION) -lt $(checkversion "7.7.0") ]; then
cat > kibana.yml<<EOF
elasticsearch.username: "elastic"
elasticsearch.password: "${PASSWD}"
xpack.security.encryptionKey: "${ENCRYPTION_KEY}"
xpack.reporting.encryptionKey: "${ENCRYPTION_KEY}"
EOF
else
cat > kibana.yml<<EOF
elasticsearch.username: "elastic"
elasticsearch.password: "${PASSWD}"
xpack.security.encryptionKey: "${ENCRYPTION_KEY}"
xpack.reporting.encryptionKey: "${ENCRYPTION_KEY}"
xpack.encryptedSavedObjects.encryptionKey: "${ENCRYPTION_KEY}"
EOF
fi
echo "${green}[DEBUG]${reset} kibana.yml re-generated with new password and encryption keys"
# restart kibana
docker restart kibana >/dev/null 2>&1
echo "${green}[DEBUG]${reset} Restarted kibana to pick up the new elastic password"
# copy the certificate authority into the homedir for the project
if [ $(checkversion $VERSION) -ge $(checkversion "7.2.0") ]; then
docker exec es01 /bin/bash -c "cp /usr/share/elasticsearch/config/certificates/ca/ca.* /temp/"
mv ${WORKDIR}/temp/ca.* ${WORKDIR}/
else
cp ${WORKDIR}/certs/ca/ca.* ${WORKDIR}/
fi
echo "${green}[DEBUG]${reset} Copied the certificate authority into ${WORKDIR}"
echo "${green}[DEBUG]${reset} Complete! - stack deployed. ${VERSION} "
echo ""
# End of stack function
}
###############################################################################################################
monitor() {
# check to make sure that ES is 6.6 or greater
if [ $(checkversion $VERSION) -lt $(checkversion "6.5.0") ]; then
echo "${red}[DEBUG]${reset} metricbeats collections started with 6.5+. Please use legacy collections method"
help
return
else
echo "${green}********** Deploying metricbeat collections monitoring **********${reset}"
fi
# check to see if ${WORKDIR} exits
if [ ! -d ${WORKDIR} ]; then
echo "${red}[DEBUG]${reset} Deployment does not exist. Starting deployment first"
stack ${VERSION}
else
cd ${WORKDIR}
fi
# check to see if monitor-compose.yml already exists.
if [ -f "monitor-compose.yml" ]; then
echo "${red}[DEBUG]${reset} monitor-compose.yml already exists. Exiting."
return
fi
# check to see if version match
OLDVERSION="`cat VERSION`"
if [ "${OLDVERSION}" != "${VERSION}" ]; then
echo "${red}[DEBUG]${reset} Version installed is ${OLDVERSION} however you requested monitoring for ${VERSION}"
return
fi
# grab the elastic password
grabpasswd
checkhealth
# add MB_CERTS_DIR & FB_CERTS to .env
cat >> .env<<EOF
MB_CERTS_DIR=/usr/share/metricbeat/certificates
FB_CERTS_DIR=/usr/share/filebeat/certificates
EOF
echo "${green}[DEBUG]${reset} Adding MB_CERTS_DIR & FB_CERTS_DIR to .env"
# pull images
pullimage "docker.elastic.co/beats/metricbeat:${VERSION}"
pullimage "docker.elastic.co/beats/filebeat:${VERSION}"
# add xpack.monitoring.kibana.collection.enabled: false to kibana.yml and restart kibana
echo "xpack.monitoring.kibana.collection.enabled: false" >> kibana.yml
docker restart kibana >/dev/null 2>&1
if [ $? -ne 0 ]; then
echo "${red}[DEBUG]${reset} Unable to restart kibana"
exit
else
echo "${green}[DEBUG]${reset} kibana restarted after adding xpack.monitoring.kibana.collection.enabled: false"
sleep 2
fi
common7="# common
http.enabled: true
http.port: 5066
http.host: 0.0.0.0
processors:
- add_cloud_metadata: ~
- add_docker_metadata: ~
monitoring.enabled: false
output.elasticsearch:
hosts: [\"https://es01:9200\", \"https://es02:9200\", \"https://es03:9200\"]
username: \"elastic\"
password: "\"${PASSWD}\""
ssl.enabled: true
ssl.verification_mode: full