-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Expand file tree
/
Copy pathinstall_influxdb.sh
More file actions
executable file
·1629 lines (1408 loc) · 60.8 KB
/
install_influxdb.sh
File metadata and controls
executable file
·1629 lines (1408 loc) · 60.8 KB
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
#!/bin/sh -e
################################################################################
# InfluxDB 3 Installation Script
################################################################################
#
# PURPOSE:
# Automated setup script for InfluxDB 3 with intelligent installation method
# selection and environment-aware configuration management. This script is
# designed to be run for quick installation and non-production evaluation.
#
# INSTALLATION METHODS:
# 1. Docker Compose: Complete stack (InfluxDB + Explorer UI)
# - Installs latest Docker images
# - Auto-creates docker-compose.yml with proper networking
# - Manages Explorer configuration and session secrets
# - Supports upgrades of existing Docker installations
#
# 2. Binary Installation: Direct binary download with optional startup
# - Downloads precompiled binaries for supported architectures
# - Extracts to user home directory (~/.influxdb)
# - Auto-configures shell PATH environment
# - Offers Quick Start, Custom, or Install-Only modes
#
# DIRECTORY STRUCTURE:
# Shared data directory (both installation methods):
# ~/.influxdb/
# ├── data/ (Database files - shared between Docker & Binary)
# └── plugins/ (Custom plugins - shared between Docker & Binary)
#
# Docker Compose specific:
# ~/.influxdb/docker/
# ├── docker-compose.yml (Docker service definitions)
# ├── .env (Environment variables)
# └── explorer/
# ├── db/ (Explorer database)
# └── config/ (Explorer configuration)
#
# Binary specific:
# ~/.influxdb/
# ├── influxdb3 (Main binary)
# └── logs/ (Timestamped server logs)
#
# REQUIREMENTS/PREREQUISITES:
# Core Requirements:
# - POSIX-compliant shell (sh or bash)
# - curl (for downloading binaries and verification)
# - tar (for extracting archives)
# - shasum (macOS) or sha256sum (Linux) for SHA256 verification
#
# Docker Compose Method:
# - Docker engine must be running and responding
# - docker and docker compose commands available
#
# Binary Method:
# - Supported OS: macOS (ARM64 only), Linux (x86_64 or ARM64)
# - Port availability (default 8181, auto-adjusts if in use)
#
# EXISTING INSTALLATION HANDLING:
# Docker Compose:
# - Detects existing docker-compose.yml at ~/.influxdb/docker/
# - Automatically upgrades in-place when detected
# - Extracts and reuses existing port configuration from .env
# - Pulls latest images and restarts containers with health checks
# - Preserves all data in bind-mounted directories
#
# Binary:
# - Overwrites any existing binary at ~/.influxdb/influxdb3
# - Preserves data directory (~/.influxdb/data) automatically
# - User can run script repeatedly to upgrade to latest version
#
# CONFIGURATION OPTIONS:
# Command Line Arguments:
# [enterprise] Install Enterprise edition (default: Core)
# --version VERSION Specify InfluxDB version (default: 3.8.0)
#
# Interactive Prompts (Binary Installation):
# Installation Type: Docker Compose or Binary
# Startup Mode: Quick Start, Custom, or Skip
# Node ID: Identifier for this server instance
# Cluster ID: (Enterprise only) Cluster identifier
# Storage Type: File, S3, Azure, GCS, or Memory
# Cloud Credentials: (If object storage selected)
# License Type: (Enterprise only) Trial or Home
# License Email: (Enterprise only) Email for activation
#
# Docker Compose Specific:
# Port Selection: Automatic via find_next_available_port()
# Session Secret: Generated via openssl or date hash
# InfluxDB Port: Default 8181 (mapped to container 8181)
# Explorer Port: Default 8888 (mapped to container 80)
# Container Restart: unless-stopped policy
#
# EXIT POINTS AND CONDITIONS:
# Successful Exits (exit 0):
# - Docker Compose: After successful deployment with access points shown
# - Docker Upgrade: After successful image pull and container restart
# - Binary: After showing "Next Steps" information
# - Skip Startup: After installation without starting service
#
# Error Exits (exit 1):
# - Unsupported OS/Architecture (Intel Mac, Windows, etc.)
# - Docker not running or unavailable (Docker Compose path)
# - Failed image pulls or docker compose commands
# - Failed binary download, signature verification, or extraction
# - Invalid SHA256 checksum on downloaded binary
# - Container startup timeout (>60 seconds for InfluxDB/Explorer)
# - Port allocation failure or port range exhausted
#
# SPECIAL BEHAVIORS:
# Binary Download:
# - URL format: https://dl.influxdata.com/influxdb/releases/
# influxdb3-{edition_tag}-{version}_{artifact}.tar.gz
# - Downloads corresponding .sha256 file for verification
# - Validates checksums before extraction
# - Automatically adds installation path to shell rc file
#
# Docker Compose:
# - Creates internal network (influxdb-network) for service communication
# - Configures Explorer to communicate via container name internally
# - Opens Explorer UI in default browser upon successful startup
# - Filters verbose docker compose output for cleaner display
#
# Health Checking:
# - InfluxDB (Docker): Waits for "startup time:" in container logs
# - Explorer: Polls /api/health endpoint for "ok/status/healthy"
#
# SHELL EXECUTION CONTEXT:
# - Runs with `sh -e` (error exit on command failure)
# - Uses POSIX-compatible syntax for maximum portability
# - Disables shellcheck SC2059 for printf variable interpolation
# - Exports INFLUXDB3_SERVE_INVOCATION_METHOD for telemetry tracking
#
################################################################################
# ==============================================================================
# SECTION 1: SCRIPT CONFIGURATION
# ==============================================================================
export LC_ALL=C
readonly GREEN='\033[0;32m'
readonly BLUE='\033[0;34m'
readonly BOLD='\033[1m'
readonly BOLDGREEN='\033[1;32m'
readonly DIM='\033[2m'
readonly YELLOW='\033[1;33m'
readonly RED='\033[0;31m'
readonly NC='\033[0m' # No Color
# No diagnostics for: 'printf "...${FOO}"'
# shellcheck disable=SC2059
# Docker Compose Constants
INFLUXDB_PORT=8181 # Can be changed if port is in use
EXPLORER_PORT=8888 # Can be changed if port is in use
readonly EXPLORER_IMAGE="influxdata/influxdb3-ui"
readonly MANUAL_TOKEN_MSG="MANUAL_TOKEN_CREATION_REQUIRED"
ARCHITECTURE=$(uname -m)
ARTIFACT=""
OS=""
INSTALL_LOC=~/.influxdb
BINARY_NAME="influxdb3"
PORT=8181
# Set the default (latest) version here. Users may specify a version using the
# --version arg (handled below)
INFLUXDB_VERSION_FLAG_SET="0"
INFLUXDB_OSS_VERSION="3.9.1"
INFLUXDB_ENT_VERSION="3.9.1"
EDITION="Core"
EDITION_TAG="core"
INFLUXDB_VERSION="${INFLUXDB_OSS_VERSION}"
# ==============================================================================
# SECTION 2: COMMAND LINE ARGUMENT PARSING
# ==============================================================================
while [ $# -gt 0 ]; do
case "$1" in
--version)
INFLUXDB_VERSION="$2"
INFLUXDB_VERSION_FLAG_SET=1
shift 2
;;
enterprise)
EDITION="Enterprise"
EDITION_TAG="enterprise"
if [ "${INFLUXDB_VERSION_FLAG_SET}" == "0" ]; then
INFLUXDB_VERSION="${INFLUXDB_ENT_VERSION}"
fi
shift 1
;;
*)
printf "Usage: %s [enterprise] [--version VERSION]\n" "$0"
printf " enterprise: Install the Enterprise edition (optional)\n"
printf " --version VERSION: Specify InfluxDB version (default: %s)\n" "$INFLUXDB_VERSION"
exit 1
;;
esac
done
# ==============================================================================
# SECTION 3: SYSTEM DETECTION
# ==============================================================================
case "$(uname -s)" in
Linux*) OS="Linux";;
Darwin*) OS="Darwin";;
*) OS="UNKNOWN";;
esac
if [ "${OS}" = "Linux" ]; then
# ldd is a shell script but on some systems (eg Ubuntu) security hardening
# prevents it from running when invoked directly. Since we only want to
# use '--verbose', find the path to ldd, then invoke under sh to bypass ldd
# hardening.
if [ "${ARCHITECTURE}" = "x86_64" ] || [ "${ARCHITECTURE}" = "amd64" ]; then
ARTIFACT="linux_amd64"
elif [ "${ARCHITECTURE}" = "aarch64" ] || [ "${ARCHITECTURE}" = "arm64" ]; then
ARTIFACT="linux_arm64"
fi
elif [ "${OS}" = "Darwin" ]; then
if [ "${ARCHITECTURE}" = "x86_64" ]; then
printf "Intel Mac support is coming soon!\n"
printf "Visit our public Discord at \033[4;94mhttps://discord.gg/az4jPm8x${NC} for additional guidance.\n"
printf "View alternative binaries on our Getting Started guide at \033[4;94mhttps://docs.influxdata.com/influxdb3/${EDITION_TAG}/${NC}.\n"
exit 1
else
ARTIFACT="darwin_arm64"
fi
fi
# Exit if unsupported system
[ -n "${ARTIFACT}" ] || {
printf "Unfortunately this script doesn't support your '${OS}' | '${ARCHITECTURE}' setup, or was unable to identify it correctly.\n"
printf "Visit our public Discord at \033[4;94mhttps://discord.gg/az4jPm8x${NC} for additional guidance.\n"
printf "View alternative binaries on our Getting Started guide at \033[4;94mhttps://docs.influxdata.com/influxdb3/${EDITION_TAG}/${NC}.\n"
exit 1
}
URL="https://dl.influxdata.com/influxdb/releases/influxdb3-${EDITION_TAG}-${INFLUXDB_VERSION}_${ARTIFACT}.tar.gz"
# ==============================================================================
# SECTION 4: GENERAL UTILITY FUNCTIONS
# ==============================================================================
# Cross-cutting utilities used by multiple installation methods
# --- Port Management ---
# Find next available port starting from given port
# Parameters: $1 - starting_port (e.g., 8181)
# Returns: Available port number (echoes to stdout)
# Exits: 1 if port range exhausted (>32767)
find_next_available_port() {
current_port="$1"
lsof_exec=$(command -v lsof)
if [ -z "$lsof_exec" ]; then
echo "$current_port"
return 0
fi
while "$lsof_exec" -i:"$current_port" -t >/dev/null 2>&1; do
printf "├─${DIM} Port %s is in use. Finding new port.${NC}\n" "$current_port" >&2
current_port=$((current_port + 1))
if [ "$current_port" -gt 32767 ]; then
printf "└─${RED} Could not find an available port. Aborting.${NC}\n" >&2
exit 1
fi
done
echo "$current_port"
}
# --- Browser Integration ---
# Utility function to open URL in browser
open_browser_url() {
URL="$1"
if command -v open >/dev/null 2>&1; then
open "$URL" >/dev/null 2>&1 &
elif command -v xdg-open >/dev/null 2>&1; then
xdg-open "$URL" >/dev/null 2>&1 &
elif command -v start >/dev/null 2>&1; then
start "$URL" >/dev/null 2>&1 &
fi
}
# --- Security Utilities ---
# Utility function to generate session secret
generate_session_secret() {
if [ "${OS}" = "Darwin" ]; then
head -c 64 /dev/urandom | shasum -a 256 | cut -d ' ' -f 1
else
head -c 64 /dev/urandom | sha256sum | cut -d ' ' -f 1
fi
}
# ==============================================================================
# SECTION 5: DOCKER COMPOSE UTILITIES
# ==============================================================================
# Docker-specific operations and helpers
# --- Docker Validation ---
# Function to check if Docker is available and running
check_docker() {
if ! command -v docker >/dev/null 2>&1; then
return 1
fi
if ! docker info >/dev/null 2>&1; then
return 1
fi
if ! docker compose version >/dev/null 2>&1; then
return 1
fi
return 0
}
# --- Image Management ---
# Pull Docker Compose image with configurable error handling
# Parameters:
# $1 - service_name: Docker Compose service name to pull
# $2 - display_name: Human-readable name for progress messages
# $3 - is_fatal: "true" if failure should abort, "false" to continue (default: false)
# Returns: 0 on success or non-fatal failure, 1 on fatal failure
pull_docker_image() {
service_name="$1"
display_name="$2"
is_fatal="${3:-false}"
printf "├─ Pulling %s image..." "$display_name"
# Capture error output
PULL_OUTPUT=$(docker compose pull "$service_name" 2>&1)
PULL_EXIT_CODE=$?
if [ $PULL_EXIT_CODE -eq 0 ]; then
printf "SUCCESS\n"
return 0
else
if [ "$is_fatal" = "true" ]; then
printf "${RED}FAILED${NC}\n"
printf "└─ ${RED}Error: Failed to pull %s image${NC}\n" "$display_name"
# Display actual error with context
printf "\n${BOLD}Error details:${NC}\n"
printf "%s\n\n" "$PULL_OUTPUT"
# Provide specific troubleshooting based on error content
printf "${BOLD}Possible causes:${NC}\n"
if echo "$PULL_OUTPUT" | grep -qi "denied\|unauthorized"; then
printf " • Docker Hub authentication required or rate limited\n"
printf " • Try: docker login\n"
elif echo "$PULL_OUTPUT" | grep -qi "network\|timeout\|connection"; then
printf " • Network connectivity issue\n"
printf " • Check your internet connection\n"
elif echo "$PULL_OUTPUT" | grep -qi "daemon"; then
printf " • Docker daemon may not be responding\n"
printf " • Try: docker info\n"
elif echo "$PULL_OUTPUT" | grep -qi "yaml\|control characters"; then
printf " • Invalid YAML syntax in docker-compose.yml\n"
printf " • Inspect file: cat %s/docker-compose.yml\n" "$DOCKER_DIR"
else
printf " • Check Docker daemon status: docker info\n"
printf " • Check internet connection\n"
printf " • Check Docker Hub access\n"
fi
printf "\n"
return 1
else
printf "${YELLOW}FAILED${NC}\n"
printf "│ ${YELLOW}Warning: %s will not be available${NC}\n" "$display_name"
printf "│ You can run this script again later to install it\n"
return 0
fi
fi
}
# --- Output Formatting ---
# Utility function to filter Docker Compose output
filter_docker_output() {
grep -v "version.*obsolete" | \
grep -v "Creating$" | \
grep -v "Created$" | \
grep -v "Starting$" | \
grep -v "Started$" | \
grep -v "Running$" \
|| true
}
# --- Filesystem Setup ---
# Utility function to create docker directories with permissions
create_docker_directories() {
DOCKER_DIR="$1"
# Create shared data directories (used by both Docker and binary)
mkdir -p "$HOME/.influxdb/data"
mkdir -p "$HOME/.influxdb/plugins"
# Create Docker-specific directories
mkdir -p "$DOCKER_DIR/explorer/db"
mkdir -p "$DOCKER_DIR/explorer/config"
chmod 700 "$DOCKER_DIR/explorer/db" 2>/dev/null || true
chmod 750 "$DOCKER_DIR/explorer/config" 2>/dev/null || true
}
# --- Health Checks ---
# Utility function to wait for container to be ready
wait_for_container_ready() {
CONTAINER_NAME="$1"
READY_MESSAGE="$2"
TIMEOUT="${3:-60}"
EDITION_TYPE="${4:-}"
LICENSE_TYPE="${5:-}"
printf "├─ Starting InfluxDB"
ELAPSED=0
EMAIL_MESSAGE_SHOWN=false
while [ $ELAPSED -lt $TIMEOUT ]; do
if docker logs "$CONTAINER_NAME" 2>&1 | grep -q "$READY_MESSAGE"; then
printf "${NC}\n"
return 0
fi
if ! docker ps | grep -q "$CONTAINER_NAME"; then
printf "${NC}\n"
printf "├─${RED} Error: InfluxDB container stopped unexpectedly${NC}\n"
docker logs --tail 20 "$CONTAINER_NAME"
return 1
fi
if [ $ELAPSED -eq $((TIMEOUT - 1)) ]; then
printf "${NC}\n"
printf "├─${RED} Error: InfluxDB failed to start within ${TIMEOUT} seconds${NC}\n"
return 1
fi
# Show email verification message after 4 seconds for Enterprise with new license
if [ "$EDITION_TYPE" = "enterprise" ] && [ -n "$LICENSE_TYPE" ] && \
[ $ELAPSED -ge 4 ] && [ "$EMAIL_MESSAGE_SHOWN" = "false" ]; then
printf "${NC}\n"
printf "├─${YELLOW} License activation requires email verification${NC}\n"
printf "├─${BOLD} → Check your inbox and verify your email address${NC}\n"
printf "├─ Continuing startup"
EMAIL_MESSAGE_SHOWN=true
fi
printf "."
sleep 2
ELAPSED=$((ELAPSED + 2))
done
}
# Utility function to wait for Explorer to be fully ready
wait_for_explorer_ready() {
TIMEOUT="${1:-60}"
printf "└─ Starting Explorer"
ELAPSED=0
while [ $ELAPSED -lt $TIMEOUT ]; do
if curl -s http://localhost:$EXPLORER_PORT >/dev/null 2>&1; then
API_RESPONSE=$(curl -s http://localhost:$EXPLORER_PORT/api/health 2>&1)
if echo "$API_RESPONSE" | grep -q "ok\|status\|healthy" 2>/dev/null; then
printf "${NC}\n"
return 0
fi
fi
printf "."
sleep 2
ELAPSED=$((ELAPSED + 2))
done
printf "${NC}\n"
return 1
}
# --- Token Management ---
# Utility function to create operator token via API
create_operator_token() {
CONTAINER_NAME="$1"
# Try API with retries
MAX_RETRIES=3
RETRY=0
TOKEN=""
while [ $RETRY -lt $MAX_RETRIES ] && [ -z "$TOKEN" ]; do
TOKEN_RESPONSE=$(curl -s -w "\n%{http_code}" -m 5 -X POST http://localhost:$INFLUXDB_PORT/api/v3/configure/token/admin 2>&1)
# Extract HTTP status code (last line)
HTTP_CODE=$(echo "$TOKEN_RESPONSE" | tail -n1)
# Extract response body (all but last line)
RESPONSE_BODY=$(echo "$TOKEN_RESPONSE" | sed '$d')
# Check for 409 conflict
if [ "$HTTP_CODE" = "409" ]; then
echo "TOKEN_ALREADY_EXISTS"
return 2
fi
# Try to extract token from response
TOKEN=$(echo "$RESPONSE_BODY" | grep -o '"token":"[^"]*"' | cut -d'"' -f4)
if [ -z "$TOKEN" ] && [ $RETRY -lt $((MAX_RETRIES - 1)) ]; then
sleep 2
RETRY=$((RETRY + 1))
else
break
fi
done
# Return token or manual creation message
if [ -n "$TOKEN" ]; then
echo "$TOKEN"
return 0
else
echo "$MANUAL_TOKEN_MSG"
return 1
fi
}
# --- Configuration Generation ---
# Function to generate Docker Compose YAML
generate_docker_compose_yaml() {
EDITION_TYPE="$1" # "core" or "enterprise"
SESSION_SECRET="$2"
LICENSE_EMAIL="$3"
DOCKER_DIR="$4"
USER_UID=$(id -u)
USER_GID=$(id -g)
# Determine edition-specific values
if [ "$EDITION_TYPE" = "enterprise" ]; then
SERVICE_NAME="influxdb3-enterprise"
IMAGE_NAME="influxdb:3-enterprise"
CLUSTER_ARG=" - --cluster-id=cluster0"
ENV_SECTION=" environment:
- INFLUXDB3_ENTERPRISE_LICENSE_EMAIL=\${INFLUXDB_EMAIL}"
else
SERVICE_NAME="influxdb3-core"
IMAGE_NAME="influxdb:3-core"
CLUSTER_ARG=""
ENV_SECTION=""
fi
cat > "$DOCKER_DIR/docker-compose.yml" << COMPOSE_EOF
services:
${SERVICE_NAME}:
image: ${IMAGE_NAME}
container_name: ${SERVICE_NAME}
user: "${USER_UID}:${USER_GID}"
ports:
- "${INFLUXDB_PORT}:8181"
command:
- influxdb3
- serve
- --node-id=node0${CLUSTER_ARG:+
${CLUSTER_ARG}}
- --object-store=file
- --data-dir=/var/lib/influxdb3/data
- --plugin-dir=/var/lib/influxdb3/plugins${ENV_SECTION:+
${ENV_SECTION}}
volumes:
- ~/.influxdb/data:/var/lib/influxdb3/data
- ~/.influxdb/plugins:/var/lib/influxdb3/plugins
restart: unless-stopped
networks:
- influxdb-network
influxdb3-explorer:
image: ${EXPLORER_IMAGE}
container_name: influxdb3-explorer
command: ["--mode=admin"]
ports:
- "${EXPLORER_PORT}:80"
volumes:
- ./explorer/db:/db:rw
- ./explorer/config:/app-root/config:ro
environment:
- SESSION_SECRET_KEY=\${SESSION_SECRET}
restart: unless-stopped
depends_on:
- ${SERVICE_NAME}
networks:
- influxdb-network
networks:
influxdb-network:
driver: bridge
COMPOSE_EOF
# Create .env file
if [ "$EDITION_TYPE" = "enterprise" ]; then
cat > "$DOCKER_DIR/.env" << ENV_EOF
INFLUXDB_EMAIL=${LICENSE_EMAIL}
SESSION_SECRET=${SESSION_SECRET}
ENV_EOF
else
cat > "$DOCKER_DIR/.env" << ENV_EOF
SESSION_SECRET=${SESSION_SECRET}
ENV_EOF
fi
# Set restrictive permissions on .env file
chmod 600 "$DOCKER_DIR/.env"
}
# Function to configure Explorer via file
configure_explorer_via_file() {
TOKEN="$1"
INFLUXDB_URL="$2"
SERVER_NAME="$3"
DOCKER_DIR="$4"
printf "├─ Configuring Explorer...\n"
# Ensure config directory exists with correct permissions
mkdir -p "$DOCKER_DIR/explorer/config"
chmod 755 "$DOCKER_DIR/explorer/config"
# Create the config.json file
cat > "$DOCKER_DIR/explorer/config/config.json" <<EOF
{
"DEFAULT_INFLUX_SERVER": "$INFLUXDB_URL",
"DEFAULT_API_TOKEN": "$TOKEN",
"DEFAULT_SERVER_NAME": "$SERVER_NAME"
}
EOF
chmod 640 "$DOCKER_DIR/explorer/config/config.json"
return 0
}
# Utility function to extract existing token from Explorer config
extract_token_from_explorer_config() {
DOCKER_DIR="$1"
CONFIG_FILE="$DOCKER_DIR/explorer/config/config.json"
if [ -f "$CONFIG_FILE" ]; then
TOKEN=$(grep '"DEFAULT_API_TOKEN"' "$CONFIG_FILE" | cut -d'"' -f4)
if [ -n "$TOKEN" ] && [ "$TOKEN" != "null" ]; then
echo "$TOKEN"
return 0
fi
fi
echo ""
return 1
}
# ==============================================================================
# SECTION 6: DOCKER COMPOSE ORCHESTRATION
# ==============================================================================
# High-level Docker Compose setup workflow
# Unified function to setup Docker Compose (both Core and Enterprise)
setup_docker_compose() {
EDITION_TYPE="$1" # "core" or "enterprise"
DOCKER_DIR="${2:-$HOME/.influxdb/docker}"
LICENSE_EMAIL="$3"
LICENSE_TYPE="$4"
# Set edition-specific values
if [ "$EDITION_TYPE" = "enterprise" ]; then
EDITION_NAME="Enterprise"
CONTAINER_NAME="influxdb3-enterprise"
SERVER_NAME="InfluxDB 3 Enterprise"
else
EDITION_NAME="Core"
CONTAINER_NAME="influxdb3-core"
SERVER_NAME="InfluxDB 3 Core"
fi
printf "\n${BOLD}Setting up InfluxDB 3 ${EDITION_NAME}${NC}\n"
# Verify Docker is running before doing any setup work (silent check)
if ! check_docker; then
printf "${RED}Error: Docker is not running${NC}\n\n"
printf "${BOLD}Docker Connection Failed${NC}\n"
printf "Docker is not responding. Please ensure Docker Desktop is running.\n\n"
printf "${BOLD}How to fix:${NC}\n"
printf " • Open Docker Desktop and wait for it to start\n"
printf " • Check Docker Desktop status in your system tray\n"
printf " • Run ${BOLD}docker info${NC} to verify Docker is responding\n"
printf " • Restart Docker Desktop if necessary, then run this script again\n\n"
return 1
fi
# Enterprise-specific: Handle license prompting
if [ "$EDITION_TYPE" = "enterprise" ]; then
# Check for existing license in shared data directory
if [ -f "$HOME/.influxdb/data/cluster0/trial_or_home_license" ]; then
printf "├─${DIM} Found existing license file${NC}\n"
elif [ -z "$LICENSE_EMAIL" ]; then
# Prompt for license if not provided
printf "\n${BOLD}License Setup Required${NC}\n"
printf "1) ${GREEN}Trial${NC} ${DIM}- Full features for 30 days (up to 256 cores)${NC}\n"
printf "2) ${GREEN}Home${NC} ${DIM}- Free for non-commercial use (max 2 cores, single node)${NC}\n"
printf "\nEnter your choice (1-2): "
read -r LICENSE_CHOICE
case "${LICENSE_CHOICE:-1}" in
1) LICENSE_TYPE="trial" ;;
2) LICENSE_TYPE="home" ;;
*) LICENSE_TYPE="trial" ;;
esac
printf "Enter your email: "
read -r LICENSE_EMAIL
while [ -z "$LICENSE_EMAIL" ]; do
printf "Email is required. Enter your email: "
read -r LICENSE_EMAIL
done
fi
fi
printf "├─ Creating directories\n"
create_docker_directories "$DOCKER_DIR"
# Stop any existing containers before reconfiguring
if [ -f "$DOCKER_DIR/docker-compose.yml" ]; then
printf "├─ Stopping existing containers\n"
cd "$DOCKER_DIR"
docker compose down 2>/dev/null || true
cd - > /dev/null
fi
# Check for available ports
INFLUXDB_PORT=$(find_next_available_port "$INFLUXDB_PORT")
EXPLORER_PORT=$(find_next_available_port "$EXPLORER_PORT")
# Generate session secret
SESSION_SECRET=$(generate_session_secret)
printf "├─ Creating docker-compose.yml\n"
generate_docker_compose_yaml "$EDITION_TYPE" "$SESSION_SECRET" "$LICENSE_EMAIL" "$DOCKER_DIR"
cd "$DOCKER_DIR"
# Pull InfluxDB image
if ! pull_docker_image "$CONTAINER_NAME" "InfluxDB 3 ${EDITION_NAME}" "true"; then
return 1
fi
docker compose up -d "$CONTAINER_NAME" 2>&1 | filter_docker_output
# Wait for InfluxDB to be ready
if ! wait_for_container_ready "$CONTAINER_NAME" "startup time:" 60 "$EDITION_TYPE" "$LICENSE_TYPE"; then
return 1
fi
# Check for existing token in Explorer config, or create new one
CONFIG_FILE="$DOCKER_DIR/explorer/config/config.json"
TOKEN_IS_NEW=false
EXPLORER_DEPLOYED=false
if [ -f "$CONFIG_FILE" ]; then
printf "└─ Found existing Explorer config\n\n"
TOKEN=$(extract_token_from_explorer_config "$DOCKER_DIR")
if [ -n "$TOKEN" ]; then
TOKEN_IS_NEW=false
else
printf " ${YELLOW}Config exists but no valid token found${NC}\n"
printf " Creating new operator token\n"
TOKEN=$(create_operator_token "$CONTAINER_NAME")
TOKEN_IS_NEW=true
printf "\n"
fi
else
printf "└─ Creating operator token\n"
TOKEN=$(create_operator_token "$CONTAINER_NAME")
TOKEN_IS_NEW=true
printf "\n"
fi
# Display token BEFORE launching Explorer (only if newly created)
if [ "$TOKEN" != "$MANUAL_TOKEN_MSG" ] && [ "$TOKEN" != "TOKEN_ALREADY_EXISTS" ]; then
if [ "$TOKEN_IS_NEW" = true ]; then
printf "${BOLD}════════════════════════════════════════════════════════════${NC}\n"
printf "${BOLD}OPERATOR TOKEN: Save this token. It will not be shown again.${NC}\n"
printf "%s\n" "$TOKEN"
printf "${BOLD}════════════════════════════════════════════════════════════${NC}\n\n"
fi
# Now launch Explorer after showing the token
printf "${BOLD}Setting up InfluxDB 3 Explorer...${NC}\n"
# Pull Explorer image
pull_docker_image "influxdb3-explorer" "InfluxDB 3 Explorer" "false"
# Configure Explorer (use port 8181 for container-to-container communication)
configure_explorer_via_file "$TOKEN" "http://${CONTAINER_NAME}:8181" "$SERVER_NAME" "$DOCKER_DIR"
docker compose up -d influxdb3-explorer 2>&1 | filter_docker_output
# Wait for Explorer to be ready
if wait_for_explorer_ready 60; then
EXPLORER_DEPLOYED=true
open_browser_url "http://localhost:${EXPLORER_PORT}/system-overview"
fi
else
# Token creation failed - prepare Explorer but don't start it
printf "${BOLD}Setting up InfluxDB 3 Explorer...${NC}\n"
# Pull Explorer image
pull_docker_image "influxdb3-explorer" "InfluxDB 3 Explorer" "false"
# Configure Explorer with placeholder token
configure_explorer_via_file "YOUR_TOKEN_HERE" "http://${CONTAINER_NAME}:8181" "$SERVER_NAME" "$DOCKER_DIR"
printf "└─ Explorer prepared (manual token configuration required)\n\n"
fi
# Display success message and access points AFTER Explorer launch
if [ "$EXPLORER_DEPLOYED" = true ]; then
printf "\n${BOLDGREEN}✓ InfluxDB 3 ${EDITION_NAME} with InfluxDB 3 Explorer successfully deployed${NC}\n\n"
else
printf "\n${BOLDGREEN}✓ InfluxDB 3 ${EDITION_NAME} successfully deployed${NC}\n\n"
fi
printf "${BOLD}Access Points:${NC}\n"
if [ "$EXPLORER_DEPLOYED" = true ]; then
printf "├─ Explorer UI: ${BLUE}http://localhost:${EXPLORER_PORT}${NC}\n"
fi
printf "└─ InfluxDB API: ${BLUE}http://localhost:${INFLUXDB_PORT}${NC}\n\n"
printf "${BOLD}Storage Locations:${NC}\n"
printf "├─ InfluxDB Data: ${DIM}%s/.influxdb/data${NC}\n" "$HOME"
if [ "$EXPLORER_DEPLOYED" = true ]; then
printf "├─ InfluxDB Plugins: ${DIM}%s/.influxdb/plugins${NC}\n" "$HOME"
printf "└─ Explorer DB: ${DIM}%s/explorer/db${NC}\n\n" "$DOCKER_DIR"
else
printf "└─ InfluxDB Plugins: ${DIM}%s/.influxdb/plugins${NC}\n\n" "$HOME"
fi
printf "${BOLD}Configuration Files:${NC}\n"
printf "├─ Docker Compose: ${DIM}%s/docker-compose.yml${NC}\n" "$DOCKER_DIR"
printf "└─ Explorer Config: ${DIM}%s/explorer/config/config.json${NC}\n\n" "$DOCKER_DIR"
# Show manual setup instructions if Explorer was not deployed
if [ "$EXPLORER_DEPLOYED" = false ]; then
printf "${BOLD}To Complete InfluxDB 3 Explorer Setup:${NC}\n"
printf "1. Replace ${DIM}\"YOUR_TOKEN_HERE\"${NC} with your admin token in the Explorer config file:\n"
printf " ${DIM}%s/explorer/config/config.json${NC}\n\n" "$DOCKER_DIR"
printf "2. Start InfluxDB 3 Explorer:\n"
printf " ${DIM}cd %s && docker compose up -d influxdb3-explorer${NC}\n\n" "$DOCKER_DIR"
printf "3. Open your browser to http://localhost:${EXPLORER_PORT}\n\n"
fi
return 0
}
# ==============================================================================
# SECTION 7: BINARY INSTALLATION UTILITIES
# ==============================================================================
# Low-level binary installation helpers
# --- Quick Start Configuration ---
# Function to set up Quick Start defaults for both Core and Enterprise
setup_quick_start_defaults() {
edition="${1:-core}"
NODE_ID="node0"
STORAGE_TYPE="File Storage"
STORAGE_PATH="$HOME/.influxdb/data"
PLUGIN_PATH="$HOME/.influxdb/plugins"
STORAGE_FLAGS="--object-store=file --data-dir ${STORAGE_PATH} --plugin-dir ${PLUGIN_PATH}"
STORAGE_FLAGS_ECHO="--object-store=file --data-dir ${STORAGE_PATH} --plugin-dir ${PLUGIN_PATH}"
START_SERVICE="y" # Always set for Quick Start
# Enterprise-specific settings
if [ "$edition" = "enterprise" ]; then
CLUSTER_ID="cluster0"
LICENSE_FILE_PATH="${STORAGE_PATH}/${CLUSTER_ID}/trial_or_home_license"
fi
# Create directories
mkdir -p "${STORAGE_PATH}"
mkdir -p "${PLUGIN_PATH}"
}
# --- Cloud Storage Configuration ---
# Function to configure AWS S3 storage
configure_aws_s3_storage() {
printf "\n"
printf "${BOLD}AWS S3 Configuration${NC}\n"
printf "├─ Enter AWS Access Key ID: "
read -r AWS_KEY
printf "├─ Enter AWS Secret Access Key: "
stty -echo
read -r AWS_SECRET
stty echo
printf "\n"
printf "├─ Enter S3 Bucket: "
read -r AWS_BUCKET
printf "└─ Enter AWS Region (default: us-east-1): "
read -r AWS_REGION
AWS_REGION=${AWS_REGION:-"us-east-1"}
STORAGE_FLAGS="--object-store=s3 --bucket=${AWS_BUCKET}"
if [ -n "$AWS_REGION" ]; then
STORAGE_FLAGS="$STORAGE_FLAGS --aws-default-region=${AWS_REGION}"
fi
STORAGE_FLAGS="$STORAGE_FLAGS --aws-access-key-id=${AWS_KEY}"
STORAGE_FLAGS_ECHO="$STORAGE_FLAGS --aws-secret-access-key=..."
STORAGE_FLAGS="$STORAGE_FLAGS --aws-secret-access-key=${AWS_SECRET}"
}
# Function to configure Azure storage
configure_azure_storage() {
printf "\n"
printf "${BOLD}Azure Storage Configuration${NC}\n"
printf "├─ Enter Storage Account Name: "
read -r AZURE_ACCOUNT
printf "└─ Enter Storage Access Key: "
stty -echo
read -r AZURE_KEY
stty echo
printf "\n"
STORAGE_FLAGS="--object-store=azure --azure-storage-account=${AZURE_ACCOUNT}"
STORAGE_FLAGS_ECHO="$STORAGE_FLAGS --azure-storage-access-key=..."
STORAGE_FLAGS="$STORAGE_FLAGS --azure-storage-access-key=${AZURE_KEY}"
}
# Function to configure Google Cloud storage
configure_google_cloud_storage() {
printf "\n"
printf "${BOLD}Google Cloud Storage Configuration${NC}\n"
printf "└─ Enter path to service account JSON file: "
read -r GOOGLE_SA
STORAGE_FLAGS="--object-store=google --google-service-account=${GOOGLE_SA}"
STORAGE_FLAGS_ECHO="$STORAGE_FLAGS"
}
# --- Enterprise License ---
# Function to set up license for Enterprise Quick Start
setup_license_for_quick_start() {
# Check if license file exists
if [ -f "$LICENSE_FILE_PATH" ]; then
printf "${DIM}Found existing license file, using it for quick start.${NC}\n"
LICENSE_TYPE=""
LICENSE_EMAIL=""
LICENSE_DESC="Existing"
else
# Prompt for license type and email only
printf "\n"
printf "${BOLD}License Setup Required${NC}\n"
printf "1) ${GREEN}Trial${NC} ${DIM}- Full features for 30 days (up to 256 cores)${NC}\n"
printf "2) ${GREEN}Home${NC} ${DIM}- Free for non-commercial use (max 2 cores, single node)${NC}\n"
printf "\n"
printf "Enter your choice (1-2): "
read -r LICENSE_CHOICE
case "${LICENSE_CHOICE:-1}" in
1)
LICENSE_TYPE="trial"
LICENSE_DESC="Trial"
;;
2)
LICENSE_TYPE="home"
LICENSE_DESC="Home"
;;
*)
LICENSE_TYPE="trial"
LICENSE_DESC="Trial"
;;
esac
printf "Enter your email: "
read -r LICENSE_EMAIL
while [ -z "$LICENSE_EMAIL" ]; do
printf "Email is required. Enter your email: "
read -r LICENSE_EMAIL
done
fi
}