109 lines
2.7 KiB
Bash
109 lines
2.7 KiB
Bash
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
INSTALL_SCRIPT="${SCRIPT_DIR}/install_clickhouse_linux.sh"
|
|
HTTPS_SCRIPT="${SCRIPT_DIR}/configure_clickhouse_https.sh"
|
|
RUNTIME_SCRIPT="${SCRIPT_DIR}/configure_clickhouse_runtime.sh"
|
|
TABLES_SCRIPT="${SCRIPT_DIR}/init_waf_logs_tables.sh"
|
|
|
|
usage() {
|
|
cat <<'EOF'
|
|
Usage:
|
|
sudo ./setup_clickhouse.sh [all|install|https|runtime|tables]
|
|
|
|
Modes:
|
|
all Install ClickHouse, configure HTTPS, apply runtime config, init ingest tables (default)
|
|
install Install ClickHouse only
|
|
https Configure HTTPS only
|
|
runtime Apply ClickHouse runtime config only
|
|
tables Initialize ingest tables only
|
|
|
|
Common env vars:
|
|
CLICKHOUSE_DEFAULT_PASSWORD Default user password set during install
|
|
CH_HTTPS_PORT HTTPS port (default: 8443)
|
|
CH_CERT_CN Certificate CN
|
|
CH_CERT_DNS Certificate SAN DNS list (comma-separated)
|
|
CH_CERT_IP Certificate SAN IP list (comma-separated)
|
|
CH_CERT_DAYS Certificate validity days (default: 825)
|
|
CH_LOG_LEVEL ClickHouse logger level (default: warning)
|
|
CH_HOST ClickHouse host for table init (default: 127.0.0.1)
|
|
CH_PORT ClickHouse port for table init (default: 9000)
|
|
CH_USER ClickHouse user for table init (default: default)
|
|
CH_PASSWORD ClickHouse password for table init
|
|
CH_DATABASE Database for table init (default: default)
|
|
EOF
|
|
}
|
|
|
|
require_script() {
|
|
local script="$1"
|
|
if [[ ! -f "${script}" ]]; then
|
|
echo "[ERROR] required file not found: ${script}"
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
run_install() {
|
|
echo "[INFO] step 1/3: install ClickHouse ..."
|
|
bash "${INSTALL_SCRIPT}"
|
|
}
|
|
|
|
run_https() {
|
|
echo "[INFO] step 2/3: configure ClickHouse HTTPS ..."
|
|
bash "${HTTPS_SCRIPT}"
|
|
}
|
|
|
|
run_runtime() {
|
|
echo "[INFO] step 3/4: apply ClickHouse runtime config ..."
|
|
bash "${RUNTIME_SCRIPT}"
|
|
}
|
|
|
|
run_tables() {
|
|
echo "[INFO] step 4/4: initialize ingest tables ..."
|
|
bash "${TABLES_SCRIPT}"
|
|
}
|
|
|
|
MODE="${1:-all}"
|
|
|
|
case "${MODE}" in
|
|
-h|--help|help)
|
|
usage
|
|
exit 0
|
|
;;
|
|
all|install|https|runtime|tables)
|
|
;;
|
|
*)
|
|
echo "[ERROR] invalid mode: ${MODE}"
|
|
usage
|
|
exit 1
|
|
;;
|
|
esac
|
|
|
|
require_script "${INSTALL_SCRIPT}"
|
|
require_script "${HTTPS_SCRIPT}"
|
|
require_script "${RUNTIME_SCRIPT}"
|
|
require_script "${TABLES_SCRIPT}"
|
|
|
|
case "${MODE}" in
|
|
all)
|
|
run_install
|
|
run_https
|
|
run_runtime
|
|
run_tables
|
|
;;
|
|
install)
|
|
run_install
|
|
;;
|
|
https)
|
|
run_https
|
|
;;
|
|
runtime)
|
|
run_runtime
|
|
;;
|
|
tables)
|
|
run_tables
|
|
;;
|
|
esac
|
|
|
|
echo "[OK] setup completed: mode=${MODE}"
|