修复脚本
This commit is contained in:
@@ -1,25 +1,24 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
# 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 <<EOF
|
||||
[Unit]
|
||||
Description=Blackbox Exporter
|
||||
Wants=network-online.target
|
||||
After=network-online.target
|
||||
|
||||
[Service]
|
||||
User=root
|
||||
WorkingDirectory=/blackbox_exporter
|
||||
ExecStart=/blackbox_exporter/blackbox_exporter --config.file=/blackbox_exporter/blackbox.yml --web.listen-address=":${PORT}"
|
||||
Restart=always
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
EOF
|
||||
|
||||
# Reload systemd, enable and start service
|
||||
echo "Enabling and starting blackbox_exporter service..."
|
||||
sudo systemctl daemon-reload
|
||||
sudo systemctl enable --now blackbox_exporter.service
|
||||
|
||||
echo "Blackbox Exporter installation completed, listening on port ${PORT}"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user