From 0ed29a9597aeaa68c3e10835441ecb037bfd3ee9 Mon Sep 17 00:00:00 2001 From: CN-JS-HuiBai Date: Mon, 16 Feb 2026 22:00:31 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=93=8D=E4=BD=9C=E7=B3=BB?= =?UTF-8?q?=E7=BB=9F=E5=88=9D=E5=A7=8B=E5=8C=96=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- system-init-shells.sh | 92 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 system-init-shells.sh diff --git a/system-init-shells.sh b/system-init-shells.sh new file mode 100644 index 0000000..5704be5 --- /dev/null +++ b/system-init-shells.sh @@ -0,0 +1,92 @@ +#!/bin/bash +set -e +#检测操作系统,如果是红帽操作系统则安装firewalld并开放端口 +if grep -Ei "red hat|rocky|alma|centos" /etc/os-release > /dev/null 2>&1; then + echo "Detected RHEL-based system" + + sudo dnf -y groupinstall "Server" + + sudo dnf -y install firewalld + + sudo systemctl enable --now firewalld + + ports=("22" "80" "443" "9100" "10000-65535") + + for port in "${ports[@]}"; do + sudo firewall-cmd --permanent --add-port=${port}/tcp + sudo firewall-cmd --permanent --add-port=${port}/udp + done + + sudo firewall-cmd --reload + + sudo firewall-cmd --list-ports + +sudo dnf install -y wget curl tar + +# Download Node Exporter + +CN_URL="https://s3.cloudyun.top/downloads/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.littlediary.cn/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 <