From d674ffa914ae5ac520ecd2472616b82f46a9bd21 Mon Sep 17 00:00:00 2001 From: livejq Date: Thu, 30 Dec 2021 12:02:55 +0800 Subject: [PATCH] version 1.0.0 --- AutoPing.sh | 137 +++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 110 insertions(+), 27 deletions(-) diff --git a/AutoPing.sh b/AutoPing.sh index 8d7cb6f..6cb253a 100644 --- a/AutoPing.sh +++ b/AutoPing.sh @@ -1,7 +1,48 @@ -#!/bin/bash +#!/usr/bin/env bash +# +# Description: Choose a faster mirror for Linux script +# +# Copyright (C) 2021 liveJQ +# + +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[0;33m' +SKYBLUE='\033[0;36m' +PLAIN='\033[0m' target_dir="/opt/ysnet" -origin="https://gitee.com/livejq/pingm/raw/master" +origin="https://gitee.com/livejq/pingm/repository/archive/master.zip" +monitorSvr="http://116.31.96.74:28080/monitorSvr/a?login" + +selectAction() { + echo "" + echo -e "${GREEN} ========================================================= ${PLAIN}" + echo -e "${GREEN} \ 1.安装SmokePing / ${PLAIN}" + echo -e "${GREEN} \ 2.安装Agent / ${PLAIN}" + echo -e "${GREEN} \ 直接回车一起安装 / ${PLAIN}" + echo -e "${GREEN} ========================================================= ${PLAIN}" + echo -e "${YELLOW} System requirements: ${PLAIN}${RED}CentOS 7${PLAIN}${YELLOW} or ${PLAIN}${RED}Ubuntu 20.04${PLAIN}${YELLOW}. ${PLAIN}" + echo -e "${YELLOW} Version: ${PLAIN}${GREEN}1.0.0${PLAIN}${YELLOW} (30 Dec 2021) ${PLAIN}" + echo -e "${YELLOW} Copyright (C) 2021 liveJQ cloud@livejq.fun ${PLAIN}" + echo "" + read -rp "请输入数字选择:" num + case $num in + 1) + get_info + install_SMP + ;; + 2) + get_info + install_Agent + ;; + *) + get_info + install_SMP + install_Agent + ;; + esac +} updateUb() { cp /etc/apt/sources.list /etc/apt/sources.list.old @@ -39,13 +80,13 @@ get_info() { else exit 1 fi - read -rp "输入监控页面端口(默认20000):" port1 - ss -tnlp | grep -q ":${port1:-20000} " && echo "端口 ${port1:-20000} 已被占用" && exit 1 } -install_packages() { - rpm_packages="smokeping unzip wqy-zenhei-fonts.noarch mtr java-1.8.0-openjdk*" - apt_packages="smokeping echoping unzip traceroute mtr openjdk-8-jdk" +install_SMP() { + rpm_packages="smokeping unzip wqy-zenhei-fonts.noarch" + apt_packages="smokeping echoping unzip traceroute" + read -rp "输入监控页面端口(默认20000):" port1 + ss -tnlp | grep -q ":${port1:-20000} " && echo "端口 ${port1:-20000} 已被占用" && exit 1 if [[ $ID == "debian" || $ID == "ubuntu" ]]; then $PM update $INS wget curl -y @@ -63,6 +104,24 @@ install_packages() { fi } +install_Agent() { + rpm_packages="mtr java-1.8.0-openjdk*" + apt_packages="mtr openjdk-8-jdk" + if [[ $ID == "debian" || $ID == "ubuntu" ]]; then + $PM update + $INS wget curl -y + $INS $apt_packages -y || error=1 + [[ $error -eq 1 ]] && echo "安装 Agent 客户端依赖包失败" && exit 1 + configureUbAgent + elif [[ $ID == "centos" ]]; then + sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config + setenforce 0 + $INS wget curl -y + $INS $rpm_packages -y + configureCeAgent + fi +} + configureUb() { #get local ip ip=$(curl -sL https://api64.ipify.org -4) || error=1 @@ -89,21 +148,13 @@ configureUb() { chmod 777 -R /var/lib/smokeping/ #timezone timedatectl set-timezone Asia/Shanghai - #Agent - mkdir -p /var/monitor_agent - wget $origin/Agent/agentMain.jar -P /var/monitor_agent - wget $origin/Agent/conf -P /var/monitor_agent - wget $origin/Agent/AgentRestart.sh -P /root - chmod 755 -R /var/monitor_agent - export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-amd64 - /root/AgentRestart.sh #test smokeping --debug || error=1 [[ $error -eq 1 ]] && echo "测试运行失败!" && exit 1 systemctl start apache2 smokeping || error=1 [[ $error -eq 1 ]] && echo "启动失败" && exit 1 echo "" - echo "安装完成,监控页面网址:http://$ip:${port1:-20000}/smokeping" + echo "Smokeping安装完成,监控页面:http://$ip:${port1:-20000}/smokeping/sm.cgi" echo "" echo "注意:" echo "如有必要请在防火墙放行 ${port1:-20000} 端口" @@ -111,6 +162,27 @@ configureUb() { echo "" } +configureUbAgent() { + #Agent + mkdir -p /var/monitor_agent + wget $origin + unzip master.zip + mv pingm-master/Agent/agentMain.jar /var/monitor_agent + mv pingm-master/Agent/conf /var/monitor_agent + mv pingm-master/Agent/AgentRestart.sh /root + rm -f master.zip + rm -fr pingm-master + chmod 755 -R /var/monitor_agent + chmod 755 /root/AgentRestart.sh + /root/AgentRestart.sh + echo "" + echo "Agent安装完成,请到监控页面添加Agent和下发策略:$monitorSvr" + echo "" + echo "注意:" + echo "如有必要请在防火墙放行 9123 端口" + echo "" +} + configureCe() { #get local ip ip=$(curl -sL https://api64.ipify.org -4) || error=1 @@ -139,21 +211,13 @@ configureCe() { systemctl stop firewalld && systemctl disable firewalld #timezone timedatectl set-timezone Asia/Shanghai - #Agent - mkdir -p /var/monitor_agent - wget $origin/Agent/agentMain.jar -P /var/monitor_agent - wget $origin/Agent/conf -P /var/monitor_agent - wget $origin/Agent/AgentRestart.sh -P /root - chmod 755 -R /var/monitor_agent - export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk - /root/AgentRestart.sh #test smokeping --debug || error=1 [[ $error -eq 1 ]] && echo "测试运行失败!" && exit 1 systemctl start httpd smokeping || error=1 [[ $error -eq 1 ]] && echo "启动失败" && exit 1 echo "" - echo "安装完成,监控页面网址:http://$ip:${port1:-20000}/smokeping/sm.cgi" + echo "Smokeping安装完成,监控页面:http://$ip:${port1:-20000}/smokeping/sm.cgi" echo "" echo "注意:" echo "如有必要请在防火墙放行 ${port1:-20000} 端口" @@ -161,5 +225,24 @@ configureCe() { echo "" } -get_info -install_packages \ No newline at end of file +configureCeAgent() { + #Agent + mkdir -p /var/monitor_agent + wget $origin + unzip master.zip + mv pingm-master/Agent/agentMain.jar /var/monitor_agent + mv pingm-master/Agent/conf /var/monitor_agent + mv pingm-master/Agent/AgentRestart.sh /root + rm -f master.zip + rm -fr pingm-master + chmod 755 -R /var/monitor_agent + chmod 755 /root/AgentRestart.sh + /root/AgentRestart.sh + echo "" + echo "Agent安装完成,请到监控页面添加Agent和下发策略:$monitorSvr" + echo "" + echo "注意:" + echo "如有必要请在防火墙放行 9123 端口" + echo "" +} +selectAction \ No newline at end of file