From e9bade6dff1f1b9f3b1d1119967c02e80f53ffa2 Mon Sep 17 00:00:00 2001 From: CN-JS-HuiBai Date: Fri, 16 Jan 2026 06:08:51 +0000 Subject: [PATCH] using ipinfo to check country Change Node_exporter download url install basic system dependency --- Prometheus/install-node_exporter.sh | 83 +++++++++++++++++++++++++++++ install-node_exporter.sh | 41 -------------- nginx.conf => nginx/nginx.conf | 0 3 files changed, 83 insertions(+), 41 deletions(-) create mode 100644 Prometheus/install-node_exporter.sh delete mode 100644 install-node_exporter.sh rename nginx.conf => nginx/nginx.conf (100%) diff --git a/Prometheus/install-node_exporter.sh b/Prometheus/install-node_exporter.sh new file mode 100644 index 0000000..dbc735c --- /dev/null +++ b/Prometheus/install-node_exporter.sh @@ -0,0 +1,83 @@ +#!/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://8.134.128.173/relayx/node_exporter-1.10.2.linux-amd64.tar.gz" +GLOBAL_URL="https://github.com/prometheus/node_exporter/releases/download/v1.10.2/node_exporter-1.10.2.linux-amd64.tar.gz" +TARGET="/tmp/node_exporter.tar.gz" + +is_cn=false + +echo "Detecting geographic location..." + +COUNTRY=$(curl -s --max-time 3 https://ipinfo.io/country || true) +if [ "$COUNTRY" = "CN" ]; then + is_cn=true +fi + + +if [ "$is_cn" = true ]; then + echo "Geolocation: China mainland detected" + DOWNLOAD_URL="$CN_URL" +else + echo "Geolocation: non-China region detected" + DOWNLOAD_URL="$GLOBAL_URL" +fi + +echo "Downloading from: $DOWNLOAD_URL" +curl -fL -o "$TARGET" "$DOWNLOAD_URL" + + + + +# Extract +echo "Extracting Node Exporter..." +tar -zxvf /tmp/node_exporter.tar.gz -C /tmp + +# Copy to /node_exporter +echo "Copying Node Exporter to /node_exporter..." +sudo cp -r /tmp/node_exporter-1.10.2.linux-amd64 /node_exporter + +# Create systemd service file +SERVICE_FILE="/etc/systemd/system/node_exporter.service" + +echo "Creating systemd service file..." +sudo tee "$SERVICE_FILE" > /dev/null < /dev/null <