version 1.0.0

master
livejq 3 years ago
parent 692e5d0740
commit d674ffa914
  1. 137
      AutoPing.sh

@ -1,7 +1,48 @@
#!/bin/bash #!/usr/bin/env bash
#
# Description: Choose a faster mirror for Linux script
#
# Copyright (C) 2021 liveJQ <cloud@livejq.fun>
#
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
SKYBLUE='\033[0;36m'
PLAIN='\033[0m'
target_dir="/opt/ysnet" 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() { updateUb() {
cp /etc/apt/sources.list /etc/apt/sources.list.old cp /etc/apt/sources.list /etc/apt/sources.list.old
@ -39,13 +80,13 @@ get_info() {
else else
exit 1 exit 1
fi fi
read -rp "输入监控页面端口(默认20000):" port1
ss -tnlp | grep -q ":${port1:-20000} " && echo "端口 ${port1:-20000} 已被占用" && exit 1
} }
install_packages() { install_SMP() {
rpm_packages="smokeping unzip wqy-zenhei-fonts.noarch mtr java-1.8.0-openjdk*" rpm_packages="smokeping unzip wqy-zenhei-fonts.noarch"
apt_packages="smokeping echoping unzip traceroute mtr openjdk-8-jdk" 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 if [[ $ID == "debian" || $ID == "ubuntu" ]]; then
$PM update $PM update
$INS wget curl -y $INS wget curl -y
@ -63,6 +104,24 @@ install_packages() {
fi 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() { configureUb() {
#get local ip #get local ip
ip=$(curl -sL https://api64.ipify.org -4) || error=1 ip=$(curl -sL https://api64.ipify.org -4) || error=1
@ -89,21 +148,13 @@ configureUb() {
chmod 777 -R /var/lib/smokeping/ chmod 777 -R /var/lib/smokeping/
#timezone #timezone
timedatectl set-timezone Asia/Shanghai 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 #test
smokeping --debug || error=1 smokeping --debug || error=1
[[ $error -eq 1 ]] && echo "测试运行失败!" && exit 1 [[ $error -eq 1 ]] && echo "测试运行失败!" && exit 1
systemctl start apache2 smokeping || error=1 systemctl start apache2 smokeping || error=1
[[ $error -eq 1 ]] && echo "启动失败" && exit 1 [[ $error -eq 1 ]] && echo "启动失败" && exit 1
echo "" echo ""
echo "安装完成,监控页面网址:http://$ip:${port1:-20000}/smokeping" echo "Smokeping安装完成,监控页面:http://$ip:${port1:-20000}/smokeping/sm.cgi"
echo "" echo ""
echo "注意:" echo "注意:"
echo "如有必要请在防火墙放行 ${port1:-20000} 端口" echo "如有必要请在防火墙放行 ${port1:-20000} 端口"
@ -111,6 +162,27 @@ configureUb() {
echo "" 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() { configureCe() {
#get local ip #get local ip
ip=$(curl -sL https://api64.ipify.org -4) || error=1 ip=$(curl -sL https://api64.ipify.org -4) || error=1
@ -139,21 +211,13 @@ configureCe() {
systemctl stop firewalld && systemctl disable firewalld systemctl stop firewalld && systemctl disable firewalld
#timezone #timezone
timedatectl set-timezone Asia/Shanghai 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 #test
smokeping --debug || error=1 smokeping --debug || error=1
[[ $error -eq 1 ]] && echo "测试运行失败!" && exit 1 [[ $error -eq 1 ]] && echo "测试运行失败!" && exit 1
systemctl start httpd smokeping || error=1 systemctl start httpd smokeping || error=1
[[ $error -eq 1 ]] && echo "启动失败" && exit 1 [[ $error -eq 1 ]] && echo "启动失败" && exit 1
echo "" echo ""
echo "安装完成,监控页面网址:http://$ip:${port1:-20000}/smokeping/sm.cgi" echo "Smokeping安装完成,监控页面:http://$ip:${port1:-20000}/smokeping/sm.cgi"
echo "" echo ""
echo "注意:" echo "注意:"
echo "如有必要请在防火墙放行 ${port1:-20000} 端口" echo "如有必要请在防火墙放行 ${port1:-20000} 端口"
@ -161,5 +225,24 @@ configureCe() {
echo "" echo ""
} }
get_info configureCeAgent() {
install_packages #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
Loading…
Cancel
Save