From d137d76392de96c455c8cf8d4b989a444f6ab7a5 Mon Sep 17 00:00:00 2001 From: Erope Date: Thu, 13 May 2021 17:54:41 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E8=8E=B7=E5=8F=96agent=E7=89=88=E6=9C=AC?= =?UTF-8?q?=E5=8F=B7=E4=BB=A5=E4=BE=BF=E4=B8=8B=E8=BD=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- script/install.sh | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/script/install.sh b/script/install.sh index 65e45d4..08ea244 100755 --- a/script/install.sh +++ b/script/install.sh @@ -156,12 +156,22 @@ install_agent() { echo -e "> 安装监控Agent" + echo -e "正在获取监控Agent版本号" + + local version=$(curl -sL "https://api.github.com/repos/naiba/nezha/releases/latest" | grep "tag_name" | head -n 1 | awk -F ":" '{print $2}' | sed 's/\"//g;s/,//g;s/ //g') + + if [ ! -n "$version" ]; then + echo -e "获取版本号失败,请检查本机能否链接 https://api.github.com/repos/naiba/nezha/releases/latest" + else + echo -e "当前最新版本为: ${version}" + fi + # 哪吒监控文件夹 mkdir -p $NZ_AGENT_PATH chmod 777 -R $NZ_AGENT_PATH echo -e "正在下载监控端" - wget -O nezha-agent_linux_${os_arch}.tar.gz https://${GITHUB_URL}/naiba/nezha/releases/latest/download/nezha-agent_linux_${os_arch}.tar.gz >/dev/null 2>&1 + wget -O nezha-agent_linux_${os_arch}.tar.gz https://${GITHUB_URL}/naiba/nezha/releases/download/${version}/nezha-agent_linux_${os_arch}.tar.gz >/dev/null 2>&1 if [[ $? != 0 ]]; then echo -e "${red}Release 下载失败,请检查本机能否连接 ${GITHUB_URL}${plain}" return 0 From 85b0b4d2bf4ff2dfe464e6036884660cf860a661 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=96=E5=A5=B3=E5=AD=A9=E7=9A=84=E5=B0=8F=E7=81=AB?= =?UTF-8?q?=E6=9F=B4?= <44471469+Erope@users.noreply.github.com> Date: Thu, 13 May 2021 18:39:13 +0800 Subject: [PATCH 2/5] Update install.sh --- script/install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/script/install.sh b/script/install.sh index 7bdb3f6..5ef73ec 100755 --- a/script/install.sh +++ b/script/install.sh @@ -11,7 +11,7 @@ NZ_BASE_PATH="/opt/nezha" NZ_DASHBOARD_PATH="${NZ_BASE_PATH}/dashboard" NZ_AGENT_PATH="${NZ_BASE_PATH}/agent" NZ_AGENT_SERVICE="/etc/systemd/system/nezha-agent.service" -NZ_VERSION="v0.5.0" +NZ_VERSION="v0.6.0" red='\033[0;31m' green='\033[0;32m' From f06a98fd54a6b962b2ffd47aba5826f1e77d67d3 Mon Sep 17 00:00:00 2001 From: Erope Date: Thu, 13 May 2021 19:44:09 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E5=AE=89=E8=A3=85=E8=84=9A=E6=9C=AC=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- script/install.sh | 62 +++++++++++++++++++++++++++++++++++------------ 1 file changed, 46 insertions(+), 16 deletions(-) diff --git a/script/install.sh b/script/install.sh index 5ef73ec..fc76ed5 100755 --- a/script/install.sh +++ b/script/install.sh @@ -93,6 +93,28 @@ confirm() { fi } +update_script () { + echo -e "> 更新脚本" + + mkdir -p $NZ_BASE_PATH + chmod 777 -R $NZ_BASE_PATH + curl -sL https://cdn.jsdelivr.net/gh/naiba/nezha@master/script/install.sh -o /tmp/nezha.sh + new_version=$(cat /tmp/nezha.sh | grep "NZ_VERSION" | head -n 1 | awk -F "=" '{print $2}' | sed 's/\"//g;s/,//g;s/ //g') + if [ ! -n "$new_version" ]; then + echo -e "脚本获取失败,请检查本机能否链接 https://cdn.jsdelivr.net/gh/naiba/nezha@master/script/install.sh" + return 1 + fi + echo -e "当前最新版本为: ${new_version}" + mv -f /tmp/nezha.sh ${NZ_BASE_PATH}/nezha.sh && chmod a+x ${NZ_BASE_PATH}/nezha.sh + + echo -e "脚本获取成功,脚本固定位置为${NZ_BASE_PATH}/nezha.sh,请今后使用 ${NZ_BASE_PATH}/nezha.sh 运行脚本" + echo -e "10s后执行新脚本" + sleep 10s + clear + exec ${NZ_BASE_PATH}/nezha.sh + exit 0 +} + before_show_menu() { echo && echo -n -e "${yellow}* 按回车返回主菜单 *${plain}" && read temp show_menu @@ -404,20 +426,21 @@ clean_all() { show_usage() { echo "哪吒监控 管理脚本使用方法: " echo "--------------------------------------------------------" - echo "./nbdomain.sh - 显示管理菜单" - echo "./nbdomain.sh install_dashboard - 安装面板端" - echo "./nbdomain.sh modify_dashboard_config - 修改面板配置" - echo "./nbdomain.sh start_dashboard - 启动面板" - echo "./nbdomain.sh stop_dashboard - 停止面板" - echo "./nbdomain.sh restart_and_update - 重启并更新面板" - echo "./nbdomain.sh show_dashboard_log - 查看面板日志" - echo "./nbdomain.sh uninstall_dashboard - 卸载管理面板" + echo "/opt/nezha/nezha.sh - 显示管理菜单" + echo "/opt/nezha/nezha.sh install_dashboard - 安装面板端" + echo "/opt/nezha/nezha.sh modify_dashboard_config - 修改面板配置" + echo "/opt/nezha/nezha.sh start_dashboard - 启动面板" + echo "/opt/nezha/nezha.sh stop_dashboard - 停止面板" + echo "/opt/nezha/nezha.sh restart_and_update - 重启并更新面板" + echo "/opt/nezha/nezha.sh show_dashboard_log - 查看面板日志" + echo "/opt/nezha/nezha.sh uninstall_dashboard - 卸载管理面板" echo "--------------------------------------------------------" - echo "./nbdomain.sh install_agent - 安装监控Agent" - echo "./nbdomain.sh modify_agent_config - 修改Agent配置" - echo "./nbdomain.sh show_agent_log - 查看Agent日志" - echo "./nbdomain.sh uninstall_agent - 卸载Agen" - echo "./nbdomain.sh restart_agent - 重启Agen" + echo "/opt/nezha/nezha.sh install_agent - 安装监控Agent" + echo "/opt/nezha/nezha.sh modify_agent_config - 修改Agent配置" + echo "/opt/nezha/nezha.sh show_agent_log - 查看Agent日志" + echo "/opt/nezha/nezha.sh uninstall_agent - 卸载Agen" + echo "/opt/nezha/nezha.sh restart_agent - 重启Agen" + echo "/opt/nezha/nezha.sh update_script - 更新脚本" echo "--------------------------------------------------------" } @@ -425,8 +448,6 @@ show_menu() { echo -e " ${green}哪吒监控管理脚本${plain} ${red}${NZ_VERSION}${plain} --- https://github.com/naiba/nezha --- - ${green}0.${plain} 退出脚本 - ————————————————- ${green}1.${plain} 安装面板端 ${green}2.${plain} 修改面板配置 ${green}3.${plain} 启动面板 @@ -440,8 +461,11 @@ show_menu() { ${green}10.${plain} 查看Agent日志 ${green}11.${plain} 卸载Agent ${green}12.${plain} 重启Agent + ————————————————- + ${green}0.${plain} 退出脚本 + ${green}13.${plain} 更新脚本 " - echo && read -p "请输入选择 [0-12]: " num + echo && read -p "请输入选择 [0-13]: " num case "${num}" in 0) @@ -483,6 +507,9 @@ show_menu() { 12) restart_agent ;; + 13) + update_script + ;; *) echo -e "${red}请输入正确的数字 [0-12]${plain}" ;; @@ -529,6 +556,9 @@ if [[ $# > 0 ]]; then "restart_agent") restart_agent 0 ;; + "update_script") + update_script 0 + ;; *) show_usage ;; esac else From 8a4c04459d00f220b2b0614622da23ec196d68b5 Mon Sep 17 00:00:00 2001 From: Erope Date: Thu, 13 May 2021 20:14:14 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E8=84=9A=E6=9C=AC?= =?UTF-8?q?=E5=AE=89=E8=A3=85=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/dashboard.yml | 2 ++ README.md | 15 ++++++++++----- script/fetch.sh | 9 +++++++++ script/install.sh | 4 ++-- 4 files changed, 23 insertions(+), 7 deletions(-) create mode 100644 script/fetch.sh diff --git a/.github/workflows/dashboard.yml b/.github/workflows/dashboard.yml index 6940ccd..b81645e 100644 --- a/.github/workflows/dashboard.yml +++ b/.github/workflows/dashboard.yml @@ -42,11 +42,13 @@ jobs: - name: Purge jsdelivr cache run: | curl -s https://purge.jsdelivr.net/gh/${{ github.repository_owner }}/nezha@master/script/install.sh + curl -s https://purge.jsdelivr.net/gh/${{ github.repository_owner }}/nezha@master/script/fetch.sh curl -s https://purge.jsdelivr.net/gh/${{ github.repository_owner }}/nezha@master/script/nezha-agent.service curl -s https://purge.jsdelivr.net/gh/${{ github.repository_owner }}/nezha@master/script/docker-compose.yaml curl -s https://purge.jsdelivr.net/gh/${{ github.repository_owner }}/nezha@master/script/config.yaml LOWER_USERNAME=$(echo "${{ github.repository_owner }}" | tr '[:upper:]' '[:lower:]') curl -s https://purge.jsdelivr.net/gh/$LOWER_USERNAME/nezha@master/script/install.sh + curl -s https://purge.jsdelivr.net/gh/$LOWER_USERNAME/nezha@master/script/fetch.sh curl -s https://purge.jsdelivr.net/gh/$LOWER_USERNAME/nezha@master/script/nezha-agent.service curl -s https://purge.jsdelivr.net/gh/$LOWER_USERNAME/nezha@master/script/docker-compose.yaml curl -s https://purge.jsdelivr.net/gh/$LOWER_USERNAME/nezha@master/script/config.yaml diff --git a/README.md b/README.md index d38bff2..27476de 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@


-    +   

:trollface: 哪吒监控 一站式轻监控轻运维系统。支持系统状态、HTTP(SSL 证书变更、即将到期、到期)、TCP、Ping 监控报警,命令批量执行和计划任务。

@@ -21,15 +21,20 @@ **推荐配置:** 安装前准备 _两个域名_,一个可以 **接入 CDN** 作为 _公开访问_,比如 (status.nai.ba);另外一个解析到面板服务器作为 Agent 连接 Dashboard 使用,**不能接入 CDN** 直接暴露面板主机 IP,比如(randomdashboard.nai.ba)。 ```shell -curl -L https://raw.githubusercontent.com/naiba/nezha/master/script/install.sh -o nezha.sh && chmod +x nezha.sh -./nezha.sh +curl -sSL https://raw.githubusercontent.com/naiba/nezha/master/script/fetch.sh | sh +/opt/nezha/nezha.sh ``` 国内镜像加速: ```shell -curl -L https://cdn.jsdelivr.net/gh/naiba/nezha@master/script/install.sh -o nezha.sh && chmod +x nezha.sh -CN=true ./nezha.sh +curl -sSL https://cdn.jsdelivr.net/gh/naiba/nezha@master/script/fetch.sh | CN=true sh +CN=true /opt/nezha/nezha.sh +``` + +再次运行仅需: +``` +/opt/nezha/nezha.sh ``` _\* 使用 WatchTower 可以自动更新面板,Windows 终端可以使用 nssm 配置自启动(见尾部教程)_ diff --git a/script/fetch.sh b/script/fetch.sh new file mode 100644 index 0000000..ca2f5df --- /dev/null +++ b/script/fetch.sh @@ -0,0 +1,9 @@ +if [[ -z "${CN}" ]]; then + GITHUB_RAW_URL="raw.githubusercontent.com/naiba/nezha/master" +else + GITHUB_RAW_URL="cdn.jsdelivr.net/gh/naiba/nezha@master" +fi +mkdir -p /opt/nezha +chmod 777 /opt/nezha +curl -sSL https://${GITHUB_RAW_URL}/script/install.sh -o /opt/nezha/nezha.sh +chmod +x /opt/nezha/nezha.sh \ No newline at end of file diff --git a/script/install.sh b/script/install.sh index fc76ed5..e0c1b9c 100755 --- a/script/install.sh +++ b/script/install.sh @@ -98,10 +98,10 @@ update_script () { mkdir -p $NZ_BASE_PATH chmod 777 -R $NZ_BASE_PATH - curl -sL https://cdn.jsdelivr.net/gh/naiba/nezha@master/script/install.sh -o /tmp/nezha.sh + curl -sL https://${GITHUB_RAW_URL}/script/install.sh -o /tmp/nezha.sh new_version=$(cat /tmp/nezha.sh | grep "NZ_VERSION" | head -n 1 | awk -F "=" '{print $2}' | sed 's/\"//g;s/,//g;s/ //g') if [ ! -n "$new_version" ]; then - echo -e "脚本获取失败,请检查本机能否链接 https://cdn.jsdelivr.net/gh/naiba/nezha@master/script/install.sh" + echo -e "脚本获取失败,请检查本机能否链接 https://${GITHUB_RAW_URL}/script/install.sh" return 1 fi echo -e "当前最新版本为: ${new_version}" From e401c5a87247afc1f8791222806cbd85460a418a Mon Sep 17 00:00:00 2001 From: Erope Date: Thu, 13 May 2021 20:19:15 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=E6=8C=87=E5=AE=9AREADME=E4=B8=ADsh?= =?UTF-8?q?=E4=B8=BAbash?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 27476de..897931f 100644 --- a/README.md +++ b/README.md @@ -21,14 +21,14 @@ **推荐配置:** 安装前准备 _两个域名_,一个可以 **接入 CDN** 作为 _公开访问_,比如 (status.nai.ba);另外一个解析到面板服务器作为 Agent 连接 Dashboard 使用,**不能接入 CDN** 直接暴露面板主机 IP,比如(randomdashboard.nai.ba)。 ```shell -curl -sSL https://raw.githubusercontent.com/naiba/nezha/master/script/fetch.sh | sh +curl -sSL https://raw.githubusercontent.com/naiba/nezha/master/script/fetch.sh | bash /opt/nezha/nezha.sh ``` 国内镜像加速: ```shell -curl -sSL https://cdn.jsdelivr.net/gh/naiba/nezha@master/script/fetch.sh | CN=true sh +curl -sSL https://cdn.jsdelivr.net/gh/naiba/nezha@master/script/fetch.sh | CN=true bash CN=true /opt/nezha/nezha.sh ```