diff --git a/Prometheus/install_blackbox_exporter.sh b/Prometheus/install_blackbox_exporter.sh index 1e2fccf..58363e7 100644 --- a/Prometheus/install_blackbox_exporter.sh +++ b/Prometheus/install_blackbox_exporter.sh @@ -1,25 +1,24 @@ #!/bin/bash set -e -#Detect Operation System - +# Detect Operation System if command -v apt >/dev/null 2>&1; then echo "Detected apt-based system" sudo apt update sudo apt install -y wget curl tar - elif command -v dnf >/dev/null 2>&1; then echo "Detected dnf-based system" sudo dnf install -y wget curl tar - else echo "Unsupported package manager" exit 1 fi -# Download Node Exporter -CN_URL="https://s3.cloudyun.top/downloads/cadvisor-v0.55.1-linux-amd64" -GLOBAL_URL="https://github.com/prometheus/blackbox_exporter/releases/download/v0.28.0/blackbox_exporter-0.28.0.linux-amd64.tar.gz" -TARGET=/tmp/cAdvisor +# Download Blackbox Exporter +VERSION="0.28.0" +ARCH="amd64" +CN_URL="https://s3.cloudyun.top/downloads/blackbox_exporter-${VERSION}.linux-${ARCH}.tar.gz" +GLOBAL_URL="https://github.com/prometheus/blackbox_exporter/releases/download/v${VERSION}/blackbox_exporter-${VERSION}.linux-${ARCH}.tar.gz" +TARGET="/tmp/blackbox_exporter.tar.gz" is_cn=false echo "Detecting geographic location..." @@ -28,7 +27,6 @@ if [ "$COUNTRY" = "CN" ]; then is_cn=true fi - if [ "$is_cn" = true ]; then echo "Geolocation: China mainland detected" DOWNLOAD_URL="$CN_URL" @@ -40,3 +38,53 @@ fi echo "Downloading from: $DOWNLOAD_URL" curl -fL -o "$TARGET" "$DOWNLOAD_URL" +# Extract +echo "Extracting Blackbox Exporter..." +tar -zxvf "$TARGET" -C /tmp +sudo mkdir -p /blackbox_exporter +sudo cp "/tmp/blackbox_exporter-${VERSION}.linux-${ARCH}/blackbox_exporter" /blackbox_exporter/ +sudo cp "/tmp/blackbox_exporter-${VERSION}.linux-${ARCH}/blackbox.yml" /blackbox_exporter/ + +# choosing port +DEFAULT_PORT=9115 +if [ -t 0 ]; then + while true; do + read -rp "Please enter blackbox_exporter listen port [default: ${DEFAULT_PORT}]: " PORT + PORT=${PORT:-$DEFAULT_PORT} + if [[ "$PORT" =~ ^[0-9]+$ ]] && [ "$PORT" -ge 1 ] && [ "$PORT" -le 65535 ]; then + break + else + echo "Invalid port. Please enter a number between 1 and 65535." + fi + done +else + PORT=$DEFAULT_PORT + echo "No TTY detected, using default port: $PORT" +fi + +# Create systemd service file +SERVICE_FILE="/etc/systemd/system/blackbox_exporter.service" +echo "Creating systemd service file..." +sudo tee "$SERVICE_FILE" > /dev/null <